diff options
author | Nils Schwabe | 2014-07-29 15:55:52 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-29 15:55:52 +0200 |
commit | 6ea561385a291bb78077c368b1df5f997e11d80e (patch) | |
tree | a961358dea1ba3f45cd0fdd8e956910ada8a2a53 /src/main/java/org/openslx/imagemaster/crcchecker | |
parent | Change type of range to long so that files larger than 2 GiB are supported (diff) | |
download | master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.tar.gz master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.tar.xz master-sync-shared-6ea561385a291bb78077c368b1df5f997e11d80e.zip |
Rename classes and methods to fit camelCase
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java | 4 | ||||
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/CrcChecker.java (renamed from src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java) | 10 | ||||
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/CrcFile.java (renamed from src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java) | 21 | ||||
-rw-r--r-- | src/main/java/org/openslx/imagemaster/crcchecker/ImageFile.java | 3 |
4 files changed, 22 insertions, 16 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java b/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java index 37f7fb2..f1e878d 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/ClassTest.java @@ -14,13 +14,13 @@ public class ClassTest String filenameCrc = args[1]; final int blockSize = 16 * 1024 * 1024; - CRCFile f = new CRCFile( filenameCrc ); + CrcFile f = new CrcFile( filenameCrc ); System.out.println( "Master sum: '" + f.getMasterSum() + "'" ); System.out.println( f.getCrcSums() ); System.out.println( "CRC file is '" + ( ( f.isValid() ) ? "valid" : "invalid" ) + "'" ); ImageFile imageFile = new ImageFile( filename, blockSize ); - CRCChecker crcFile = new CRCChecker( imageFile, f ); + CrcChecker crcFile = new CrcChecker( imageFile, f ); int blocks = getNumberOfBlocks( imageFile.length(), blockSize ); for ( int i = 0; i < blocks; i++ ) { diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java b/src/main/java/org/openslx/imagemaster/crcchecker/CrcChecker.java index d0384a6..882f565 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/CrcChecker.java @@ -3,12 +3,12 @@ package org.openslx.imagemaster.crcchecker; import java.io.IOException; import java.util.zip.CRC32; -public class CRCChecker +public class CrcChecker { private static final int blockSize = 16 * 1024 * 1024; private ImageFile imageFile; - private CRCFile crcFile; + private CrcFile crcFile; private byte[] block = new byte[ blockSize ]; // array that is used to read the blocks @@ -18,7 +18,7 @@ public class CRCChecker * @param imageFile The image file to check * @param crcFile The crc file to check against */ - public CRCChecker( ImageFile imageFile, CRCFile crcFile ) + public CrcChecker( ImageFile imageFile, CrcFile crcFile ) { this.imageFile = imageFile; this.crcFile = crcFile; @@ -54,7 +54,7 @@ public class CRCChecker try { length = imageFile.getBlock( blockNumber, block ); } catch ( IOException e ) { - throw new IOException( "Could not read image file", e ); + throw new IOException( "image", e ); } if ( length <= 0 ) @@ -72,7 +72,7 @@ public class CRCChecker try { crcSumFromFile = crcFile.getCRCSum( blockNumber ); } catch ( IOException e ) { - throw new IOException( "Could not read CRC file", e ); + throw new IOException( "crc", e ); } return ( crcSum == crcSumFromFile ); diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CrcFile.java index 357082b..542234b 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/CrcFile.java @@ -14,7 +14,7 @@ import java.util.zip.CRC32; /** * Represents a crc file */ -public class CRCFile +public class CrcFile { private File file = null; private List<Integer> crcSums = null; @@ -25,7 +25,7 @@ public class CRCFile * * @param filename */ - public CRCFile( String filename ) + public CrcFile( String filename ) { this.file = new File( filename ); } @@ -35,7 +35,7 @@ public class CRCFile * * @param crcSums */ - public CRCFile( List<Integer> crcSums ) + public CrcFile( List<Integer> crcSums ) { this.crcSums = crcSums; } @@ -43,14 +43,19 @@ public class CRCFile /** * Creates a new crc file with the given sums. * The first crc sum in the list needs to be the sum over the other sums. + * Deletes existing files with the same name. * * @param listOfCrcSums The list of the crc sums that are going into the crc file * @param filename Where to save the created crc file * @throws IOException If it's not possible to write the file */ - public static CRCFile writeCrcFile( List<Integer> listOfCrcSums, String filename ) throws IOException + public static CrcFile writeCrcFile( List<Integer> listOfCrcSums, String filename ) throws IOException { File file = new File( filename ); + + if ( file.exists() ) + file.delete(); + FileOutputStream fos = new FileOutputStream( file ); DataOutputStream dos = new DataOutputStream( fos ); @@ -59,7 +64,7 @@ public class CRCFile } dos.close(); - return new CRCFile( filename ); + return new CrcFile( filename ); } /** @@ -117,7 +122,7 @@ public class CRCFile { if ( crcSums == null ) loadSums(); - if (crcSums.size() == 0) + if ( crcSums.size() == 0 ) return 0; if ( blockNumber < 0 ) @@ -138,7 +143,7 @@ public class CRCFile { if ( crcSums == null ) loadSums(); - if (crcSums.size() == 0) + if ( crcSums.size() == 0 ) return new ArrayList<>(); return this.crcSums; } @@ -160,7 +165,7 @@ public class CRCFile { if ( crcSums == null ) loadSums(); - if (crcSums.size() == 0) + if ( crcSums.size() == 0 ) return 0; return this.crcSums.get( 0 ); } diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/ImageFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/ImageFile.java index 9c77984..f661b75 100644 --- a/src/main/java/org/openslx/imagemaster/crcchecker/ImageFile.java +++ b/src/main/java/org/openslx/imagemaster/crcchecker/ImageFile.java @@ -64,7 +64,8 @@ public class ImageFile return; file.close(); file = null; - } catch ( IOException e ) {/* Can't do anything about it.*/ + } catch ( IOException e ) { + /* Can't do anything about it. */ } } } |