public static final void decompress(IData pipeline) throws ServiceException { // --- <<IS-START(decompress)>> --- // @subtype unknown // @sigtype java 3.5 // [i] object:0:optional $content.gzip // [i] field:0:optional $encoding // [i] field:0:optional $mode // {"stream","bytes","string","base64"} // [o] object:0:optional $content IDataCursor cursor = pipeline.getCursor(); try { Object input = IDataUtil.get(cursor, "$content.gzip"); Charset charset = CharsetHelper.normalize(IDataUtil.getString(cursor, "$encoding")); ObjectConvertMode mode = ObjectConvertMode.normalize(IDataUtil.getString(cursor, "$mode")); Object output = ObjectHelper.convert( GzipHelper.decompress(InputStreamHelper.normalize(input, charset)), charset, mode); if (output != null) IDataUtil.put(cursor, "$content", output); } catch (IOException ex) { ExceptionHelper.raise(ex); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void write(IData pipeline) throws ServiceException { // --- <<IS-START(write)>> --- // @subtype unknown // @sigtype java 3.5 // [i] field:0:optional $file // [i] field:0:optional $mode {"append","write"} // [i] object:0:optional $content // [i] field:0:optional $encoding // [o] field:0:optional $file IDataCursor cursor = pipeline.getCursor(); try { String file = IDataUtil.getString(cursor, "$file"); String mode = IDataUtil.getString(cursor, "$mode"); Object content = IDataUtil.get(cursor, "$content"); String encoding = IDataUtil.getString(cursor, "$encoding"); file = write(file, mode, content, encoding); IDataUtil.put(cursor, "$file", file); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void put(IData pipeline) throws ServiceException { // --- <<IS-START(put)>> --- // @subtype unknown // @sigtype java 3.5 // [i] field:0:optional $key // [i] object:0:optional $value IDataCursor cursor = pipeline.getCursor(); try { String key = IDataUtil.getString(cursor, "$key"); Object value = IDataUtil.get(cursor, "$value"); tundra.support.document.put(pipeline, key, value); } finally { cursor.destroy(); } // --- <<IS-END>> --- }
public static final void epochToDateString(IData pipeline) throws ServiceException { // --- <<IS-START(epochToDateString)>> --- // @sigtype java 3.5 // [i] object:0:required epochTime // [o] field:0:required dateString IDataCursor pipelineCursor = pipeline.getCursor(); Long myTimeAsLong = (Long) IDataUtil.get(pipelineCursor, "epochTime"); Date date = new Date(myTimeAsLong); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); String dateString = format.format(date); IDataUtil.put(pipelineCursor, "dateString", dateString); pipelineCursor.destroy(); // --- <<IS-END>> --- }
protected <T> T extractSingleValue( IData data, ValueConverter<?, T> converter, String key, boolean mandatory, T defaultValue) throws ServiceOutputException { T result = defaultValue; IDataCursor cur = data.getCursor(); try { Object value = IDataUtil.get(cur, key); if (value != null) { if (converter.canConvert(value)) { result = converter.convert(value); } else { throw new ServiceOutputException( this, "can not convert " + key + " to " + converter.getResultType()); } } if (result == null && mandatory) { throw new ServiceOutputException(this, String.format("missing required %s", key)); } } finally { cur.destroy(); } return result; }