Search in sources :

Example 1 with ContentStorage

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

the class ZipFileTest method testPullOutFileFromZip.

public void testPullOutFileFromZip() throws MongoException, IOException, ZipException, DecoderException {
    ContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
    ContentPointer zip = storage.storeContent(getClass().getResourceAsStream("mongodb.epub"));
    ContentPointer png = ZipFile.extractFile(storage, zip, "images/img0.png");
    assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils.shaHex(storage.getContent(png).getInputStream()));
}
Also used : MongoContentStorage(v7db.files.mongodb.MongoContentStorage) MongoContentStorage(v7db.files.mongodb.MongoContentStorage) ContentStorage(v7db.files.spi.ContentStorage) ContentPointer(v7db.files.spi.ContentPointer)

Example 2 with ContentStorage

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

the class MongoContentStorageTest method testReadChunkedData.

public void testReadChunkedData() throws MongoException, IOException {
    byte[] data1 = "first chunk".getBytes();
    byte[] sha1 = DigestUtils.sha(data1);
    byte[] data2 = " second chunk".getBytes();
    byte[] sha2 = DigestUtils.sha(data2);
    byte[] data = "first chunk second chunk".getBytes();
    byte[] sha = DigestUtils.sha(data);
    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha1).append("in", data1));
    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha2).append("in", data2));
    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha).append("store", "cat").append("base", Arrays.asList(new BasicBSONObject("sha", sha1).append("length", data1.length), new BasicBSONObject("sha", sha2).append("length", data2.length))));
    Mongo mongo = getMongo();
    ContentStorage storage = new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));
    Content check = storage.getContent(sha);
    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) Mongo(com.mongodb.Mongo) ContentStorage(v7db.files.spi.ContentStorage) Content(v7db.files.spi.Content)

Example 3 with ContentStorage

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

the class MongoContentStorageTest method testRoundtrip.

public void testRoundtrip() throws MongoException, IOException {
    Mongo mongo = getMongo();
    ContentStorage storage = new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));
    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
    Content check = storage.getContent(pointer);
    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
}
Also used : Mongo(com.mongodb.Mongo) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentStorage(v7db.files.spi.ContentStorage) Content(v7db.files.spi.Content) ContentPointer(v7db.files.spi.ContentPointer)

Example 4 with ContentStorage

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

the class ZipFileTest method testIndexZipFile.

public void testIndexZipFile() throws MongoException, IOException, ZipException, DecoderException {
    ContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
    ContentPointer zip = storage.storeContent(getClass().getResourceAsStream("mongodb.epub"));
    ZipFile.index(storage, zip);
    assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils.shaHex(storage.getContent(decodeHex("fc012bb0439382f709d3caebab958ff592811d17".toCharArray())).getInputStream()));
}
Also used : MongoContentStorage(v7db.files.mongodb.MongoContentStorage) MongoContentStorage(v7db.files.mongodb.MongoContentStorage) ContentStorage(v7db.files.spi.ContentStorage) ContentPointer(v7db.files.spi.ContentPointer)

Example 5 with ContentStorage

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

the class MongoContentStorageTest method testReadCompressedData.

public void testReadCompressedData() throws MongoException, IOException {
    byte[] data = "some data we are going to store compressed with gzip".getBytes();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(baos);
    gzip.write(data);
    gzip.close();
    byte[] compressed = baos.toByteArray();
    byte[] sha = DigestUtils.sha(data);
    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha).append("store", "gz").append("zin", compressed));
    Mongo mongo = getMongo();
    ContentStorage storage = new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));
    Content check = storage.getContent(sha);
    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) Mongo(com.mongodb.Mongo) ContentStorage(v7db.files.spi.ContentStorage) Content(v7db.files.spi.Content) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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