use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testMimeDetection2.
@Test
// Ignore until we find a proper fix for this problem...
@Ignore
public void testMimeDetection2() throws IOException {
// File-based test - no sandbox mode
NavajoFactory.getInstance().setSandboxMode(false);
URL url = this.getClass().getResource("binary1.txt");
Binary binaryx = new Binary(new File(url.getFile()));
Assert.assertEquals("text/plain", binaryx.guessContentType());
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testBinaryIteratorFromLazyURL.
@Test
public void testBinaryIteratorFromLazyURL() throws IOException {
NavajoFactory.getInstance().setSandboxMode(false);
URL u = new URL("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
Binary b1 = new Binary(u, false);
int i = 0;
int size = 0;
for (byte[] e : b1.getDataAsIterable(128)) {
i++;
size += e.length;
}
logger.info(">>> {}", size);
Assert.assertEquals(5969, size);
Assert.assertEquals(93, i);
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestTMLJson method testJsonBinary.
@Test
public void testJsonBinary() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Binary binary1 = new Binary(getClass().getResourceAsStream("binary1.txt"));
Property binProp = NavajoFactory.getInstance().createProperty(n, "Bin", "", "", "");
binProp.setAnyValue(binary1);
n.getMessage("SimpleMessage").addProperty(binProp);
Property testprop = NavajoFactory.getInstance().createProperty(n, "TestProp", "", "", "");
testprop.setAnyValue("100a");
n.getMessage("SimpleMessage").addProperty(testprop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
// Length should be 113, right?
Assert.assertEquals(113, result.length());
// Turn back into a Navajo and compare
Navajo n2 = json.parse(new StringReader(result), "SimpleMessage");
Assert.assertEquals(n2.getMessage("SimpleMessage").getProperty("Bin").getTypedValue(), "YWJjZGVmZw==");
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class Base64Encode method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
Object o = operand(0).value;
String data = null;
if (o instanceof Binary) {
Binary b = (Binary) o;
data = Base64.getEncoder().encodeToString(b.getData());
} else if (o instanceof String) {
data = Base64.getEncoder().encodeToString(((String) o).getBytes(StandardCharsets.UTF_8));
} else if (o instanceof Property && ((Property) o).getType() == Property.BINARY_PROPERTY) {
data = ((Property) o).getValue();
} else {
throw new TMLExpressionException("Can not Base64Encode null data");
}
return data;
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method setUp.
@Before
public void setUp() throws IOException {
NavajoFactory.getInstance().setSandboxMode(true);
fixture.setUp();
binary1 = new Binary(getClass().getResourceAsStream("binary1.txt"));
binary2 = new Binary(getClass().getResourceAsStream("binary2.txt"));
binary3 = new Binary(getClass().getResourceAsStream("binary3.txt"));
binary4 = new Binary(getClass().getResourceAsStream("binary4.txt"));
logger.info("Created first");
StringWriter sw = new StringWriter();
binary1.writeBase64(sw);
StringReader sr = new StringReader(sw.toString());
binary5 = new Binary(sr);
logger.info("Last...");
}
Aggregations