public static void encode(List<String> valueList, StreamSchema schema, OutputStream out, boolean eof)
    throws IOException {
    int index = 0;
    GDATEncoder encoder = new GDATEncoder();
    Preconditions.checkArgument(valueList.size() == schema.getFields().size());
    for (GDATField field : schema.getFields()) {
      String value = valueList.get(index);
      switch(field.getType()) {
        case BOOL:
          encoder.writeBool(Boolean.parseBoolean(value));
          break;
        case INT:
          encoder.writeInt(Integer.valueOf(value));
          break;
        case LONG:
          encoder.writeLong(Long.valueOf(value));
          break;
        case DOUBLE:
          encoder.writeDouble(Double.valueOf(value));
          break;
        case STRING:
          encoder.writeString(value);
          break;
      }
      index++;
    }
    if (!eof) {
      encoder.writeTo(out);
    } else {
      encoder.writeEOFRecord(out);
    }
  }
public static void encode ( List < String > valueList , StreamSchema schema , OutputStream out , boolean eof ) throws IOException { int index = 0 ; GDATEncoder encoder = new GDATEncoder ( ) ; Preconditions . checkArgument ( valueList . size ( ) == schema . getFields ( ) . size ( ) ) ; for ( GDATField field : schema . getFields ( ) ) { String value = valueList . get ( index ) ; switch ( field . getType ( ) ) { case BOOL : encoder . writeBool ( Boolean . parseBoolean ( value ) ) ; break ; case INT : encoder . writeInt ( Integer . valueOf ( value ) ) ; break ; case LONG : encoder . writeLong ( Long . valueOf ( value ) ) ; break ; case DOUBLE : encoder . writeDouble ( Double . valueOf ( value ) ) ; break ; case STRING : encoder . writeString ( value ) ; break ; } index ++ ; } if ( ! eof ) { encoder . writeTo ( out ) ; } else { encoder . writeEOFRecord ( out ) ; } }
TODO: Think about using Json objects to parse the JSON input instead of considering all the values as Strings.