Search in sources :

Example 1 with IDataCSVParser

use of permafrost.tundra.data.IDataCSVParser in project Tundra by Permafrost.

the class csv method emit.

// ---( server methods )---
public static final void emit(IData pipeline) throws ServiceException {
    // --- <<IS-START(emit)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $document
    // [i] - record:1:optional recordWithNoID
    // [i] field:0:optional $delimiter
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData document = IDataHelper.get(cursor, "$document", IData.class);
        String delimiter = IDataHelper.get(cursor, "$delimiter", String.class);
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        if (document != null) {
            IDataHelper.put(cursor, "$content", ObjectHelper.convert(new IDataCSVParser(delimiter).emit(document, charset), charset, mode));
        }
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : IDataCSVParser(permafrost.tundra.data.IDataCSVParser) ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Example 2 with IDataCSVParser

use of permafrost.tundra.data.IDataCSVParser in project Tundra by Permafrost.

the class csv method parse.

public static final void parse(IData pipeline) throws ServiceException {
    // --- <<IS-START(parse)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] object:0:optional $content
    // [i] field:0:optional $delimiter
    // [i] field:0:optional $encoding
    // [o] record:0:optional $document
    // [o] - record:1:optional recordWithNoID
    IDataCursor cursor = pipeline.getCursor();
    try {
        Object content = IDataHelper.get(cursor, "$content");
        String delimiter = IDataHelper.get(cursor, "$delimiter", String.class);
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        if (content != null) {
            IDataHelper.put(cursor, "$document", new IDataCSVParser(delimiter).parse(InputStreamHelper.normalize(content, charset)));
        }
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : IDataCSVParser(permafrost.tundra.data.IDataCSVParser) Charset(java.nio.charset.Charset) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 Charset (java.nio.charset.Charset)2 IDataCSVParser (permafrost.tundra.data.IDataCSVParser)2 ObjectConvertMode (permafrost.tundra.lang.ObjectConvertMode)1