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());
}
}
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();
}
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();
}
Aggregations