Exemple #1
0
  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
    // {&quot;stream&quot;,&quot;bytes&quot;,&quot;string&quot;,&quot;base64&quot;}
    // [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>> ---

  }
Exemple #2
0
  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 {&quot;append&quot;,&quot;write&quot;}
    // [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>> ---

  }
Exemple #3
0
  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>> ---

  }
Exemple #4
0
  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;
 }