Search in sources :

Example 6 with Binary

use of javax.jcr.Binary in project jackrabbit by apache.

the class ClientProperty method setValue.

/**
     * Sets the binary value of this property. Implemented as
     * setValue(new BinaryValue(value)).
     *
     * {@inheritDoc}
     */
public void setValue(InputStream value) throws RepositoryException {
    if (value == null) {
        setValue((Value) null);
    } else {
        ValueFactory factory = getSession().getValueFactory();
        Binary binary = factory.createBinary(value);
        try {
            setValue(factory.createValue(binary));
        } finally {
            binary.dispose();
        }
    }
}
Also used : ValueFactory(javax.jcr.ValueFactory) SerialValueFactory(org.apache.jackrabbit.rmi.value.SerialValueFactory) Binary(javax.jcr.Binary)

Example 7 with Binary

use of javax.jcr.Binary in project jackrabbit by apache.

the class LengthTest method testBinaryLength.

public void testBinaryLength() throws RepositoryException {
    byte[] data = "abc".getBytes();
    Binary b = vf.createBinary(new ByteArrayInputStream(data));
    try {
        node.setProperty(propertyName1, b);
    } finally {
        b.dispose();
    }
    superuser.save();
    checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Binary(javax.jcr.Binary)

Example 8 with Binary

use of javax.jcr.Binary in project jackrabbit by apache.

the class LengthTest method testLengthBinaryLiteral.

public void testLengthBinaryLiteral() throws RepositoryException {
    node.setProperty(propertyName1, "abc");
    superuser.save();
    String length = String.valueOf(node.getProperty(propertyName1).getLength());
    Binary b = vf.createBinary(new ByteArrayInputStream(length.getBytes()));
    try {
        executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(b));
    } finally {
        b.dispose();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Binary(javax.jcr.Binary)

Example 9 with Binary

use of javax.jcr.Binary in project jackrabbit by apache.

the class BinaryValueTest method setProperty.

protected Property setProperty(Node node, int length) throws RepositoryException {
    Random rand = new Random();
    byte[] data = new byte[length];
    rand.nextBytes(data);
    Binary b = vf.createBinary(new ByteArrayInputStream(data));
    //System.out.println(b.getClass() + ": " + System.identityHashCode(b));
    try {
        return node.setProperty(propertyName1, b);
    } finally {
        b.dispose();
    }
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) Binary(javax.jcr.Binary)

Example 10 with Binary

use of javax.jcr.Binary in project jackrabbit by apache.

the class PropertyImpl method getStream.

/** Wrapper around {@link #getValue()} */
public InputStream getStream() throws RepositoryException {
    final Binary binary = getValue().getBinary();
    // make sure binary is disposed after stream had been consumed
    return new AutoCloseInputStream(binary.getStream()) {

        @Override
        public void close() throws IOException {
            super.close();
            binary.dispose();
        }
    };
}
Also used : Binary(javax.jcr.Binary) AutoCloseInputStream(org.apache.commons.io.input.AutoCloseInputStream)

Aggregations

Binary (javax.jcr.Binary)50 ByteArrayInputStream (java.io.ByteArrayInputStream)28 InputStream (java.io.InputStream)22 Node (javax.jcr.Node)20 Value (javax.jcr.Value)14 Test (org.junit.Test)12 Session (javax.jcr.Session)10 ReferenceBinary (org.apache.jackrabbit.api.ReferenceBinary)8 BigDecimal (java.math.BigDecimal)7 SimpleReferenceBinary (org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary)7 RandomInputStream (org.apache.jackrabbit.core.data.RandomInputStream)7 IOException (java.io.IOException)5 Property (javax.jcr.Property)4 RepositoryException (javax.jcr.RepositoryException)4 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)4 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)4 NamespaceRegistry (javax.jcr.NamespaceRegistry)3 ValueFactory (javax.jcr.ValueFactory)3 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)3 QValue (org.apache.jackrabbit.spi.QValue)3