Package org.apache.jackrabbit.oak.api

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


        return r.id;
    }

    @Override
    public long getLength(String blobId) throws MicroKernelException {
        Blob blob = blobs.get(blobId);
        if (blob != null) {
            return blob.length();
        } else {
            throw new MicroKernelException("Blob not found: " + blobId);
        }
    }
View Full Code Here


    }

    @Override
    public int read(String blobId, long pos, byte[] buff, int off, int length)
            throws MicroKernelException {
        Blob blob = blobs.get(blobId);
        if (blob != null) {
            try {
                InputStream stream = blob.getNewStream();
                try {
                    ByteStreams.skipFully(stream, pos);
                    return stream.read(buff, off, length);
                } finally {
                    stream.close();
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

            throw new RepositoryException(e);
        }
    }

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

        PropertyState p;
        if (reader.matches('[')) {
            p = MongoNodeState.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 = MongoNodeState.readProperty("x", nodeStore, reader);
            if (p.getType() == Type.BINARY) {
                Blob b = p.getValue(Type.BINARY);
                batch.add(b);
            }
        }
    }
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

    public void test() throws Exception {
        MongoNodeStore s = new MongoMK.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());
    }
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

        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

    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

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.