Parses file size from a string. The units GB, MB, KB and bytes are supported.

@param argument
Lower case file size
@return Parsed file size
@throws NumberFormatException
Failed to parse file size
777702
private static long parse(final String argument) throws NumberFormatException {
		if (argument.endsWith("gb")) {
			return Long.parseLong(argument.substring(0, argument.length() - "gb".length()).trim()) * GB;
		} else if (argument.endsWith("mb")) {
			return Long.parseLong(argument.substring(0, argument.length() - "mb".length()).trim()) * MB;
		} else if (argument.endsWith("kb")) {
			return Long.parseLong(argument.substring(0, argument.length() - "kb".length()).trim()) * KB;
		} else if (argument.endsWith("bytes")) {
			return Long.parseLong(argument.substring(0, argument.length() - "bytes".length()).trim());
		} else {
			return Long.parseLong(argument.trim());
		}
	}
444564
def parse_size(size):
        
        if size.startswith('x'):
            return None, int(size.replace('x', ''))
        if 'x' in size:
            return int(size.split('x')[0]), int(size.split('x')[1])
        return int(size), None
221939
private String sizeToString(final long aSizeInBytes) {
        final String size = sizeFromBytes(aSizeInBytes, true).replace(" ", "");
        return size.substring(0, size.length() - 1);
    }
189741
def sizeof_fmt(num):
    
    units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']
    decimals = [0, 0, 1, 2, 2, 2]
    if num > 1:
        exponent = min(int(log(num, 1024)), len(units) - 1)
        quotient = float(num) / 1024 ** exponent
        unit = units[exponent]
        num_decimals = decimals[exponent]
        format_string = '{0:.%sf} {1}' % (num_decimals)
        return format_string.format(quotient, unit)
    if num == 0:
        return '0 bytes'
    if num == 1:
        return '1 byte'
768438
public static String byte2FitMemorySize(final long byteNum) {
        if (byteNum < 0) {
            return "shouldn't be less than zero!";
        } else if (byteNum < MemoryConst.KB) {
            return String.format("%.3fB", (double) byteNum);
        } else if (byteNum < MemoryConst.MB) {
            return String.format("%.3fKB", (double) byteNum / MemoryConst.KB);
        } else if (byteNum < MemoryConst.GB) {
            return String.format("%.3fMB", (double) byteNum / MemoryConst.MB);
        } else {
            return String.format("%.3fGB", (double) byteNum / MemoryConst.GB);
        }
    }
1137434
public Coin parse(String str) throws NumberFormatException {
        return Coin.valueOf(parseValue(str, Coin.SMALLEST_UNIT_EXPONENT));
    }
623058
public static String formatSize(double size) {
        double kiloByte = size / 1024;
        if (kiloByte < 1) {
            return size + "Byte";
        }

        double megaByte = kiloByte / 1024;
        if (megaByte < 1) {
            BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
            return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
        }

        double gigaByte = megaByte / 1024;
        if (gigaByte < 1) {
            BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
            return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
        }

        double teraBytes = gigaByte / 1024;
        if (teraBytes < 1) {
            BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
            return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
        }
        BigDecimal result4 = new BigDecimal(teraBytes);
        return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
    }
149853
protected Number parseInteger(String string) throws ParseException {
		try {
			return Long.valueOf(string);
		} catch (NumberFormatException e) {
			fail(INTEGER);
			return null;
		}
	}
595820
public static String formatSize(final long value) {
        double size = value;
        DecimalFormat df = new DecimalFormat("#.##");
        if (size >= GB) {
            return df.format(size / GB) + " GB";
        }
        if (size >= MB) {
            return df.format(size / MB) + " MB";
        }
        if (size >= KB) {
            return df.format(size / KB) + " KB";
        }
        return String.valueOf((int) size) + " bytes";
    }
1247752
private function parseSize($sizeString)
    {
        if(!$sizeString)
            $sizeString = $this->defaultSize;
        $sizeArray = explode('x', $sizeString);
        $part1 = (isset($sizeArray[0]) and $sizeArray[0] != '');
        $part2 = (isset($sizeArray[1]) and $sizeArray[1] != '');
        if ($part1 && $part2) {
            if (intval($sizeArray[0]) > 0
                &&
                intval($sizeArray[1]) > 0
            ) {
                $size = [
                    'width' => intval($sizeArray[0]),
                    'height' => intval($sizeArray[1])
                ];
            } else {
                $size = null;
            }
        } elseif ($part1 && !$part2) {
            $size = [
                'width' => intval($sizeArray[0]),
                'height' => null
            ];
        } elseif (!$part1 && $part2) {
            $size = [
                'width' => null,
                'height' => intval($sizeArray[1])
            ];
        } else {
            throw new \Exception('Error parsing size.');
        }
        return $size;
    }
