Search in sources :

Example 11 with V7GridFS

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));
    }
}
Also used : V7File(v7db.files.mongodb.V7File) V7GridFS(v7db.files.mongodb.V7GridFS)

Aggregations

V7GridFS (v7db.files.mongodb.V7GridFS)11 V7File (v7db.files.mongodb.V7File)8 IOException (java.io.IOException)3 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)3 DB (com.mongodb.DB)2 DecoderException (org.apache.commons.codec.DecoderException)2 ObjectId (org.bson.types.ObjectId)2 ContentSHA (v7db.files.spi.ContentSHA)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Properties (java.util.Properties)1 BasicBSONObject (org.bson.BasicBSONObject)1 Content (v7db.files.spi.Content)1