diff options
author | Nils Schwabe | 2014-07-07 15:43:30 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-07 15:43:30 +0200 |
commit | 5ead99f1ed794602f2be95e4560253226b29c0f7 (patch) | |
tree | 50a1e61e9d7e6147018a7bfa06bfee07ade3e027 /src/main/java/org/openslx/imagemaster | |
parent | Change CRCFile constr. to public (diff) | |
download | master-sync-shared-5ead99f1ed794602f2be95e4560253226b29c0f7.tar.gz master-sync-shared-5ead99f1ed794602f2be95e4560253226b29c0f7.tar.xz master-sync-shared-5ead99f1ed794602f2be95e4560253226b29c0f7.zip |
Change the behavior of CRCFile (hopefully the last time)
Diffstat (limited to 'src/main/java/org/openslx/imagemaster')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java index 3bab0d3..9612361 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java @@ -86,21 +86,11 @@ public class CRCFile * * @param blockNumber * @return The crcSum or 0 if the block number is invalid - * @throws IOException + * @throws IOException If the crcSums could not be loaded from file */ public int getCRCSum( int blockNumber ) throws IOException { - if ( crcSums == null ) { - // the crcSums were not read yet - DataInputStream dis = new DataInputStream( new FileInputStream( file ) ); - crcSums = new ArrayList<>(); - for ( int i = 0; i < file.length() / 4; i++ ) { - int s = dis.readInt(); - if ( i > 0 ) - crcSums.add( s ); // skip the first crcSum because it's the sum over the crcFile - } - dis.close(); - } + if (crcSums == null) loadSums(); if ( blockNumber < 0 ) return 0; @@ -110,7 +100,26 @@ public class CRCFile return crcSums.get( blockNumber ); } - public List<Integer> getCrcSums() { + /** + * Returns the loaded crcSums. + * @return The loaded crcSums + * @throws IOException If the crcSums could not be loaded from file + */ + public List<Integer> getCrcSums() throws IOException { + if (crcSums == null) loadSums(); return this.crcSums; } + + private void loadSums() throws IOException + { + // the crcSums were not read yet + DataInputStream dis = new DataInputStream( new FileInputStream( file ) ); + crcSums = new ArrayList<>(); + for ( int i = 0; i < file.length() / 4; i++ ) { + int s = dis.readInt(); + if ( i > 0 ) + crcSums.add( s ); // skip the first crcSum because it's the sum over the crcFile + } + dis.close(); + } } |