avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Schönig <stefan.schoe...@sea-gmbh.com>
Subject How to encode/decode java.util.Properties
Date Mon, 14 May 2012 15:08:42 GMT
I'm not able to Encode/Decode a class from the Standard-JDK ( 
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);

		ReflectDatumReader<Properties> reader = new 
		Decoder decoder = DecoderFactory.get().binaryDecoder(os.toByteArray(),
		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

View raw message