Search in sources :

Example 6 with ContentStorage

use of v7db.files.spi.ContentStorage in project v7files by thiloplanz.

the class MongoReferenceTrackingTest method testPurge.

public void testPurge() throws MongoException, IOException, DecoderException {
    Mongo mongo = getMongo();
    DBCollection contents = mongo.getDB("test").getCollection("v7files.content");
    ContentStorage storage = new MongoContentStorage(contents);
    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
    DBCollection references = mongo.getDB("test").getCollection("v7files.refs");
    ReferenceTracking refs = new MongoReferenceTracking(references);
    Object owner = new DBRef(null, "test", "test");
    refs.updateReferences(owner, pointer);
    refs.purge(owner);
    SimpleGarbageCollector.purge(contents, references);
    assertMockMongoDoesNotContainDocument("test.v7files.refs", owner);
    assertMockMongoDoesNotContainDocument("test.v7files.content", DigestUtils.sha(data));
    mongo.close();
}
Also used : DBCollection(com.mongodb.DBCollection) ReferenceTracking(v7db.files.spi.ReferenceTracking) Mongo(com.mongodb.Mongo) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentStorage(v7db.files.spi.ContentStorage) ContentPointer(v7db.files.spi.ContentPointer) DBRef(com.mongodb.DBRef) BasicBSONObject(org.bson.BasicBSONObject)

Example 7 with ContentStorage

use of v7db.files.spi.ContentStorage in project v7files by thiloplanz.

the class UploadCommand method main.

public static void main(String[] args) throws MongoException, IOException {
    if (args.length < 2) {
        System.err.println("Upload the contents of one or more files and print their SHA digests:");
        System.err.println("   upload <file> [file] [file] [...]");
        System.exit(1);
    }
    ContentStorage storage = new MongoContentStorage(Configuration.getMongo().getDB(Configuration.getProperty("mongo.db")));
    for (int i = 1; i < args.length; i++) {
        File f = new File(args[i]);
        if (f.isFile() && f.canRead()) {
            try {
                ContentSHA up = storage.storeContent(new FileInputStream(f));
                // TODO: display if chunked or not
                System.out.format("-      %10d %80s %40s\n", f.length(), f.getName(), up.getDigest());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : MongoContentStorage(v7db.files.mongodb.MongoContentStorage) ContentSHA(v7db.files.spi.ContentSHA) MongoContentStorage(v7db.files.mongodb.MongoContentStorage) ContentStorage(v7db.files.spi.ContentStorage) File(java.io.File) FileInputStream(java.io.FileInputStream) MongoException(com.mongodb.MongoException) IOException(java.io.IOException)

Aggregations

ContentStorage (v7db.files.spi.ContentStorage)7 Mongo (com.mongodb.Mongo)4 ContentPointer (v7db.files.spi.ContentPointer)4 BasicBSONObject (org.bson.BasicBSONObject)3 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)3 Content (v7db.files.spi.Content)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DBCollection (com.mongodb.DBCollection)1 DBRef (com.mongodb.DBRef)1 MongoException (com.mongodb.MongoException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ContentSHA (v7db.files.spi.ContentSHA)1 ReferenceTracking (v7db.files.spi.ReferenceTracking)1