All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tsl2.nano.replication.serializer.SerializeXML Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package de.tsl2.nano.replication.serializer;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class SerializeXML implements Serializer {
    public static final String KEY = "XML";
    @Override
    public String getKey() {
        return KEY;
    }
    @Override
    public String getExtension() {
        return "xml";
    }
    @Override
    public ByteArrayOutputStream serialize(Object obj) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(out))) {
	        encoder.writeObject(obj);
        }
        return out;
    }
    @SuppressWarnings("unchecked")
    @Override
    public  T deserialize(InputStream stream, Class type) {
        try (XMLDecoder dec = new XMLDecoder(stream)) { return (T) dec.readObject();}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy