Package org.apache.jackrabbit.oak.api

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


    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


    @Test
    public void getStream() throws RepositoryException, IOException {
        byte[] bytes = "just a test".getBytes();
        Binary binary = new TestBinary(bytes);
        Blob blob = new BinaryBasedBlob(binary);

        assertEquals(bytes.length, blob.length());

        InputStream expected = binary.getStream();
        InputStream actual = blob.getNewStream();
        try {
            for (int e = expected.read(); e != -1; e = expected.read()) {
                assertEquals(e, actual.read());
            }
            assertEquals(-1, actual.read());
View Full Code Here

        }
    }

    @Test
    public void getStreamWithError() throws IOException {
        Blob blob = new BinaryBasedBlob(new FailingBinary());

        assertEquals(-1, blob.length());
        InputStream ins = blob.getNewStream();
        try {
            ins.read();
            fail();
        } catch (IOException ignored) {
        } finally {
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

        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

        store = new FileStore(directory, 1, memoryMapping);
        SegmentNodeState base = store.getHead();
        SegmentNodeBuilder builder = base.builder();
        byte[] data = new byte[10 * 1024 * 1024];
        new Random().nextBytes(data);
        Blob blob = builder.createBlob(new ByteArrayInputStream(data));
        builder.setProperty("foo", blob);
        store.setHead(base, builder.getNodeState());
        store.flush();
        store.setHead(store.getHead(), base);
        store.close();
View Full Code Here

        log.setText(sb.toString());
    }

    private String toString(PropertyState ps, int index, String tarFile) {
        if (ps.getType().tag() == PropertyType.BINARY) {
            Blob b = ps.getValue(Type.BINARY, index);
            String info = "<";
            info += b.getClass().getSimpleName() + ";";
            info += "ref:" + b.getReference() + ";";
            info += "id:" + b.getContentIdentity() + ";";
            info += FileUtils.byteCountToDisplaySize(b.length()) + ">";
            for (SegmentId sid : SegmentBlob.getBulkSegmentIds(b)) {
                info += newline + "        Bulk Segment Id " + sid;
                String f = getFile(sid);
                if (!f.equals(tarFile)) {
                    info += " in " + f;
View Full Code Here

                    localPaths.add(path + "@" + ps + " [SegmentPropertyState@"
                            + recordId + "]");
                }
                if (ps.getType().tag() == PropertyType.BINARY) {
                    for (int i = 0; i < ps.count(); i++) {
                        Blob b = ps.getValue(Type.BINARY, i);
                        for (SegmentId sbid : SegmentBlob.getBulkSegmentIds(b)) {
                            UUID bid = new UUID(sbid.getMostSignificantBits(),
                                    sbid.getLeastSignificantBits());
                            if (!bid.equals(id) && uuids.contains(bid)) {
                                localPaths.add(path + "@" + ps
View Full Code Here

        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);
                    int read = stream.read(buff, off, length);
                    return read < 0 ? 0 : read;
                } finally {
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.