use of javax.jcr.Binary in project jackrabbit by apache.
the class AbstractValue method getBinary.
/**
* Returns the binary representation of this value. The default
* implementation uses the UTF-8 serialization of the string returned
* by {@link #getString()}. Subclasses
*/
public Binary getBinary() throws RepositoryException {
try {
final byte[] value = getString().getBytes("UTF-8");
return new Binary() {
public int read(byte[] b, long position) {
if (position >= value.length) {
return -1;
} else {
int p = (int) position;
int n = Math.min(b.length, value.length - p);
System.arraycopy(value, p, b, 0, n);
return n;
}
}
public InputStream getStream() {
return new ByteArrayInputStream(value);
}
public long getSize() {
return value.length;
}
public void dispose() {
}
};
} catch (UnsupportedEncodingException e) {
throw new RepositoryException("UTF-8 is not supported", e);
}
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class RepositoryTest method testReferenceBinary.
@Test
public void testReferenceBinary() throws RepositoryException {
ValueFactory valueFactory = getAdminSession().getValueFactory();
Binary binary = valueFactory.createBinary(new RandomInputStream(1, 256 * 1024));
String reference = binary instanceof ReferenceBinary ? ((ReferenceBinary) binary).getReference() : null;
assumeTrue(reference != null);
Session session = createAdminSession();
try {
valueFactory = session.getValueFactory();
assertEquals(binary, valueFactory.createValue(new SimpleReferenceBinary(reference)).getBinary());
} finally {
session.logout();
}
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class RepositoryTest method addSmallBinaryProperty.
@Test
public void addSmallBinaryProperty() throws RepositoryException, IOException {
Node parentNode = getNode(TEST_PATH);
InputStream is = new NumberStream(1234);
Binary bin = getAdminSession().getValueFactory().createBinary(is);
addProperty(parentNode, "bigBinary", getAdminSession().getValueFactory().createValue(bin));
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class RepositoryTest method addBigBinaryProperty.
@Test
public void addBigBinaryProperty() throws RepositoryException, IOException {
Node parentNode = getNode(TEST_PATH);
InputStream is = new NumberStream(123456);
Binary bin = getAdminSession().getValueFactory().createBinary(is);
addProperty(parentNode, "bigBinary", getAdminSession().getValueFactory().createValue(bin));
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class OperationLoggerTest method testBinaryLogger.
public void testBinaryLogger() throws Exception {
Node node1 = testRootNode.addNode(nodeName1);
start();
byte[] data = "hello".getBytes();
Binary b = superuser.getValueFactory().createBinary(new ByteArrayInputStream(data));
node1.setProperty("foo", b);
stop();
boolean binaryLog = false;
for (ILoggingEvent e : logs.list) {
if (e.getLoggerName().startsWith(OPS_BINARY)) {
if (e.getMessage().contains("Created binary property")) {
assertEquals(Long.valueOf(data.length), e.getArgumentArray()[0]);
binaryLog = true;
}
}
}
assertTrue("Did not find binary upload log", binaryLog);
}
Aggregations