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


            NodeBuilder builder = nodeStore.getRoot().builder();
            builder.child("hello");
            nodeStore.merge(builder, EmptyHook.INSTANCE, null);
        }

        Blob blob = getFileBlob();
        NodeBuilder builder = nodeStore.getRoot().builder();
        builder.getChildNode("hello").setProperty("world", blob);
        nodeStore.merge(builder, EmptyHook.INSTANCE, null);

        state = nodeStore.getRoot().getChildNode("hello");
View Full Code Here

        FileStore source = new FileStore(src, 256, false);

        NodeStore store = new SegmentNodeStore(source);

        // ~100k
        Blob blob = store.createBlob(new ByteArrayInputStream(new byte[100000]));

        NodeBuilder builder = store.getRoot().builder();
        NodeBuilder c1 = builder.child("test-backup");
        c1.setProperty("blob", blob);
        NodeBuilder c2 = builder.child("test-backup2");
View Full Code Here

        if (sourceType == targetType) {
            return value;
        }
        switch (targetType) {
        case PropertyType.BINARY:
            Blob blob = value.getValue(Type.BINARY);
            return newBinary(blob);
        case PropertyType.BOOLEAN:
            return newBoolean(value.getValue(Type.BOOLEAN));
        case PropertyType.DATE:
            return newDate(value.getValue(Type.DATE));
View Full Code Here

    @Override
    public String write(InputStream in) throws MicroKernelException {
        try {
            final Hasher hasher = Hashing.sha256().newHasher();
            Blob blob = store.createBlob(
                    new CheckedInputStream(in, new Checksum() {
                        @Override
                        public void update(byte[] b, int off, int len) {
                            hasher.putBytes(b, off, len);
                        }
                        @Override
                        public void update(int b) {
                            hasher.putByte((byte) b);
                        }
                        @Override
                        public void reset() {
                            throw new UnsupportedOperationException();
                        }
                        @Override
                        public long getValue() {
                            throw new UnsupportedOperationException();
                        }
                    }));
            HashCode hash = hasher.hash();

            // wrap into AbstractBlob for the SHA-256 memorization feature
            if (!(blob instanceof AbstractBlob)) {
                final Blob b = blob;
                blob = new AbstractBlob(hash) {
                    @Override
                    public long length() {
                        return b.length();
                    }
                    @Override
                    public InputStream getNewStream() {
                        return b.getNewStream();
                    }
                };
            }

            String id = hash.toString();
View Full Code Here

                json.value(TypeCodes.encode(type.tag(), value.toString()));
            } else {
                json.encodedValue(value.toString());
            }
        } else if (type == BINARY) {
            Blob blob = property.getValue(BINARY, index);
            json.value(TypeCodes.encode(type.tag(), blobs.serialize(blob)));
        } else  {
            String value = property.getValue(STRING, index);
            if (type != STRING || TypeCodes.split(value) != -1) {
                value = TypeCodes.encode(type.tag(), value);
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(b1.getReference());

        //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)));
        assertNotNull(b2.getReference());
        assertNotNull(dbs.getRecordIfStored(new DataIdentifier(b2.getReference())));
    }
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

            Iterator<Blob> blobIterator = nodeStore.getReferencedBlobsIterator();
            referencedBlobs.ensureCapacity(getBatchCount());

            int referencesFound = 0;
            while (blobIterator.hasNext()) {
                Blob blob = blobIterator.next();

                if (debugMode) {
                    LOG.debug("BlobId : " + blob.toString());
                }

                if (blob.toString().length() != 0) {
                    Iterator<String> idIter = ((GarbageCollectableBlobStore) nodeStore
                            .getBlobStore())
                            .resolveChunks(blob.toString());
                    while (idIter.hasNext()) {
                        String id = idIter.next();
                        referencedBlobs.add(id);
                        if (debugMode) {
                            LOG.debug("chunkId : " + id);
View Full Code Here

        FileStore source = new FileStore(src, 256, false);

        NodeStore store = new SegmentNodeStore(source);

        // ~100k
        Blob blob = store.createBlob(new ByteArrayInputStream(new byte[100000]));

        NodeBuilder builder = store.getRoot().builder();
        NodeBuilder c1 = builder.child("test-backup");
        c1.setProperty("blob", blob);
        NodeBuilder c2 = builder.child("test-backup2");
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.