use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class LsCommand method main.
public static void main(String[] args) throws MongoException, IOException {
if (args.length != 3) {
System.err.println("List a file or directory:");
System.err.println(" ls <root> <path>");
System.exit(1);
}
V7GridFS fs = new V7GridFS(Configuration.getMongo().getDB(Configuration.getProperty("mongo.db")));
String root = args[1];
String path = args[2];
String[] fullPath = ArrayUtils.add(StringUtils.split(path, '/'), 0, root);
V7File file = fs.getFile(fullPath);
if (file == null) {
System.err.println("file not found");
System.exit(1);
}
if (file.hasContent()) {
System.out.format(" %10d %80s\n", file.getLength(), file.getName());
}
List<V7File> children = file.getChildren();
Collections.sort(children, new Comparator<V7File>() {
public int compare(V7File o1, V7File o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (V7File child : children) {
if (child.getLength() == null)
System.out.format("d %10s %80s\n", "", child.getName());
}
for (V7File child : children) {
if (child.getLength() != null)
System.out.format("- %10d %80s %10s\n", child.getLength(), child.getName(), child.getDigest().substring(0, 10));
}
}
Aggregations