1156370
public String getFormatted(String key, String argument) {
        return MessageFormat.format(resource.getString(key), new Object[] {argument});
    }
1368630
public static long parseTimeSize(String timeSize) {
    double alpha = 0.0001;
    String time = "";
    String size = "";
    Matcher m = SEP_DIGIT_LETTER.matcher(timeSize);
    if (m.matches()) {
      time = m.group(1);
      size = m.group(2);
    }
    double douTime = Double.parseDouble(time);
    long sign = 1;
    if (douTime < 0) {
      sign = -1;
      douTime = -douTime;
    }
    size = size.toLowerCase();
    if (size.isEmpty() || size.equalsIgnoreCase("ms")
        || size.equalsIgnoreCase("millisecond")) {
      return sign * (long) (douTime + alpha);
    } else if (size.equalsIgnoreCase("s") || size.equalsIgnoreCase("sec")
        || size.equalsIgnoreCase("second")) {
      return sign * (long) (douTime * Constants.SECOND + alpha);
    } else if (size.equalsIgnoreCase("m") || size.equalsIgnoreCase("min")
        || size.equalsIgnoreCase("minute")) {
      return sign * (long) (douTime * Constants.MINUTE + alpha);
    } else if (size.equalsIgnoreCase("h") || size.equalsIgnoreCase("hr")
        || size.equalsIgnoreCase("hour")) {
      return sign * (long) (douTime * Constants.HOUR + alpha);
    } else if (size.equalsIgnoreCase("d") || size.equalsIgnoreCase("day")) {
      return sign * (long) (douTime * Constants.DAY + alpha);
    } else {
      throw new IllegalArgumentException("Fail to parse " + timeSize + " to milliseconds");
    }
  }
76566
private void parseLimitMessageSize(Map<Object, Object> props) {
        Object value = props.get(HttpConfigConstants.PROPNAME_MSG_SIZE_LIMIT);
        if (null != value) {
            try {
                this.limitMessageSize = convertLong(value);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "Config: Message size limit is " + getMessageSizeLimit());
                }
            } catch (NumberFormatException nfe) {
                FFDCFilter.processException(nfe, getClass().getName() + ".parseLimitMessageSize", "1");
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "Config: Invalid message size limit; " + value);
                }
            }
        }
    }
923711
private Size parseSize(String token) {
        if (token.startsWith("[") && token.endsWith("]")) {
            return parseBoundedSize(token);
        }
        if (token.startsWith("max(") && token.endsWith(")")) {
            return parseOldBoundedSize(token, false);
        }
        if (token.startsWith("min(") && token.endsWith(")")) {
            return parseOldBoundedSize(token, true);
        }
        return parseAtomicSize(token);
    }
224578
public static double parseFloat(InputStream inputStream, final int size) throws IOException {
        byte[] buffer = new byte[size];
        int numberOfReadsBytes = inputStream.read(buffer, 0, size);
        assert numberOfReadsBytes == size;

        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.BIG_ENDIAN);
        if (8 == size) {
            return byteBuffer.getDouble();
        }

        return byteBuffer.getFloat();
    }
838040
private static String checkBufferSize(final String str) {
        // try to get value
        int nb_mega;
        try {
            nb_mega = Integer.parseInt(str);
        } catch (final NumberFormatException e) {
            return null;
        }

        // Compute the real size and the power of 2
        final long size = (long) nb_mega * 1024 * 1024;
        long l = size;
        int cnt;
        for (cnt = 0; l > 0; cnt++) {
            l >>= 1;
        }
        cnt--;

        // Check if number ob Mb is not power of 2
        if (Math.pow(2, cnt) < size) {
            cnt++;
        }
        System.out.println(nb_mega + " Mbytes  (2^" + cnt + ")");

        final int jacorb_size = cnt - 4;
        return Integer.toString(jacorb_size);
    }
1287873
private static int getBytesSize(ArrayList<String> arr) {
        int count=0;
        
        for (String str : arr) {
            count = count + str.length();
        }
        return count;
    }