Search in sources :

Example 1 with FileLineMap

use of com.dexels.navajo.adapter.filemap.FileLineMap in project navajo by Dexels.

the class FileMap method setMessage.

public void setMessage(Object o) throws MappableException {
    if (o instanceof Message) {
        Message arrraymessage = (Message) o;
        if (!arrraymessage.getType().equals(Message.MSG_TYPE_ARRAY)) {
            throw new MappableException("SetMssage only accepts array message");
        }
        for (Message m : arrraymessage.getElements()) {
            FileLineMap fileLineMap = new FileLineMap();
            fileLineMap.setSeparator(separator);
            for (Property p : m.getAllProperties()) {
                fileLineMap.setColumn(p.getTypedValue().toString());
            }
            setLine(fileLineMap);
        }
    } else if (o instanceof List) {
        @SuppressWarnings("rawtypes") List maps = (List) o;
        for (Object mapobject : maps) {
            if (mapobject instanceof com.dexels.navajo.adapter.navajomap.MessageMap) {
                com.dexels.navajo.adapter.navajomap.MessageMap map = (com.dexels.navajo.adapter.navajomap.MessageMap) mapobject;
                FileLineMap fileLineMap = new FileLineMap();
                fileLineMap.setSeparator(separator);
                for (Property p : map.getMsg().getAllProperties()) {
                    if (p.getName().equals("__id")) {
                        continue;
                    }
                    if (p.getTypedValue() != null) {
                        fileLineMap.setColumn(p.getTypedValue().toString());
                    } else {
                        fileLineMap.setColumn("");
                    }
                }
                setLine(fileLineMap);
            }
        }
    } else {
        throw new MappableException("SetMessage only accepts array message or List, but got a " + o.getClass());
    }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) Message(com.dexels.navajo.document.Message) FileLineMap(com.dexels.navajo.adapter.filemap.FileLineMap) ArrayList(java.util.ArrayList) List(java.util.List) Property(com.dexels.navajo.document.Property)

Example 2 with FileLineMap

use of com.dexels.navajo.adapter.filemap.FileLineMap in project navajo by Dexels.

the class TestAdapters method testFileMap.

@Test
public void testFileMap() throws IOException, MappableException, UserException {
    FileMap fm = new FileMap();
    FileLineMap[] flm = new FileLineMap[2];
    flm[0] = new FileLineMap();
    flm[0].setLine("apenoot");
    flm[1] = new FileLineMap();
    flm[1].setLine("kibbeling");
    fm.setLines(flm);
    File f = File.createTempFile("test", ".txt");
    fm.setFileName(f.getAbsolutePath());
    fm.store();
    Assert.assertEquals(18, f.length());
    f.deleteOnExit();
}
Also used : FileLineMap(com.dexels.navajo.adapter.filemap.FileLineMap) File(java.io.File) Test(org.junit.Test)

Example 3 with FileLineMap

use of com.dexels.navajo.adapter.filemap.FileLineMap in project navajo by Dexels.

the class FileMap method getBytes.

private byte[] getBytes() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (int i = 0; i < lineArray.size(); i++) {
        FileLineMap flm = lineArray.get(i);
        if (flm != null) {
            String nextLine = handleLineEnds(flm.getLine());
            baos.write((charsetName == null) ? nextLine.getBytes() : nextLine.getBytes(charsetName));
        }
    }
    baos.close();
    return baos.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileLineMap(com.dexels.navajo.adapter.filemap.FileLineMap)

Aggregations

FileLineMap (com.dexels.navajo.adapter.filemap.FileLineMap)3 Message (com.dexels.navajo.document.Message)1 Property (com.dexels.navajo.document.Property)1 MappableException (com.dexels.navajo.script.api.MappableException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1