diff options
| author | Nils Schwabe | 2014-07-23 16:06:47 +0200 |
|---|---|---|
| committer | Nils Schwabe | 2014-07-23 16:06:47 +0200 |
| commit | a956b282692a5d84fd7efac1b1018cccf41653bf (patch) | |
| tree | 7b595a24a0a00a28e252d7dbd9b434ad59d9d8c3 /src/main/java/org/openslx/imagemaster/util | |
| parent | Fix some bugs while testing the connection (diff) | |
| download | masterserver-a956b282692a5d84fd7efac1b1018cccf41653bf.tar.gz masterserver-a956b282692a5d84fd7efac1b1018cccf41653bf.tar.xz masterserver-a956b282692a5d84fd7efac1b1018cccf41653bf.zip | |
Add "synchronized" to UploadingImage
Add method to calc the amount of blocks to Util
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; + } + } |
