@Override public String toString() { return "(memory: " + StorageUtil.toHumanReadableSize(aggregatedMemoryByteSize) + " bytes, CPU cores: " + aggregatedCores + ")"; } }
@Override public Long parse(String s) { return s == null ? null : StorageUtil.getByteValue(s); }
/** * Return byte value for the given string (e.g., 0.1KB, 100kb, 1mb, 3MB, 8.5GB ...) * * @throws IllegalArgumentException */ public static long getByteValue(String s) { double result = getSizeInBytes(s); if (result > Long.MAX_VALUE || result < Long.MIN_VALUE) { throw new IllegalArgumentException("The given value:" + result + " is not within the long range."); } else { return (long) result; } }
/** * Mounts a RAM disk * * @param name * @param size * @param unit * @return The root of the mounted disk * @throws IOException * @throws InterruptedException */ public static Path mountRamDisk(String name, int size, StorageUtil.StorageUnit unit) throws IOException, InterruptedException { if (SystemUtils.IS_OS_MAC) { return mountMacRamDisk(name, (StorageUtil.getIntSizeInBytes(size, unit) * 2) / StorageUtil.BASE); } else if (SystemUtils.IS_OS_LINUX) { return mountLinuxRamDisk(name, size + unit.getLinuxUnitTypeInLetter()); } throw new UnsupportedOperationException("Unsupported OS: " + System.getProperty("os.name")); }
unitType = StorageUnit.BYTE; } else { throw invalidFormatException(s); unitType = StorageUnit.BYTE; } else { throw invalidFormatException(s); throw invalidFormatException(s);
final CompilerProperties compilerProperties = Mockito.mock(CompilerProperties.class); Mockito.when(appCtx.getCompilerProperties()).thenReturn(compilerProperties); Mockito.when(compilerProperties.getFrameSize()).thenReturn(StorageUtil.getIntSizeInBytes(32, KILOBYTE)); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter out = new PrintWriter(baos, true);
@Override public String serializeToHumanReadable(Object value) { return value + " (" + StorageUtil.toHumanReadableSize((long) value) + ")"; }
@Override public Integer parse(String s) { if (s == null) { return null; } long result1 = StorageUtil.getByteValue(s); if (result1 > Integer.MAX_VALUE || result1 < Integer.MIN_VALUE) { throw new IllegalArgumentException("The given value: " + result1 + " is not within the int range."); } return (int) result1; }
@Override public String serializeToHumanReadable(Object value) { return value + " (" + StorageUtil.toHumanReadableSize((int) value) + ")"; }
private String truncateIfLong(String string) { if (string.length() < TRUNCATE_THRESHOLD) { return string; } final StringBuilder truncatedString = new StringBuilder(string); truncatedString.setLength(TRUNCATE_THRESHOLD); truncatedString.append("\n<truncated ") .append(StorageUtil.toHumanReadableSize(string.length() - TRUNCATE_THRESHOLD)).append("...>"); return truncatedString.toString(); }