use of org.apache.pivot.serialization.PropertiesSerializer in project pivot by apache.
the class PropertiesSerializerTest method readValues.
@Test
public // run writeValues before readValues, important
void readValues() throws IOException, SerializationException {
log("readValues()");
assertNotNull(testMap);
// prepare test data, but without using a static variable
byte[] testBytes = mapToPropertiesToBytes(testMap);
assertNotNull(testBytes);
Serializer<Map<?, ?>> serializer = new PropertiesSerializer();
log("serializer instance created: " + serializer);
ByteArrayInputStream inputStream = new ByteArrayInputStream(testBytes);
@SuppressWarnings("unchecked") Map<String, Object> readData = (Map<String, Object>) serializer.readObject(inputStream);
assertNotNull(readData);
log("Succesfully Read");
for (String key : readData) {
log(key + "=" + readData.get(key));
}
inputStream.close();
}
use of org.apache.pivot.serialization.PropertiesSerializer in project pivot by apache.
the class PropertiesSerializerTest method mapToPropertiesToBytes.
// utility method to transform the given Map to Properties,
// and then to byte array
protected byte[] mapToPropertiesToBytes(Map<String, Object> testMap2) throws IOException, SerializationException {
Serializer<Map<?, ?>> serializer = new PropertiesSerializer();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
serializer.writeObject(testMap2, outputStream);
outputStream.flush();
outputStream.close();
String result = outputStream.toString();
return result.getBytes();
}
Aggregations