org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(TraditionalBinaryPrefix.long2String(bc.getMaxSize(), "B", 1)), jamonWriter); org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(TraditionalBinaryPrefix.long2String(bc.getCurrentSize(), "B", 1)), jamonWriter); org.jamon.escaping.Escaping.HTML.write(org.jamon.emit.StandardEmitter.valueOf(TraditionalBinaryPrefix.long2String(bc.getCurrentDataSize(), "B", 1)), jamonWriter);
private TraditionalBinaryPrefix(int bitShift) { this.bitShift = bitShift; this.value = 1L << bitShift; this.bitMask = this.value - 1L; this.symbol = toString().charAt(0); }
try { Long packetSize = StringUtils.TraditionalBinaryPrefix .string2long(pSize); base.set(ConfigOption.PACKET_SIZE.getCfgOption(), packetSize .toString());
try { Long packetSize = StringUtils.TraditionalBinaryPrefix .string2long(pSize); base.set(ConfigOption.PACKET_SIZE.getCfgOption(), packetSize .toString());
long m = 1024; for(String s : symbol) { assertEquals(0, string2long(0 + s)); assertEquals(m, string2long(1 + s)); m *= 1024; assertEquals(0L, string2long("0")); assertEquals(1024L, string2long("1k")); assertEquals(-1024L, string2long("-1k")); assertEquals(1259520L, string2long("1230K")); assertEquals(-1259520L, string2long("-1230K")); assertEquals(104857600L, string2long("100m")); assertEquals(-104857600L, string2long("-100M")); assertEquals(956703965184L, string2long("891g")); assertEquals(-956703965184L, string2long("-891G")); assertEquals(501377302265856L, string2long("456t")); assertEquals(-501377302265856L, string2long("-456T")); assertEquals(11258999068426240L, string2long("10p")); assertEquals(-11258999068426240L, string2long("-10P")); assertEquals(1152921504606846976L, string2long("1e")); assertEquals(-1152921504606846976L, string2long("-1E")); string2long(tooLargeNumStr); fail("Test passed for a number " + tooLargeNumStr + " too large"); } catch (IllegalArgumentException e) { string2long(tooSmallNumStr); fail("Test passed for a number " + tooSmallNumStr + " too small"); } catch (IllegalArgumentException e) {
long m = 1024; for(String s : symbol) { assertEquals(0, string2long(0 + s)); assertEquals(m, string2long(1 + s)); m *= 1024; assertEquals(0L, string2long("0")); assertEquals(1024L, string2long("1k")); assertEquals(-1024L, string2long("-1k")); assertEquals(1259520L, string2long("1230K")); assertEquals(-1259520L, string2long("-1230K")); assertEquals(104857600L, string2long("100m")); assertEquals(-104857600L, string2long("-100M")); assertEquals(956703965184L, string2long("891g")); assertEquals(-956703965184L, string2long("-891G")); assertEquals(501377302265856L, string2long("456t")); assertEquals(-501377302265856L, string2long("-456T")); assertEquals(11258999068426240L, string2long("10p")); assertEquals(-11258999068426240L, string2long("-10P")); assertEquals(1152921504606846976L, string2long("1e")); assertEquals(-1152921504606846976L, string2long("-1E")); string2long(tooLargeNumStr); fail("Test passed for a number " + tooLargeNumStr + " too large"); } catch (IllegalArgumentException e) { string2long(tooSmallNumStr); fail("Test passed for a number " + tooSmallNumStr + " too small"); } catch (IllegalArgumentException e) {
genbytes = StringUtils.TraditionalBinaryPrefix.string2long(argv[++i]); if (genbytes <= 0) { LOG.error("size of input data to be generated specified using "
String min = pieces[0]; String max = pieces[1]; long tMin = StringUtils.TraditionalBinaryPrefix.string2long(min); long tMax = StringUtils.TraditionalBinaryPrefix.string2long(max); if (tMin > tMax) { long tmp = tMin;
String min = pieces[0]; String max = pieces[1]; long tMin = StringUtils.TraditionalBinaryPrefix.string2long(min); long tMax = StringUtils.TraditionalBinaryPrefix.string2long(max); if (tMin > tMax) { long tmp = tMin;
long prefix; try { prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid size prefix '" + lastchar
long prefix; try { prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid size prefix '" + lastchar
long prefix; try { prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid size prefix '" + lastchar
long prefix; try { prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid size prefix '" + lastchar
/** * Convert a string to long. * The input string is first be trimmed * and then it is parsed with traditional binary prefix. * * For example, * "-1230k" will be converted to -1230 * 1024 = -1259520; * "891g" will be converted to 891 * 1024^3 = 956703965184; * * @param s input string * @return a long value represented by the input string. */ public static long string2long(String s) { s = s.trim(); final int lastpos = s.length() - 1; final char lastchar = s.charAt(lastpos); if (Character.isDigit(lastchar)) return Long.parseLong(s); else { long prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; long num = Long.parseLong(s.substring(0, lastpos)); if (num > (Long.MAX_VALUE/prefix) || num < (Long.MIN_VALUE/prefix)) { throw new IllegalArgumentException(s + " does not fit in a Long"); } return num * prefix; } } }
/** * Convert a string to long. * The input string is first be trimmed * and then it is parsed with traditional binary prefix. * * For example, * "-1230k" will be converted to -1230 * 1024 = -1259520; * "891g" will be converted to 891 * 1024^3 = 956703965184; * * @param s input string * @return a long value represented by the input string. */ public static long string2long(String s) { s = s.trim(); final int lastpos = s.length() - 1; final char lastchar = s.charAt(lastpos); if (Character.isDigit(lastchar)) return Long.parseLong(s); else { long prefix = TraditionalBinaryPrefix.valueOf(lastchar).value; long num = Long.parseLong(s.substring(0, lastpos)); if (num > (Long.MAX_VALUE/prefix) || num < (Long.MIN_VALUE/prefix)) { throw new IllegalArgumentException(s + " does not fit in a Long"); } return num * prefix; } } }