use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class ReferenceBinaryIT method testReferenceBinaryExchangeWithSharedRepository.
/**
* Taken from org.apache.jackrabbit.core.value.ReferenceBinaryTest
* @throws Exception
*/
@Test
public void testReferenceBinaryExchangeWithSharedRepository() throws Exception {
Session firstSession = createAdminSession();
// create a binary
Binary b = firstSession.getValueFactory().createBinary(new RandomInputStream(1, STREAM_LENGTH));
ReferenceBinary referenceBinary = null;
if (b instanceof ReferenceBinary) {
referenceBinary = (ReferenceBinary) b;
}
assertNotNull(referenceBinary);
assertNotNull(referenceBinary.getReference());
// in the current test the message is exchanged via repository which is shared as well
// put the reference message value in a property on a node
String newNode = "sample_" + System.nanoTime();
firstSession.getRootNode().addNode(newNode).setProperty("reference", referenceBinary.getReference());
// save the first session
firstSession.save();
// get a second session over the same repository / ds
Session secondSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
// read the binary referenced by the referencing binary
String reference = secondSession.getRootNode().getNode(newNode).getProperty("reference").getString();
ReferenceBinary ref = new SimpleReferenceBinary(reference);
assertEquals(b, secondSession.getValueFactory().createValue(ref).getBinary());
safeLogout(firstSession);
safeLogout(secondSession);
}
use of javax.jcr.Binary in project jackrabbit by apache.
the class BinaryPropertyTest method testValueJcr2.
/**
* Tests that Value.getStream() delivers the same as Value.getBinary.getStream().
* We check this by reading each byte of the two streams and assuring that
* they are equal.
*/
public void testValueJcr2() throws IOException, RepositoryException {
Value val = PropertyUtil.getValue(prop);
InputStream in = val.getStream();
Binary bin = val.getBinary();
try {
InputStream in2 = bin.getStream();
try {
int b = in.read();
while (b != -1) {
int b2 = in2.read();
assertEquals("Value.getStream() and Value.getBinary().getStream() " + "return different values.", b, b2);
b = in.read();
}
assertEquals("Value.getStream() and Value.getBinary().getStream() " + "return different values.", -1, in2.read());
} finally {
try {
in.close();
} catch (IOException ignore) {
}
try {
in2.close();
} catch (IOException ignore) {
}
}
} finally {
bin.dispose();
}
}
use of javax.jcr.Binary in project jackrabbit by apache.
the class BinaryPropertyTest method testGetLengthJcr2.
/**
* Tests the Binary.getSize() method.
*/
public void testGetLengthJcr2() throws RepositoryException {
Value val = PropertyUtil.getValue(prop);
Binary binary = val.getBinary();
long length;
try {
length = binary.getSize();
} finally {
binary.dispose();
}
long bytes = PropertyUtil.countBytes(val);
if (bytes != -1) {
assertEquals("Binary.getSize() returns wrong number of bytes.", bytes, length);
}
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class DefaultSyncContextTest method testCreateValueFromInputStream.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-4231">OAK-4231</a>
*/
@Test
public void testCreateValueFromInputStream() throws Exception {
byte[] bytes = new byte[] { 'a', 'b' };
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Binary binary = valueFactory.createBinary(is);
Value v = syncCtx.createValue(is);
assertNotNull(v);
assertEquals(PropertyType.BINARY, v.getType());
assertEquals(binary, v.getBinary());
}
use of javax.jcr.Binary in project jackrabbit-oak by apache.
the class DefaultSyncContextTest method testCreateValueFromBytesArray.
@Test
public void testCreateValueFromBytesArray() throws Exception {
byte[] bytes = new byte[] { 'a', 'b' };
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Binary binary = valueFactory.createBinary(is);
Value v = syncCtx.createValue(bytes);
assertNotNull(v);
assertEquals(PropertyType.BINARY, v.getType());
assertEquals(binary, v.getBinary());
}
Aggregations