I'm not able to Encode/Decode a class from the Standard-JDK (
java.util.Properties).
The inserted key/value pair is not available after decode.
Any idea what goint wrong?!?
Thank in advance!
Code of the application:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.avro.*;
import org.apache.avro.io.*;
import org.apache.avro.reflect.*;
public class AvroPropertiesTest {
public static void main(String[] args) throws IOException {
ReflectData reflectData = ReflectData.get();
Schema schema = reflectData.getSchema(Properties.class);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Encoder e = EncoderFactory.get().binaryEncoder(os, null);
Properties properties = new Properties();
properties.put("Hello", "World");
System.out.println("properties: " + properties);
DatumWriter<Properties> writer =
new ReflectDatumWriter<Properties>(schema);
writer.write(properties, e);
e.flush();
ReflectDatumReader<Properties> reader = new
ReflectDatumReader<Properties>(
schema);
Decoder decoder =
DecoderFactory.get().binaryDecoder(os.toByteArray(),
null);
Properties decodedProperties = (Properties) reader.read(null,
decoder);
System.out.println("decodedProperties: " + decodedProperties);
}
}
--
This email was Anti Virus checked by Astaro Security Gateway.
http://www.astaro.com