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();
}
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();
}
}
}
}
Aggregations