Package org.apache.avro.io

Examples of org.apache.avro.io.JsonDecoder$ReorderBuffer


    Encoder e = new JsonEncoder(s, bao);
    w.write(r, e);
    e.flush();
   
    Object o = new GenericDatumReader<GenericRecord>(s).read(null,
        new JsonDecoder(s, new ByteArrayInputStream(bao.toByteArray())));
    assertEquals(r, o);
  }
View Full Code Here


    writer.write(datum, encoder);
    encoder.flush();
    byte[] data = out.toByteArray();

    reader.setSchema(schema);
    Decoder decoder = new JsonDecoder(schema, new ByteArrayInputStream(data));
    Object decoded = reader.read(null, decoder);
    assertEquals("Decoded data does not match.", datum, decoded);

    decoded = reader.read(decoded, decoder);
    assertEquals("Decoded data does not match.", datum, decoded);
View Full Code Here

    assertEquals("Encoded data does not match.", json, encoded);

    DatumReader<Object> reader = new GenericDatumReader<Object>();
    reader.setSchema(schema);
    Object decoded =
      reader.read(null, new JsonDecoder(schema,new ByteArrayInputStream(data)));
     
    assertEquals("Decoded data does not match.", datum, decoded);
  }
View Full Code Here

                if(keyFormat.equals("readable")) {
                    Object keyObject;
                    String keySerializerName = keySerializerDef.getName();
                    if(isAvroSchema(keySerializerName)) {
                        Schema keySchema = Schema.parse(keySerializerDef.getCurrentSchemaInfo());
                        JsonDecoder decoder = new JsonDecoder(keySchema, keyString);
                        GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(keySchema);
                        keyObject = datumReader.read(null, decoder);
                    } else if(keySerializerName.equals(DefaultSerializerFactory.JSON_SERIALIZER_TYPE_NAME)) {
                        JsonReader jsonReader = new JsonReader(new StringReader(keyString));
                        keyObject = jsonReader.read();
View Full Code Here

                // before we do the actual parsing with the schema
                String avroString = (String) obj;
                // From here on, this is just normal avro parsing.
                Schema latestSchema = Schema.parse(serializerDef.getCurrentSchemaInfo());
                try {
                    JsonDecoder decoder = new JsonDecoder(latestSchema, avroString);
                    GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(latestSchema);
                    obj = datumReader.read(null, decoder);
                } catch(IOException io) {
                    errorStream.println("Error parsing avro string " + avroString);
                    io.printStackTrace();
View Full Code Here

                if(line.toLowerCase().startsWith("get")) {

                    System.out.println("Enter key:");
                    line = reader.readLine();

                    JsonDecoder decoder = new JsonDecoder(keySchema, line);
                    GenericDatumReader<Object> datumReader = null;
                    Object key = null;
                    try {
                        datumReader = new GenericDatumReader<Object>(keySchema);
                        key = datumReader.read(null, decoder);
                    } catch(IOException e) {}
                    if(key == null) {
                        System.err.println("Error parsing key ");
                        continue;
                    }

                    System.out.println("Value - " + client.get(key));
                } else if(line.toLowerCase().startsWith("put")) {

                    String keyString = null;
                    String valueString = null;

                    System.out.println("Enter key:");
                    line = reader.readLine();
                    keyString = line;

                    System.out.println("Enter value:");
                    line = reader.readLine();
                    valueString = line;

                    JsonDecoder keyDecoder = new JsonDecoder(keySchema, keyString);
                    JsonDecoder valueDecoder = new JsonDecoder(valueSchema, valueString);

                    GenericDatumReader<Object> datumReader = null;
                    Object key = null;
                    Object value = null;
                    try {
View Full Code Here

  protected Decoder createDecoder() throws IOException {
    switch(codecType) {
      case BINARY:
        return new BinaryDecoder(getOrCreateInputStream());
      case JSON:
        return new JsonDecoder(schema, getOrCreateInputStream());
    }
    return null;
  }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static Properties readSingleClientConfigAvro(String configAvro) {
        Properties props = new Properties();
        try {
            JsonDecoder decoder = new JsonDecoder(CLIENT_CONFIG_AVRO_SCHEMA, configAvro);
            GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(CLIENT_CONFIG_AVRO_SCHEMA);
            Map<Utf8, Utf8> flowMap = (Map<Utf8, Utf8>) datumReader.read(null, decoder);
            for(Utf8 key: flowMap.keySet()) {
                props.put(key.toString(), flowMap.get(key).toString());
            }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static Map<String, Properties> readMultipleClientConfigAvro(String configAvro) {
        Map<String, Properties> mapStoreToProps = Maps.newHashMap();
        try {
            JsonDecoder decoder = new JsonDecoder(CLIENT_CONFIGS_AVRO_SCHEMA, configAvro);
            GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(CLIENT_CONFIGS_AVRO_SCHEMA);

            Map<Utf8, Map<Utf8, Utf8>> storeConfigs = (Map<Utf8, Map<Utf8, Utf8>>) datumReader.read(null,
                                                                                                    decoder);
            // Store config props to return back
View Full Code Here

                    if(keyFormat.equals(AdminParserUtils.OPT_JSON)) {
                        Object keyObject;
                        String keySerializerName = keySerializerDef.getName();
                        if(isAvroSchema(keySerializerName)) {
                            Schema keySchema = Schema.parse(keySerializerDef.getCurrentSchemaInfo());
                            JsonDecoder decoder = new JsonDecoder(keySchema, keyString);
                            GenericDatumReader<Object> datumReader = new GenericDatumReader<Object>(keySchema);
                            keyObject = datumReader.read(null, decoder);
                        } else if(keySerializerName.equals(DefaultSerializerFactory.JSON_SERIALIZER_TYPE_NAME)) {
                            JsonReader jsonReader = new JsonReader(new StringReader(keyString));
                            keyObject = jsonReader.read();
View Full Code Here

TOP

Related Classes of org.apache.avro.io.JsonDecoder$ReorderBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.