Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.BinaryKey


        // Now process the binary changes ...
        for (Change change : changeSet) {
            // Look at property added/removed/changed events, and node add/removed/moved/renamed/reordered events ...
            if (change instanceof BinaryValueUnused) {
                BinaryValueUnused unused = (BinaryValueUnused)change;
                BinaryKey key = unused.getKey();
                if (usedBinaryKeys.contains(key)) {
                    // This change set had marked it as used, but now is unused again; removed it from the used.
                    usedBinaryKeys.remove(key);
                    break;
                }
                unusedBinaryKeys.add(key);
            }
            if (change instanceof BinaryValueUsed) {
                BinaryValueUsed unused = (BinaryValueUsed)change;
                BinaryKey key = unused.getKey();
                if (unusedBinaryKeys.contains(key)) {
                    // This change set had marked it as used, but now is unused again; removed it from the used.
                    unusedBinaryKeys.remove(key);
                    break;
                }
View Full Code Here


        assertThat(countStoredFiles(), is(storedSha1s.size()));
        assertThat(countTrashFiles(), is(0));

        // Mark one of the files as being unused ...
        String unused = storedSha1s.iterator().next();
        store.markAsUnused(Collections.singleton(new BinaryKey(unused)));

        // Make sure the trash file was created
        assertThat(countStoredFiles(), is(storedSha1s.size()));
        assertThat(countTrashFiles(), is(1));
        // Check that the name of the trash file is the SHA1
View Full Code Here

        assertThat(countStoredFiles(), is(storedCount));
        assertThat(countTrashFiles(), is(0));

        // Mark one of the files as being unused ...
        String unused = binaries.iterator().next().getHexHash();
        BinaryKey unusedKey = new BinaryKey(unused);
        store.markAsUnused(Collections.singleton(unusedKey));

        // Make sure the file was moved to the trash ...
        assertThat(countStoredFiles(), is(storedCount));
        assertThat(countTrashFiles(), is(1));
View Full Code Here

    @Test
    public void testStreamingSingleBytes() throws IOException {
        // usses read() and write() instead of read(byte[] ...)
        byte[] data = new byte[2048];
        RANDOM.nextBytes(data);
        BinaryKey dataKey = BinaryKey.keyFor(data);

        ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey.toString());
        for (byte aData : data) {
            chunkOutputStream.write(aData);
        }
        chunkOutputStream.close();
        assertEquals(1, chunkOutputStream.chunksCount());
        ChunkInputStream chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int b;
        while ((b = chunkInputStream.read()) != -1) {
            byteArrayOutputStream.write(b);
        }
View Full Code Here

    @Test
    public void shouldStreamMultipleChunks() throws Exception {
        byte[] data = new byte[InfinispanBinaryStore.DEFAULT_CHUNK_SIZE * 3];
        RANDOM.nextBytes(data);
        BinaryKey dataKey = BinaryKey.keyFor(data);

        ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey.toString());
        IoUtil.write(new ByteArrayInputStream(data), chunkOutputStream);

        assertEquals(3, chunkOutputStream.chunksCount());
        ChunkInputStream chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        byte[] storedData = IoUtil.readBytes(chunkInputStream);
        assertArrayEquals("Invalid data read from the stream", data, storedData);
    }
View Full Code Here

    @FixFor( "MODE-1752" )
    public void shouldSkipMultipleChunks() throws Exception {
        int totalSize = chunkSize * 3;
        byte[] data = new byte[totalSize];
        RANDOM.nextBytes(data);
        BinaryKey dataKey = BinaryKey.keyFor(data);

        ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey.toString());
        IoUtil.write(new ByteArrayInputStream(data), chunkOutputStream);

        ChunkInputStream chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        // skip 2 bytes, expect the same amount
        assertEquals(2, chunkInputStream.skip(2));
        // skip the equivalent of 2 chunks, expect the same amount
        assertEquals(chunkSize * 2, chunkInputStream.skip(chunkSize * 2));
        // skip on chunk, expect on chunk - 2 bytes because of the above skip calls
        assertEquals(chunkSize - 2, chunkInputStream.skip(chunkSize));
        // already at EOS so expect no more skipping
        assertEquals(0, chunkInputStream.skip(1));
        assertEquals(0, chunkInputStream.skip(chunkSize));

        chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        assertEquals(totalSize, chunkInputStream.skip(totalSize));
        assertEquals(0, chunkInputStream.skip(chunkSize));
        assertEquals(totalSize, new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length).skip(totalSize + 1));
        assertEquals(totalSize, new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length).skip(chunkSize * 4));
    }
