Search in sources :

Example 1 with BlobSerializer

use of org.apache.jackrabbit.oak.json.BlobSerializer in project jackrabbit-oak by apache.

the class BlobTest method testBlobSerialization.

@Test
public void testBlobSerialization() throws Exception {
    TestBlobStore blobStore = new TestBlobStore();
    DocumentMK mk = builderProvider.newBuilder().setBlobStore(blobStore).open();
    BlobSerializer blobSerializer = mk.getNodeStore().getBlobSerializer();
    Blob blob = new BlobStoreBlob(blobStore, "foo");
    assertEquals("foo", blobSerializer.serialize(blob));
    assertEquals(0, blobStore.writeCount);
    blob = new ArrayBasedBlob("foo".getBytes());
    blobSerializer.serialize(blob);
    assertEquals(1, blobStore.writeCount);
    byte[] bytes = "foo".getBytes();
    String blobId = blobStore.writeBlob(new ByteArrayInputStream(bytes));
    String reference = blobStore.getReference(blobId);
    blob = new ReferencedBlob("foo".getBytes(), reference);
    blobStore.writeCount = 0;
    blobSerializer.serialize(blob);
    // Using reference so no reference should be written
    assertEquals(0, blobStore.writeCount);
}
Also used : BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) BlobSerializer(org.apache.jackrabbit.oak.json.BlobSerializer) Test(org.junit.Test)

Example 2 with BlobSerializer

use of org.apache.jackrabbit.oak.json.BlobSerializer in project jackrabbit-oak by apache.

the class JsonDeserializationTest method serialize.

private String serialize(NodeState nodeState) {
    JsopBuilder json = new JsopBuilder();
    new JsonSerializer(json, "{\"properties\":[\"*\", \"-:*\"]}", new BlobSerializer()).serialize(nodeState);
    return json.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) BlobSerializer(org.apache.jackrabbit.oak.json.BlobSerializer) Base64BlobSerializer(org.apache.jackrabbit.oak.json.Base64BlobSerializer) JsonSerializer(org.apache.jackrabbit.oak.json.JsonSerializer)

Example 3 with BlobSerializer

use of org.apache.jackrabbit.oak.json.BlobSerializer in project jackrabbit-oak by apache.

the class NodeStateSerializer method createBlobSerializer.

private BlobSerializer createBlobSerializer(File dir) {
    if (!serializeBlobContent) {
        return new BlobSerializer();
    }
    File blobs = new File(dir, blobDirName);
    blobSerializer = new FSBlobSerializer(blobs);
    return blobSerializer;
}
Also used : FSBlobSerializer(org.apache.jackrabbit.oak.plugins.blob.serializer.FSBlobSerializer) BlobSerializer(org.apache.jackrabbit.oak.json.BlobSerializer) Base64BlobSerializer(org.apache.jackrabbit.oak.json.Base64BlobSerializer) FSBlobSerializer(org.apache.jackrabbit.oak.plugins.blob.serializer.FSBlobSerializer) File(java.io.File)

Aggregations

BlobSerializer (org.apache.jackrabbit.oak.json.BlobSerializer)3 Base64BlobSerializer (org.apache.jackrabbit.oak.json.Base64BlobSerializer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 JsopBuilder (org.apache.jackrabbit.oak.commons.json.JsopBuilder)1 JsonSerializer (org.apache.jackrabbit.oak.json.JsonSerializer)1 BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)1 FSBlobSerializer (org.apache.jackrabbit.oak.plugins.blob.serializer.FSBlobSerializer)1 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)1 Test (org.junit.Test)1