From a956b282692a5d84fd7efac1b1018cccf41653bf Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Wed, 23 Jul 2014 16:06:47 +0200 Subject: Add "synchronized" to UploadingImage Add method to calc the amount of blocks to Util --- src/main/java/org/openslx/imagemaster/util/Util.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/main/java/org/openslx/imagemaster/util') 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; + } + } -- cgit v1.2.3-55-g7522