@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; }
/** * Parses the input args with a command line format, using * {@link org.apache.commons.cli.CommandLineParser}. * * @param args the input args * @return true if parsing succeeded */ private static boolean parseInputArgs(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args); } catch (ParseException e) { System.out.println("Failed to parse input args: " + e); return false; } sHelp = cmd.hasOption("help"); sType = OperationType.valueOf(cmd.getOptionValue("type", "READ")); sFileSize = FormatUtils.parseSpaceSize(cmd.getOptionValue("fileSize", "1KB")); sIterations = Integer.parseInt(cmd.getOptionValue("iterations", "1")); sConcurrency = Integer.parseInt(cmd.getOptionValue("concurrency", "1")); return true; }
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(); }
@Override public long getBytes(PropertyKey key) { String rawValue = get(key); try { return FormatUtils.parseSpaceSize(rawValue); } catch (Exception ex) { throw new RuntimeException(ExceptionMessage.KEY_NOT_BYTES.getMessage(key)); } }
for (int i = 0; i < dirPaths.length; i++) { int index = i >= dirQuotas.length ? dirQuotas.length - 1 : i; long capacity = FormatUtils.parseSpaceSize(dirQuotas[index]); try { StorageDir dir = StorageDir.newStorageDir(this, i, capacity, dirPaths[i]);
break; long quota = FormatUtils.parseSpaceSize(dirQuotas[index]); success &= addDirectoryInfo(dirPaths[i], quota, storageMap);
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); int numOfBytes = Constants.KB; if (cl.hasOption('c')) { numOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c')); Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0"); } if (status.isFolder()) { throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path)); } OpenFilePOptions options = OpenFilePOptions.getDefaultInstance(); try (FileInStream is = mFileSystem.openFile(path, options)) { byte[] buf = new byte[numOfBytes]; long bytesToRead; if (status.getLength() > numOfBytes) { bytesToRead = numOfBytes; } else { bytesToRead = status.getLength(); } is.skip(status.getLength() - bytesToRead); int read = is.read(buf); if (read != -1) { System.out.write(buf, 0, read); } } }
long max = 10240; for (long k = 0; k < max; k++) { Assert.assertEquals(k / 10, FormatUtils.parseSpaceSize(k / 10.0 + "b")); Assert.assertEquals(k / 10, FormatUtils.parseSpaceSize(k / 10.0 + "B")); Assert.assertEquals(k / 10, FormatUtils.parseSpaceSize(k / 10.0 + "")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "kb")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "Kb")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "KB")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "kB")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "k")); Assert.assertEquals(k * Constants.KB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "K")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "mb")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "Mb")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "MB")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "mB")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "m")); Assert.assertEquals(k * Constants.MB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "M")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "gb")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "Gb")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "GB")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "gB")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "g")); Assert.assertEquals(k * Constants.GB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "G")); Assert.assertEquals(k * Constants.TB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "tb")); Assert.assertEquals(k * Constants.TB / 10, FormatUtils.parseSpaceSize(k / 10.0 + "Tb"));
byteUnit = ByteUnit.valueOf(arg); System.out.println( FormatUtils.parseSpaceSize(property.getValue()) / byteUnit.getValue()); break; } catch (Exception e) {
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(); }
@Override public long getBytes(PropertyKey key) { String rawValue = get(key); try { return FormatUtils.parseSpaceSize(rawValue); } catch (Exception ex) { throw new RuntimeException(ExceptionMessage.KEY_NOT_BYTES.getMessage(key)); } }
/** * Parses the input args with a command line format, using * {@link org.apache.commons.cli.CommandLineParser}. * * @param args the input args * @return true if parsing succeeded */ private static boolean parseInputArgs(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args); } catch (ParseException e) { System.out.println("Failed to parse input args: " + e); return false; } sHelp = cmd.hasOption("help"); sType = OperationType.valueOf(cmd.getOptionValue("type", "READ")); sFileSize = FormatUtils.parseSpaceSize(cmd.getOptionValue("fileSize", "1KB")); sIterations = Integer.parseInt(cmd.getOptionValue("iterations", "1")); sConcurrency = Integer.parseInt(cmd.getOptionValue("concurrency", "1")); return true; }
break; long quota = FormatUtils.parseSpaceSize(dirQuotas[index]); success &= addDirectoryInfo(dirPaths[i], quota, storageMap);