Search in sources :

Example 16 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TestBinaries method testBinaryStream.

@Test
public void testBinaryStream() throws Exception {
    Binary b = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml")).toObservable().lift(StreamDocument.createBinary()).firstOrError().blockingGet();
    // 5,258
    Assert.assertEquals(5258, b.getLength());
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Test(org.junit.Test)

Example 17 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class SetMimeType method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    // application/vnd.ms-excel
    Object o = getOperand(0);
    if (!(o instanceof Binary)) {
        throw new TMLExpressionException(this, "Mime type can only be set for binaries.");
    }
    Object mt = getOperand(1);
    if (!(mt instanceof String)) {
        throw new TMLExpressionException(this, "Mime type should be string expression.");
    }
    Binary b = (Binary) o;
    b.setMimeType((String) mt);
    return b;
}
Also used : Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 18 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class ToString method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    Object s = this.getOperands().get(0);
    if (s == null) {
        return null;
    }
    if (s instanceof com.dexels.navajo.document.types.Binary) {
        Binary b = (Binary) s;
        byte[] data = b.getData();
        StringWriter w = new StringWriter();
        for (int i = 0; i < data.length; i++) {
            w.write(data[i]);
        }
        return w.toString();
    }
    if (s instanceof Money) {
        Money m = (Money) s;
        return m.formattedString();
    }
    return s.toString();
}
Also used : Money(com.dexels.navajo.document.types.Money) StringWriter(java.io.StringWriter) Binary(com.dexels.navajo.document.types.Binary)

Example 19 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class ZipArchive method addFiles.

private final void addFiles(ZipOutputStream zo, String path, File f) throws Exception {
    if (f.isFile()) {
        ZipEntry entry = new ZipEntry(path + "/" + f.getName());
        zo.putNextEntry(entry);
        // Write file content
        Binary bfi = new Binary(new FileInputStream(f));
        bfi.write(zo);
    } else {
        path = (!path.equals("") ? path + "/" : "") + f.getName();
        File[] entries = f.listFiles();
        for (int i = 0; i < entries.length; i++) {
            addFiles(zo, path, entries[i]);
        }
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) Binary(com.dexels.navajo.document.types.Binary) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 20 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class ToSecureImage method main.

public static void main(String[] args) {
    try {
        java.util.Locale.setDefault(new java.util.Locale("nl", "NL"));
        // Tests.
        ToSecureImage tm = new ToSecureImage();
        for (int i = 0; i < 100; i++) {
            tm.reset();
            RandomString rs = new RandomString();
            rs.reset();
            rs.insertIntegerOperand(6);
            String random = (String) rs.evaluate();
            System.err.println("String[" + i + "]: " + random);
            // lala
            tm.insertStringOperand(new String(random));
            tm.insertIntegerOperand(110);
            tm.insertIntegerOperand(30);
            Binary b = (Binary) tm.evaluate();
        }
    } catch (Exception e) {
        logger.error("Error: ", e);
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6