Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.BinaryValue


        localStoreWithoutADefaultStore = new CompositeBinaryStore(stores);
        localStoreWithoutADefaultStore.setMinimumBinarySizeInBytes(MIN_BINARY_SIZE);
        localStoreWithoutADefaultStore.start();

        BinaryValue v = localStoreWithoutADefaultStore.storeValue(new ByteArrayInputStream(randomContent()),
                                                                  "this-hint-doesnt-reference-a-store", false);

        assertTrue(alternativeStore.hasBinary(v.getKey()));
    }
View Full Code Here


        assertTrue("Did not expect BinaryStore to contain the key", !getBinaryStore().hasBinary(invalidBinaryKey()));
    }

    private BinaryValue storeAndValidate( BinaryKey key,
                                          byte[] data ) throws BinaryStoreException, IOException {
        BinaryValue res = getBinaryStore().storeValue(new ByteArrayInputStream(data), false);
        assertNotNull(res);
        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);
View Full Code Here

        assertFalse(binaryStore.hasBinary(binaryKey));
    }

    @Test
    public void shouldAcceptStrategyHintsForStoringValues() throws Exception {
        BinaryValue res = getBinaryStore().storeValue(new ByteArrayInputStream(STORED_MEDIUM_BINARY), null, false);
        assertTrue(getBinaryStore().hasBinary(res.getKey()));
    }
View Full Code Here

    }

    @Test
    public void shouldExtractAndStoreMimeTypeWhenDetectorConfigured() throws RepositoryException, IOException {
        getBinaryStore().setMimeTypeDetector(new DummyMimeTypeDetector());
        BinaryValue binaryValue = getBinaryStore().storeValue(new ByteArrayInputStream(IN_MEMORY_BINARY), false);
        // unclean stuff... a getter modifies silently data
        assertEquals(DummyMimeTypeDetector.DEFAULT_TYPE, getBinaryStore().getMimeType(binaryValue, "foobar.txt"));
    }
View Full Code Here

        TextExtractors extractors = new TextExtractors(Executors.newSingleThreadExecutor(),
                                                       Arrays.<TextExtractor>asList(new DummyTextExtractor()));
        BinaryStore binaryStore = getBinaryStore();
        binaryStore.setTextExtractors(extractors);

        BinaryValue binaryValue = getBinaryStore().storeValue(new ByteArrayInputStream(STORED_LARGE_BINARY), false);
        String extractedText = binaryStore.getText(binaryValue);
        if (extractedText == null) {
            // if nothing is found the first time, sleep and try again - Mongo on Windows seems to exhibit this problem for some
            // reason
            Thread.sleep(TimeUnit.SECONDS.toMillis(2));
View Full Code Here

    @Test
    public void shouldPersistContentIntoTheDefaultStore() throws BinaryStoreException, IOException {
        byte[] content = randomContent();

        BinaryValue v = store.storeValue(new ByteArrayInputStream(content), false);

        InputStream is = store.getInputStream(v.getKey());
        byte[] storeContent = IoUtil.readBytes(is);

        InputStream is1 = defaultStore.getInputStream(v.getKey());
        byte[] defaultStoreContent = IoUtil.readBytes(is1);

        assertArrayEquals(content, storeContent);
        assertArrayEquals(content, defaultStoreContent);
    }
View Full Code Here

    @Test
    public void shouldLookInAllBinaryStoresForAKey() throws BinaryStoreException, IOException {
        byte[] content = randomContent();

        BinaryValue v = alternativeStore.storeValue(new ByteArrayInputStream(content), false);

        InputStream is = store.getInputStream(v.getKey());
        byte[] storedContent = IoUtil.readBytes(is);

        assertArrayEquals(content, storedContent);
        assertThat(store.hasBinary(v.getKey()), is(true));
    }
View Full Code Here

    }

    @Override
    public BinaryValue storeValue( InputStream stream, boolean markAsUnused ) throws BinaryStoreException {
        // store into temporary file system store and get SHA-1
        BinaryValue temp = cache.storeValue(stream, markAsUnused);
        try {
            // prepare new binary key based on SHA-1
            BinaryKey key = new BinaryKey(temp.getKey().toString());

            // check for duplicate content
            if (this.contentExists(key, ALIVE)) {
                return new StoredBinaryValue(this, key, temp.getSize());
            }

            // check unused content
            if (this.contentExists(key, UNUSED)) {
                if (!markAsUnused) {
                    // mark it as used
                    session.execute("UPDATE modeshape.binary SET usage=1 WHERE cid='" + key + "';");
                }
                return new StoredBinaryValue(this, key, temp.getSize());
            }

            if (!markAsUnused) {
                // store content as used
                String stmt = "INSERT INTO modeshape.binary (cid, payload, usage) VALUES (?,?,1)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), buffer(stream)));
            } else {
                // store content as un-used
                String stmt = "INSERT INTO modeshape.binary (cid, usage_time, payload, usage) VALUES (?,?,?,0)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), new Date(), buffer(stream)));
            }
            return new StoredBinaryValue(this, key, temp.getSize());
        } catch (BinaryStoreException e) {
            throw e;
        } catch (Exception e) {
            throw new BinaryStoreException(e);
        } finally {
            // remove content from temp store
            cache.markAsUnused(temp.getKey());
        }
    }
View Full Code Here

    @Override
    public boolean equals( Object obj ) {
        if (obj == this) return true;
        if (obj instanceof BinaryValue) {
            BinaryValue that = (BinaryValue)obj;
            return ValueComparators.BINARY_COMPARATOR.compare(this, that) == 0;
        }
        return false;
    }
View Full Code Here

    }

    @Override
    public BinaryValue storeValue( InputStream stream, final boolean markAsUnused ) throws BinaryStoreException {
        // store into temporary file system store and get SHA-1
        final BinaryValue temp = cache.storeValue(stream, markAsUnused);
        try {
            return dbCall(new DBCallable<BinaryValue>() {
                @Override
                public BinaryValue execute( Connection connection ) throws Exception {
                    // prepare new binary key based on SHA-1
                    BinaryKey key = new BinaryKey(temp.getKey().toString());

                    // check for duplicate content
                    Database database = database();

                    if (database.contentExists(key, ALIVE, connection)) {
                        return new StoredBinaryValue(DatabaseBinaryStore.this, key, temp.getSize());
                    }

                    // check unused content
                    if (database.contentExists(key, UNUSED, connection)) {
                        if (!markAsUnused) {
                            database.restoreContent(connection, Arrays.asList(key));
                        }
                    } else {
                        // store the content
                        database.insertContent(key, temp.getStream(), temp.getSize(), connection);
                        if (markAsUnused) {
                            database.markUnused(Arrays.asList(key), connection);
                        }
                    }
                    return new StoredBinaryValue(DatabaseBinaryStore.this, key, temp.getSize());
                }
            });
        } finally {
            // remove content from temp store
            cache.markAsUnused(temp.getKey());
        }
    }
View Full Code Here

TOP

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

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.