Skip to content

Commit

Permalink
Fixes #6 : Tool fails with MissingFormatArgumentException
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmay committed Sep 17, 2017
1 parent 3aa4beb commit 4e376d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 13 additions & 0 deletions tool/src/main/java/de/m3y/hadoop/hdfs/hfsa/tool/FormatUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.m3y.hadoop.hdfs.hfsa.tool;

import java.util.Arrays;

/**
* Helps formatting output.
*/
Expand Down Expand Up @@ -72,4 +74,15 @@ static String padRight(char c, int length) {
}
return buf.toString();
}

public static Object[] boxAndPadWithZeros(int length, long[] values) {
long[] padded;
if (values.length == length) {
padded = values;
} else {
padded = new long[length];
System.arraycopy(values, 0, padded, 0, values.length);
}
return Arrays.stream(padded).boxed().toArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static void doSummary(CliOptions options, Report report) {
overallStats.sumDirectories, overallStats.sumSymLinks,
overallStats.sumFiles, overallStats.sumFileSize / 1024L / 1024L,
overallStats.sumBlocks,
String.format(bucketFormatValue, Arrays.stream(overallStats.fileSizeBuckets.get()).boxed().toArray())
String.format(bucketFormatValue,
FormatUtil.boxAndPadWithZeros(maxLength.length, overallStats.fileSizeBuckets.get()))
));
System.out.println();

Expand All @@ -147,7 +148,8 @@ static void doSummary(CliOptions options, Report report) {
stat.groupName, stat.sumDirectories, stat.sumSymLinks,
stat.sumFiles, stat.sumFileSize / 1024L / 1024L,
stat.sumBlocks,
String.format(bucketFormatValue, Arrays.stream(stat.fileSizeBuckets.get()).boxed().toArray())
String.format(bucketFormatValue,
FormatUtil.boxAndPadWithZeros(maxLength.length, stat.fileSizeBuckets.get()))
));
}

Expand All @@ -166,7 +168,8 @@ static void doSummary(CliOptions options, Report report) {
stat.userName, stat.sumDirectories, stat.sumSymLinks,
stat.sumFiles, stat.sumFileSize / 1024L / 1024L,
stat.sumBlocks,
String.format(bucketFormatValue, Arrays.stream(stat.fileSizeBuckets.get()).boxed().toArray())
String.format(bucketFormatValue,
FormatUtil.boxAndPadWithZeros(maxLength.length, stat.fileSizeBuckets.get()))
));
}
}
Expand Down Expand Up @@ -251,7 +254,7 @@ public void onSymLink(FsImageProto.INodeSection.INode inode, String path) {
System.out.println("Ignoring symlink: " + inode.getName().toStringUtf8());
overallStats.sumSymLinks++;
final FsImageProto.INodeSection.INodeSymlink symlink = inode.getSymlink();
if(symlink.hasPermission()) {
if (symlink.hasPermission()) {
PermissionStatus p = loader.getPermissionStatus(symlink.getPermission());

// Group stats
Expand Down

0 comments on commit 4e376d4

Please sign in to comment.