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