@Override public Long convert(String value) { return ConfigurationTypeHelper.getFixedMemoryAsBytes(value); } }
@Override public void init(Map<String,String> options) { limit = ConfigurationTypeHelper.getFixedMemoryAsBytes(options.get(SIZE_LIMIT_OPT)); }
@Override public String convert(String str) { long size = ConfigurationTypeHelper.getFixedMemoryAsBytes(str); checkArgument(size > 0); return Long.toString(size); } }
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { sourceIter = source; if (options.containsKey(MAX_BUFFER_SIZE_OPT)) { maxBufferSize = ConfigurationTypeHelper .getFixedMemoryAsBytes(options.get(MAX_BUFFER_SIZE_OPT)); } }
@Override public boolean validateOptions(Map<String,String> options) { String maxBufferSizeStr = options.get(MAX_BUFFER_SIZE_OPT); try { ConfigurationTypeHelper.getFixedMemoryAsBytes(maxBufferSizeStr); } catch (Exception e) { throw new IllegalArgumentException( "Failed to parse opt " + MAX_BUFFER_SIZE_OPT + " " + maxBufferSizeStr, e); } return true; }
@Override public void init(Map<String,String> options) { String threshold = options.get(LARGE_FILE_COMPRESSION_THRESHOLD); largeFileCompressionType = options.get(LARGE_FILE_COMPRESSION_TYPE); verifyRequiredProperties(threshold, largeFileCompressionType); largeFileCompressionThreshold = ConfigurationTypeHelper.getFixedMemoryAsBytes(threshold); }
@Override public boolean validateOptions(Map<String,String> options) { for (Entry<String,String> option : options.entrySet()) { try { if (option.getKey().equals(AUTH_OPT)) { new Authorizations(option.getValue().getBytes(UTF_8)); } else if (option.getKey().equals(MAX_BUFFER_SIZE_OPT)) { ConfigurationTypeHelper.getFixedMemoryAsBytes(option.getValue()); } } catch (Exception e) { throw new IllegalArgumentException( "Failed to parse opt " + option.getKey() + " " + option.getValue(), e); } } return true; }
/** * Interprets a string specifying a Memory type which is specified as a long integer followed by * an optional B (bytes), K (KB), M (MB), G (GB) or % (percentage). * * @param str * String value * @return interpreted memory size in bytes */ public static long getMemoryAsBytes(String str) { char lastChar = str.charAt(str.length() - 1); if (lastChar == '%') { try { int percent = Integer.parseInt(str.substring(0, str.length() - 1)); if (percent <= 0 || percent >= 100) { throw new IllegalArgumentException( "The value '" + str + "' is not a valid memory setting."); } return Runtime.getRuntime().maxMemory() * percent / 100; } catch (Exception ex) { throw new IllegalArgumentException( "The value '" + str + "' is not a valid memory setting."); } } return getFixedMemoryAsBytes(str); }
maxMergingMinorCompactionFileSize = ConfigurationTypeHelper.getFixedMemoryAsBytes( tablet.getTableConfiguration().get(Property.TABLE_MINC_MAX_MERGE_FILE_SIZE)); if (maxMergingMinorCompactionFileSize > 0) {
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { super.init(source, options, env); scanning = IteratorScope.scan.equals(env.getIteratorScope()); if (scanning) { String auths = options.get(AUTH_OPT); if (auths != null && !auths.isEmpty()) { ve = new VisibilityEvaluator(new Authorizations(auths.getBytes(UTF_8))); visibleCache = new LRUMap(100); } } if (options.containsKey(MAX_BUFFER_SIZE_OPT)) { maxBufferSize = ConfigurationTypeHelper .getFixedMemoryAsBytes(options.get(MAX_BUFFER_SIZE_OPT)); } else { maxBufferSize = DEFAULT_MAX_BUFFER_SIZE; } parsedVisibilitiesCache = new LRUMap(100); }
/** * Gets a property of type {@link PropertyType#BYTES} or {@link PropertyType#MEMORY}, interpreting * the value properly. * * @param property * Property to get * @return property value * @throws IllegalArgumentException * if the property is of the wrong type */ public long getAsBytes(Property property) { String memString = get(property); if (property.getType() == PropertyType.MEMORY) { return ConfigurationTypeHelper.getMemoryAsBytes(memString); } else if (property.getType() == PropertyType.BYTES) { return ConfigurationTypeHelper.getFixedMemoryAsBytes(memString); } else { throw new IllegalArgumentException(property.getKey() + " is not of BYTES or MEMORY type"); } }
size = ConfigurationTypeHelper.getFixedMemoryAsBytes(cl.getOptionValue(sizeOpt.getOpt()));
long bsize = ConfigurationTypeHelper.getFixedMemoryAsBytes(value); Preconditions.checkArgument(bsize > 0 && bsize < Integer.MAX_VALUE, key + " must be greater than 0 and less than " + Integer.MAX_VALUE + " but was: " + bsize);