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();
}
}
}
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());
}
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();
}
}
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();
}
}
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();
}
};
}
Aggregations