core/src/main/java/nl/nn/adapterframework/util/Misc.java
/**
	 * Converts the file size to bytes.
	 * <pre>Misc.toFileSize("14GB", 20); // gives out 15032385536</pre>
	 */
Converts the file size to bytes.
Converts the file size to bytes .
public static long toFileSize(String value, long defaultValue) {
		if(value == null)
			return defaultValue;
		String s = value.trim().toUpperCase();
		long multiplier = 1;
		int index;
		if((index = s.indexOf("KB")) != -1) {
			multiplier = 1024;
			s = s.substring(0, index);
		}
		else if((index = s.indexOf("MB")) != -1) {
			multiplier = 1024L*1024;
			s = s.substring(0, index);
		}
		else if((index = s.indexOf("GB")) != -1) {
			multiplier = 1024L*1024*1024;
			s = s.substring(0, index);
		}
		if(s != null) {
			try {
				return Long.parseLong(s) * multiplier;
			}
			catch (NumberFormatException e) {
				log.error("[" + value + "] not in expected format", e);
			}
		}
		return defaultValue;
	}
public static long toFileSize ( String value , long defaultValue ) { if ( value == null ) return defaultValue ; String s = value . trim ( ) . toUpperCase ( ) ; long multiplier = 1 ; int index ; if ( ( index = s . indexOf ( "KB" ) ) != - 1 ) { multiplier = 1024 ; s = s . substring ( 0 , index ) ; } else if ( ( index = s . indexOf ( "MB" ) ) != - 1 ) { multiplier = 1024L * 1024 ; s = s . substring ( 0 , index ) ; } else if ( ( index = s . indexOf ( "GB" ) ) != - 1 ) { multiplier = 1024L * 1024 * 1024 ; s = s . substring ( 0 , index ) ; } if ( s != null ) { try { return Long . parseLong ( s ) * multiplier ; } catch ( NumberFormatException e ) { log . error ( "[" + value + "] not in expected format" , e ) ; } } return defaultValue ; }
Converts the file size to bytes.
Converts the file size to bytes .