View Full Code Here

    @Test
    @FixFor( "MODE-1752" )
    public void shouldCorrectlyReadAfterSkippingMultipleChunks() throws Exception {
        byte[] data = new byte[chunkSize * 3];
        RANDOM.nextBytes(data);
        BinaryKey dataKey = BinaryKey.keyFor(data);

        ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey.toString());
        IoUtil.write(new ByteArrayInputStream(data), chunkOutputStream);

        // skip 2 bytes and read the rest
        ChunkInputStream chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        chunkInputStream.skip(2);
        byte[] expected = new byte[data.length - 2];
        System.arraycopy(data, 2, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

        // skip 1 chunk and read until nothing is left
        chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        chunkInputStream.skip(chunkSize);
        expected = new byte[data.length - chunkSize];
        System.arraycopy(data, chunkSize, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

        // skip the equivalent of 2 chunks, read the rest
        chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, data.length);
        chunkInputStream.skip(chunkSize * 2);
        expected = new byte[data.length - (chunkSize * 2)];
        System.arraycopy(data, chunkSize * 2, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

View Full Code Here

    public void shouldCorrectlyReadAfterDirectlySkippingMultipleChunks() throws Exception {
        int chunkSize = InfinispanBinaryStore.DEFAULT_CHUNK_SIZE;
        int totalSize = chunkSize * 3;
        byte[] data = new byte[totalSize];
        RANDOM.nextBytes(data);
        BinaryKey dataKey = BinaryKey.keyFor(data);

        ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey.toString());
        IoUtil.write(new ByteArrayInputStream(data), chunkOutputStream);

        // skip 2 bytes and read the rest
        ChunkInputStream chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, totalSize);
        chunkInputStream.skip(2);
        byte[] expected = new byte[data.length - 2];
        System.arraycopy(data, 2, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

        // skip 1 chunk and read until nothing is left
        chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, totalSize);
        chunkInputStream.skip(chunkSize);
        expected = new byte[data.length - chunkSize];
        System.arraycopy(data, chunkSize, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

        // skip the equivalent of 2 chunks, read the rest
        chunkInputStream = new ChunkInputStream(blobCache, dataKey.toString(), chunkSize, totalSize);
        chunkInputStream.skip(chunkSize * 2);
        expected = new byte[data.length - (chunkSize * 2)];
        System.arraycopy(data, chunkSize * 2, expected, 0, expected.length);
        assertArrayEquals(expected, IoUtil.readBytes(chunkInputStream));

View Full Code Here

        assertEquals(key, res.getKey());
        assertEquals(data.length, res.getSize());
        InputStream inputStream = getBinaryStore().getInputStream(key);
        byte[] content = IoUtil.readBytes(inputStream);
        assertArrayEquals(data, content);
        BinaryKey currentKey = BinaryKey.keyFor(content);
        assertEquals(key, currentKey);
        return res;
    }
View Full Code Here

    @Test
    @FixFor( "MODE-2302" )
    public void shouldStoreBinariesAsUnused() throws Exception {
        byte[] randomBinary = new byte[(int)(AbstractBinaryStore.DEFAULT_MINIMUM_BINARY_SIZE_IN_BYTES * 2)];
        RANDOM.nextBytes(randomBinary);
        BinaryKey binaryKey = BinaryKey.keyFor(randomBinary);

        BinaryStore binaryStore = getBinaryStore();
        binaryStore.storeValue(new ByteArrayInputStream(randomBinary), true);
        assertTrue("Binary not stored", binaryStore.hasBinary(binaryKey));
        for (BinaryKey storedKey : binaryStore.getAllBinaryKeys()) {
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.BinaryKey

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.