Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.BinaryValue


    @Override
    public InputStream getStream() throws ValueFormatException {
        if (value == null) return null;
        try {
            if (asStream == null) {
                BinaryValue binary = factories().getBinaryFactory().create(value);
                asStream = binary.getStream();
            }
            return asStream;
        } catch (Exception error) {
            throw createValueFormatException(InputStream.class);
        }
View Full Code Here


    @Override
    public BinaryValue getBinary() throws RepositoryException {
        if (value == null) return null;
        try {
            BinaryValue binary = factories().getBinaryFactory().create(value);
            return binary;
        } catch (RuntimeException error) {
            throw createValueFormatException(InputStream.class);
        }
    }
View Full Code Here

                switch (this.type) {
                    case PropertyType.STRING:
                        return this.getString().equals(that.getString());
                    case PropertyType.BINARY:
                        BinaryFactory binaryFactory = factories().getBinaryFactory();
                        BinaryValue thisValue = binaryFactory.create(this.value);
                        BinaryValue thatValue = binaryFactory.create(that.value);
                        return thisValue.equals(thatValue);
                    case PropertyType.BOOLEAN:
                        return this.getBoolean() == that.getBoolean();
                    case PropertyType.DOUBLE:
                        return this.getDouble() == that.getDouble();
View Full Code Here

                final BinaryFactory binaryFactory = context().getValueFactories().getBinaryFactory();
                InputStream[] result = property.getValuesAsArray(new Property.ValueTypeTransformer<InputStream>() {
                    @Override
                    public InputStream transform( Object value ) {
                        try {
                            BinaryValue binaryValue = binaryFactory.create(value);
                            return binaryValue.getStream();
                        } catch (RepositoryException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }, InputStream.class);
View Full Code Here

        }
    }

    @Test
    public void shouldConsiderEquivalentThoseInstancesWithSameContent() {
        BinaryValue another = new InMemoryBinaryValue(store, validByteArrayContent);
        assertThat(binary.equals(another), is(true));
        assertThat(binary.compareTo(another), is(0));
        assertThat(binary, is(another));
        assertThat(binary, hasContent(validByteArrayContent));
        assertThat(another, hasContent(validByteArrayContent));
View Full Code Here

    public void shouldUseSizeWhenComparing() {
        byte[] shorterContent = new byte[validByteArrayContent.length - 2];
        for (int i = 0; i != shorterContent.length; ++i) {
            shorterContent[i] = validByteArrayContent[i];
        }
        BinaryValue another = new InMemoryBinaryValue(store, shorterContent);
        assertThat(binary.equals(another), is(false));
        assertThat(binary.compareTo(another) > 0, is(true));
        assertThat(another.compareTo(binary) < 0, is(true));
        assertThat(another, hasContent(shorterContent));
    }
View Full Code Here

        assertThat(store.hasBinary(v.getKey()), is(true));
    }

    @Test
    public void shouldStoreThingsInTheDefaultStoreWhenTheStrategyFails() throws BinaryStoreException {
        BinaryValue v = store.storeValue(new ByteArrayInputStream(randomContent()), "this-hint-doesnt-reference-a-store", false);
        assertTrue(defaultStore.hasBinary(v.getKey()));
    }
View Full Code Here

        assertTrue(defaultStore.hasBinary(v.getKey()));
    }

    @Test
    public void shouldKnowWhatBinaryStoreAKeyIsIn() throws BinaryStoreException {
        BinaryValue v = defaultStore.storeValue(new ByteArrayInputStream(randomContent()), false);
        BinaryValue v1 = alternativeStore.storeValue(new ByteArrayInputStream(randomContent()), false);

        assertEquals(defaultStore, store.findBinaryStoreContainingKey(v.getKey()));
        assertEquals(alternativeStore, store.findBinaryStoreContainingKey(v1.getKey()));
        assertNull(store.findBinaryStoreContainingKey(new BinaryKey("this-is-not-a-key")));
    }
View Full Code Here

        assertNull(store.findBinaryStoreContainingKey(new BinaryKey("this-is-not-a-key")));
    }

    @Test
    public void shouldMoveBinaryKeysBetweenStores() throws BinaryStoreException {
        BinaryValue v = defaultStore.storeValue(new ByteArrayInputStream(randomContent()), false);
        assertFalse(alternativeStore.hasBinary(v.getKey()));

        store.moveValue(v.getKey(), defaultHint, alternativeHint);

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

        store.moveValue(new BinaryKey("this-doesnt-exist"), alternativeHint);
    }

    @Test( expected = BinaryStoreException.class )
    public void shouldRaiseAnExceptionWhenMovingAKeyThatDoesntExistInTheSourceStore() throws BinaryStoreException {
        BinaryValue v = defaultStore.storeValue(new ByteArrayInputStream(randomContent()), false);
        store.moveValue(v.getKey(), alternativeHint, defaultHint);
    }
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.