Package org.apache.jackrabbit.oak.api

Examples of org.apache.jackrabbit.oak.api.Blob


            throws IOException {
        NodeBuilder file = addChild(node, name, JcrConstants.NT_FILE);
        NodeBuilder content = addChild(file, JcrConstants.JCR_CONTENT,
                JcrConstants.NT_RESOURCE);
        content.setProperty(JcrConstants.JCR_MIMETYPE, "text/plain");
        Blob blob = store.createBlob(new ByteArrayInputStream("Apache Oak".getBytes()));
        content.setProperty(JcrConstants.JCR_DATA, blob);
        return file;
    }
View Full Code Here


        nodeStore = getNodeStore(dbs);

        //Test for Blob which get inlined
        byte[] data = new byte[fds.getMinRecordLength()-2];
        new Random().nextBytes(data);
        Blob b1 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data)));
        assertTrue(b1 instanceof SegmentBlob);
        assertNull(((SegmentBlob) b1).getBlobId());

        //Test for Blob which need to be pushed to BlobStore
        byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1];
        new Random().nextBytes(data2);
        Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2)));
        assertTrue(b2 instanceof SegmentBlob);
        assertNotNull(b2.getReference());
        InputStream is = dbs.getInputStream(((SegmentBlob) b2).getBlobId());
        assertNotNull(IOUtils.contentEquals(new ByteArrayInputStream(data2), is));
        is.close();
    }
View Full Code Here

        nodeStore = getNodeStore(dbs);

        //Test for Blob which get inlined
        byte[] data = new byte[fds.getMinRecordLength()-2];
        new Random().nextBytes(data);
        Blob b1 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data)));
        assertTrue(b1 instanceof SegmentBlob);
        assertNull(((SegmentBlob) b1).getBlobId());

        //Test for Blob which need to be pushed to BlobStore
        byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1];
        new Random().nextBytes(data2);
        Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2)));
        assertTrue(b2 instanceof SegmentBlob);
        assertNotNull(b2.getReference());
        assertNotNull(dbs.getRecordIfStored(new DataIdentifier(((SegmentBlob) b2).getBlobId())));
    }
View Full Code Here

            throws IOException {
        NodeBuilder file = addChild(node, name, JcrConstants.NT_FILE);
        NodeBuilder content = addChild(file, JcrConstants.JCR_CONTENT,
                JcrConstants.NT_RESOURCE);
        content.setProperty(JcrConstants.JCR_MIMETYPE, "text/plain");
        Blob blob = store.createBlob(new ByteArrayInputStream("Apache Oak".getBytes()));
        content.setProperty(JcrConstants.JCR_DATA, blob);
        return file;
    }
View Full Code Here

        PropertyState p;
        if (reader.matches('[')) {
            p = DocumentPropertyState.readArrayProperty("x", nodeStore, reader);
            if (p.getType() == Type.BINARIES) {
                for (int i = 0; i < p.count(); i++) {
                    Blob b = p.getValue(Type.BINARY, i);
                    batch.add(b);
                }
            }
        } else {
            p = DocumentPropertyState.readProperty("x", nodeStore, reader);
            if (p.getType() == Type.BINARY) {
                Blob b = p.getValue(Type.BINARY);
                batch.add(b);
            }
        }
    }
View Full Code Here

    private PropertyState compact(PropertyState property) {
        String name = property.getName();
        Type<?> type = property.getType();
        if (type == BINARY) {
            Blob blob = compact(property.getValue(Type.BINARY));
            return BinaryPropertyState.binaryProperty(name, blob);
        } else if (type == BINARIES) {
            List<Blob> blobs = new ArrayList<Blob>();
            for (Blob blob : property.getValue(BINARIES)) {
                blobs.add(compact(blob));
View Full Code Here

    private void checkRandomStreamRecord(int size) throws IOException {
        byte[] source = new byte[size];
        random.nextBytes(source);

        Blob value = writer.writeStream(new ByteArrayInputStream(source));
        InputStream stream = value.getNewStream();
        try {
            byte[] b = new byte[349]; // prime number
            int offset = 0;
            for (int n = stream.read(b); n != -1; n = stream.read(b)) {
                for (int i = 0; i < n; i++) {
View Full Code Here

            throw new RepositoryException(e);
        }
    }

    private ValueImpl createBinaryValue(InputStream value) throws IOException {
        Blob blob = blobFactory.createBlob(value);
        return new ValueImpl(BinaryPropertyState.binaryProperty("", blob), namePathMapper);
    }
View Full Code Here

    public void test() throws Exception {
        DocumentNodeStore s = new DocumentMK.Builder().getNodeStore();
        NodeBuilder a = s.getRoot().builder();
        HashSet<String> set = new HashSet<String>();
        for (int i = 0; i < 100; i++) {
            Blob b = a.createBlob(randomStream(i, 10));
            set.add(b.toString());
            a.child("c" + i).setProperty("x", b);
        }
        s.merge(a, EmptyHook.INSTANCE, null);
        Iterator<Blob> it = s.getReferencedBlobsIterator();
        while (it.hasNext()) {
            Blob b = it.next();
            set.remove(b.toString());
        }
        assertTrue(set.isEmpty());
        s.dispose();
    }
View Full Code Here

        assertFalse(xx.exists());
    }

    @Test
    public void testBlob() throws CommitFailedException, IOException {
        Blob expected = new StringBasedBlob("test blob");
        root.getTree("/x").setProperty("blob", expected);
        root.commit();

        Blob actual = root.getTree("/x").getProperty("blob").getValue(Type.BINARY);
        assertEquals(expected, actual);

        assertTrue(expected.getNewStream().available() >= 0);
        assertTrue(actual.getNewStream().available() >= 0);
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.api.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.