/** Constructor */ SetQuotaCommand(String[] args, int pos, Configuration conf) { super(conf); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); this.quota = StringUtils.TraditionalBinaryPrefix.string2long(parameters.remove(0)); this.args = parameters.toArray(new String[parameters.size()]); }
bandwidth = StringUtils.TraditionalBinaryPrefix.string2long(argv[idx]); } catch (NumberFormatException nfe) { System.err.println("NumberFormatException: " + nfe.getMessage());
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, Configuration conf) { super(conf); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); try { quota = StringUtils.TraditionalBinaryPrefix.string2long(str); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota."); } String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { try { this.type = StorageType.parseStorageType(storageTypeString); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Storage type " + storageTypeString + " is not available. Available storage types are " + StorageType.getTypesSupportingQuota()); } } this.args = parameters.toArray(new String[parameters.size()]); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) { return defaultValue; } return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); try { quota = StringUtils.TraditionalBinaryPrefix.string2long(str); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota."); } String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } this.args = parameters.toArray(new String[parameters.size()]); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @throws NumberFormatException when the value is invalid * @throws NullPointerException if the configuration property does not exist * @return property value as a <code>long</code> */ public long getLongBytes(String name) { String valueString = getTrimmed(name); Preconditions.checkNotNull(valueString); return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); try { quota = StringUtils.TraditionalBinaryPrefix.string2long(str); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota."); } String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } this.args = parameters.toArray(new String[parameters.size()]); }
private Integer extractMegabytes(Properties conf, String[] names) { String javaOptions = extract(conf, names, null); if (javaOptions == null) { return null; } Matcher matcher = heapPattern.matcher(javaOptions); Integer heapMegabytes = null; while (matcher.find()) { String heapSize = matcher.group(1); heapMegabytes = ((int) (StringUtils.TraditionalBinaryPrefix.string2long(heapSize) / BYTES_IN_MEG)); } return heapMegabytes; }
private static long parseSuffixed(String value) { return StringUtils.TraditionalBinaryPrefix.string2long(value); }
private long parseLong(String[] args, int offset) { if (offset == args.length) { throw new IllegalArgumentException("<n> not specified in " + cmd); } long n = StringUtils.TraditionalBinaryPrefix.string2long(args[offset]); if (n <= 0) { throw new IllegalArgumentException("n = " + n + " <= 0 in " + cmd); } return n; } }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(NAME, 2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); quota = StringUtils.TraditionalBinaryPrefix.string2long(str); this.args = parameters.toArray(new String[parameters.size()]); }
private Integer extractMegabytes(Properties conf, String[] names) { String javaOptions = extract(conf, names, null); if (javaOptions == null) { return null; } Matcher matcher = heapPattern.matcher(javaOptions); Integer heapMegabytes = null; while (matcher.find()) { String heapSize = matcher.group(1); heapMegabytes = ((int) (StringUtils.TraditionalBinaryPrefix.string2long(heapSize) / BYTES_IN_MEG)); } return heapMegabytes; }
@Test public void testTraditionalBinaryPrefix() throws Exception { String[] symbol = {"k", "m", "g", "t", "p", "e"}; long m = 1024; for(String s : symbol) { assertEquals(0, StringUtils.TraditionalBinaryPrefix.string2long(0 + s)); assertEquals(m, StringUtils.TraditionalBinaryPrefix.string2long(1 + s)); m *= 1024; } assertEquals(0L, StringUtils.TraditionalBinaryPrefix.string2long("0")); assertEquals(-1259520L, StringUtils.TraditionalBinaryPrefix.string2long("-1230k")); assertEquals(956703965184L, StringUtils.TraditionalBinaryPrefix.string2long("891g")); }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(NAME, 2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); quota = StringUtils.TraditionalBinaryPrefix.string2long(str); this.args = parameters.toArray(new String[parameters.size()]); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
private static long parseSuffixed(String value) { return StringUtils.TraditionalBinaryPrefix.string2long(value); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }
/** * Get the value of the <code>name</code> property as a <code>long</code> or * human readable format. If no such property exists, the provided default * value is returned, or if the specified value is not a valid * <code>long</code> or human readable format, then an error is thrown. You * can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), * t(tera), p(peta), e(exa) * * @param name property name. * @param defaultValue default value. * @throws NumberFormatException when the value is invalid * @return property value as a <code>long</code>, * or <code>defaultValue</code>. */ public long getLongBytes(String name, long defaultValue) { String valueString = getTrimmed(name); if (valueString == null) return defaultValue; return StringUtils.TraditionalBinaryPrefix.string2long(valueString); }