diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/util')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/util/Util.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java index 9d5c5fb..df7cea4 100644 --- a/src/main/java/org/openslx/imagemaster/util/Util.java +++ b/src/main/java/org/openslx/imagemaster/util/Util.java @@ -32,7 +32,7 @@ public class Util System.exit( 2 ); } } - + /** * Check if String is null or empty, abort program if so. * An optional message to be printed can be passed. A stack trace @@ -42,7 +42,7 @@ public class Util * @param something The string you want to check * @param message The message to be printed if "something" is null or empty */ - public static void notNullOrEmptyFatal( String something, String message) + public static void notNullOrEmptyFatal( String something, String message ) { if ( something == null || something.isEmpty() ) { if ( message != null ) @@ -92,15 +92,25 @@ public class Util /** * Tries to parse an int. Returns 0 on error. + * * @param s The strig to parse * @return The parsed int or 0 on error */ - public static int tryToParseInt(String s) { + public static int tryToParseInt( String s ) + { try { return Integer.parseInt( s ); - } catch (NumberFormatException e) { + } catch ( NumberFormatException e ) { return 0; } } - + + public static int getNumberOfBlocks( long fileSize, int blockSize ) + { + int blocks = (int) ( fileSize / blockSize ); + if ( fileSize % blockSize != 0 ) + blocks++; + return blocks; + } + } |