use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testBinarySerialize.
@Test
public void testBinarySerialize() throws IOException, ClassNotFoundException {
NavajoFactory.getInstance().setSandboxMode(true);
Binary binaryx = new Binary(getClass().getResourceAsStream("binary1.txt"));
binaryx.getLength();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(binaryx);
byte[] bb = baos.toByteArray();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bb));
Binary ooo = (Binary) ois.readObject();
Assert.assertTrue(ooo.equals(binaryx));
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testEqual6.
@Test
public void testEqual6() throws IOException, URISyntaxException {
Binary binaryStreamed = new Binary(getClass().getResourceAsStream("logo.gif"));
Path path = Paths.get(getClass().getResource("logo.gif").toURI());
byte[] data = Files.readAllBytes(path);
Binary binaryByteArray = new Binary(data);
Assert.assertEquals(binaryStreamed, binaryByteArray);
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testMimeDetection4.
@Test
// Ignore until we find a proper fix for this problem...
@Ignore
public void testMimeDetection4() throws IOException {
// File-based test - no sandbox mode
NavajoFactory.getInstance().setSandboxMode(false);
URL url = this.getClass().getResource("doc3.docx");
Binary binaryx = new Binary(new File(url.getFile()));
Assert.assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", binaryx.guessContentType());
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class Base64ImageStringToBinary method evaluate.
// I think this function does not work when you pass a Binary into it.
// It is a bit pointless anyway, it is more like a 'clone' then.
@Override
public Object evaluate() throws TMLExpressionException {
String data = getStringOperand(0);
Binary b;
String partSeparator = ",";
if (data.contains(partSeparator)) {
String encodedImg = data.split(partSeparator)[1];
// Basic Base64 decoding
byte[] decodedValue = Base64.getDecoder().decode(encodedImg.getBytes(StandardCharsets.UTF_8));
b = new Binary(decodedValue);
return b;
} else if (data != null && !data.contains(partSeparator)) {
// Might be just the base64 string without id part
// Basic Base64 decoding
byte[] decodedValue = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8));
b = new Binary(decodedValue);
return b;
}
return null;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testResolveOnTransport.
@Test
public void testResolveOnTransport() throws IOException {
URL u = new URL("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
Binary b = new Binary(u, true);
Assert.assertFalse(b.isResolved());
StringWriter sw = new StringWriter();
b.writeBase64(sw);
sw.close();
String result = sw.toString();
Assert.assertTrue(b.isResolved());
Assert.assertTrue(result.length() > 1000);
}
Aggregations