/** * Gets size. * * @return the file size */ public String getSize() { if (mIsDirectory) { return ""; } else { return FormatUtils.getSizeFromBytes(mSize); } }
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); mNumOfBytes = Constants.KB; if (cl.hasOption('c')) { mNumOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c')); Preconditions.checkArgument(mNumOfBytes > 0, "specified bytes must be > 0"); } AlluxioURI path = new AlluxioURI(args[0]); runWildCardCmd(path, cl); return 0; }
/** * Converts the input time into millisecond unit. * * @param time the time to be converted into milliseconds * @return the time in millisecond unit */ public static long getMs(String time) { try { return FormatUtils.parseTimeSize(time); } catch (Exception e) { throw new RuntimeException(ExceptionMessage.INVALID_TIME.getMessage(time)); } }
break; long quota = FormatUtils.parseSpaceSize(dirQuotas[index]); success &= addDirectoryInfo(dirPaths[i], quota, storageMap); for (Map.Entry<String, Long> directoryQuota : storage.getDirectoryQuotas().entrySet()) { builder.append(String.format("- Quota for %s: %s%n", directoryQuota.getKey(), FormatUtils.getSizeFromBytes(directoryQuota.getValue()))); + "Available: %s (Additional %s free space required)%n", level, storageEntry.getKey(), FormatUtils.getSizeFromBytes(quota), builder.toString(), FormatUtils.getSizeFromBytes(used), FormatUtils.getSizeFromBytes(available), FormatUtils.getSizeFromBytes(quota - used - available)); success = false;
byteUnit = ByteUnit.valueOf(arg); System.out.println( FormatUtils.parseSpaceSize(property.getValue()) / byteUnit.getValue()); break; } catch (Exception e) { timeUnit = TimeUnit.valueOf(arg); System.out.println( FormatUtils.parseTimeSize(property.getValue()) / timeUnit.getValue()); break; } catch (IllegalArgumentException ex) {
/** * Creates a new instance of {@link alluxio.util.webui.UIFileInfo}. * * @param fileInfo underlying {@link alluxio.util.webui.UIFileInfo.LocalFileInfo} */ public UIFileInfo(UIFileInfo.LocalFileInfo fileInfo) { mId = -1; mName = fileInfo.mName; mAbsolutePath = fileInfo.mAbsolutePath; mBlockSizeBytes = 0; mSize = fileInfo.mSize; mCreationTimeMs = fileInfo.mCreationTimeMs; mLastModificationTimeMs = fileInfo.mLastModificationTimeMs; mInAlluxio = false; mInAlluxioPercentage = 0; mIsDirectory = fileInfo.mIsDirectory; mPinned = false; mOwner = ""; mGroup = ""; mMode = FormatUtils.formatMode(Mode.createNoAccess().toShort(), true, false); mPersistenceState = PersistenceState.NOT_PERSISTED.name(); mFileLocations = new ArrayList<>(); }
/** * Parses a byte array into a space separated hex string where each byte is represented in the * format {@code 0x%02x}. * * @param bytes the byte array to be transformed * @return the string representation of the byte array */ public static String byteArrayToHexString(byte[] bytes) { return byteArrayToHexString(bytes, "0x", " "); }
private void write(FileSystem alluxioClient) throws IOException, AlluxioException { FileOutStream fileOutStream = createFile(alluxioClient, mFilePath, mDeleteIfExists); long startTimeMs = CommonUtils.getCurrentMs(); try (DataOutputStream os = new DataOutputStream(fileOutStream)) { os.writeInt(mLength); for (int i = 0; i < mLength; i++) { os.writeInt(i); } } LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
if (sDebugMode) { mBuf.flip(); LOG.info(FormatUtils.byteBufferToString(mBuf));
break; long quota = FormatUtils.parseSpaceSize(dirQuotas[index]); success &= addDirectoryInfo(dirPaths[i], quota, storageMap); for (Map.Entry<String, Long> directoryQuota : storage.getDirectoryQuotas().entrySet()) { builder.append(String.format("- Quota for %s: %s%n", directoryQuota.getKey(), FormatUtils.getSizeFromBytes(directoryQuota.getValue()))); + "Available: %s (Additional %s free space required)%n", level, storageEntry.getKey(), FormatUtils.getSizeFromBytes(quota), builder.toString(), FormatUtils.getSizeFromBytes(used), FormatUtils.getSizeFromBytes(available), FormatUtils.getSizeFromBytes(quota - used - available)); success = false;
@Test public void formatPermissionExtendedAcl() { Assert.assertEquals("-rw-rw-rw-+", FormatUtils.formatMode((short) 0666, false, true)); Assert.assertEquals("drw-rw-rw-+", FormatUtils.formatMode((short) 0666, true, true)); Assert.assertEquals("-rwxrwxrwx+", FormatUtils.formatMode((short) 0777, false, true)); Assert.assertEquals("drwxrwxrwx+", FormatUtils.formatMode((short) 0777, true, true)); } }
/** * Tests the {@link FormatUtils#byteArrayToHexString(byte[])} method. */ @Test public void byteArrayToHexString() { Assert.assertEquals("", FormatUtils.byteArrayToHexString(new byte[0])); Assert.assertEquals("0x01", FormatUtils.byteArrayToHexString(new byte[]{1})); Assert.assertEquals("0x01 0xac", FormatUtils.byteArrayToHexString(new byte[]{1, (byte) 0xac})); Assert.assertEquals("01ac", FormatUtils.byteArrayToHexString(new byte[] {1, (byte) 0xac}, "", "")); }
private void writeFile(FileSystem fileSystem) throws IOException, AlluxioException { ByteBuffer buf = ByteBuffer.allocate(NUMBERS * 4); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { buf.putInt(k); } LOG.debug("Writing data..."); long startTimeMs = CommonUtils.getCurrentMs(); FileOutStream os = fileSystem.createFile(mFilePath, mWriteOptions); os.write(buf.array()); os.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
if (sDebugMode) { mBuf.flip(); LOG.info(FormatUtils.byteBufferToString(mBuf));
/** * Gets capacity. * * @return the capacity */ public String getCapacity() { return FormatUtils.getSizeFromBytes(mCapacityBytes); }
private static UnixMountInfo.Options parseUnixMountOptions(String line) { UnixMountInfo.Options.Builder builder = new UnixMountInfo.Options.Builder(); for (String option : line.split(",")) { Matcher matcher = Pattern.compile("(.*)=(.*)").matcher(option.trim()); if (matcher.matches() && matcher.group(1).equalsIgnoreCase("size")) { try { builder.setSize(FormatUtils.parseSpaceSize(matcher.group(2))); } catch (IllegalArgumentException e) { LOG.debug("Failed to parse mount point size: {}", e); } } } return builder.build(); }
/** * Tests the {@link FormatUtils#formatMode(short, boolean, boolean)} method. */ @Test public void formatPermission() { Assert.assertEquals("-rw-rw-rw-", FormatUtils.formatMode((short) 0666, false, false)); Assert.assertEquals("drw-rw-rw-", FormatUtils.formatMode((short) 0666, true, false)); Assert.assertEquals("-rwxrwxrwx", FormatUtils.formatMode((short) 0777, false, false)); Assert.assertEquals("drwxrwxrwx", FormatUtils.formatMode((short) 0777, true, false)); Assert.assertEquals("-r--r--r--", FormatUtils.formatMode((short) 0444, false, false)); Assert.assertEquals("dr--r--r--", FormatUtils.formatMode((short) 0444, true, false)); Assert.assertEquals("-r-xr-xr-x", FormatUtils.formatMode((short) 0555, false, false)); Assert.assertEquals("dr-xr-xr-x", FormatUtils.formatMode((short) 0555, true, false)); Assert.assertEquals("-rwxr-xr--", FormatUtils.formatMode((short) 0754, false, false)); Assert.assertEquals("drwxr-xr--", FormatUtils.formatMode((short) 0754, true, false)); }
/** * Starts {@link DailyMetadataBackup}. */ public void start() { Preconditions.checkState(mBackup == null); long delayedTimeInMillis = getTimeToNextBackup(); mBackup = mScheduledExecutor.scheduleAtFixedRate(this::dailyBackup, delayedTimeInMillis, FormatUtils.parseTimeSize("1day"), TimeUnit.MILLISECONDS); LOG.info("Daily metadata backup scheduled to start in {}", CommonUtils.convertMsToClockTime(delayedTimeInMillis)); }
/** * Parses a byte array into a space separated hex string where each byte is represented in the * format {@code 0x%02x}. * * @param bytes the byte array to be transformed * @return the string representation of the byte array */ public static String byteArrayToHexString(byte[] bytes) { return byteArrayToHexString(bytes, "0x", " "); }
private boolean readFile(FileSystem fileSystem) throws IOException, AlluxioException { boolean pass = true; LOG.debug("Reading data..."); final long startTimeMs = CommonUtils.getCurrentMs(); FileInStream is = fileSystem.openFile(mFilePath, mReadOptions); ByteBuffer buf = ByteBuffer.allocate((int) is.remaining()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { pass = pass && (buf.getInt() == k); } is.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; } }