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

eu.interedition.text.h2.SerializableDataStreamMapper Maven / Gradle / Ivy

The newest version!
package eu.interedition.text.h2;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

/**
 * @author Gregor Middell
 */
public class SerializableDataStreamMapper implements DataStreamMapper {

    @Override
    public void write(T data, OutputStream stream) throws IOException {
        final ObjectOutputStream objectStream = new ObjectOutputStream(stream);
        objectStream.writeObject(data);
        objectStream.flush();
    }

    @SuppressWarnings("unchecked")
    @Override
    public T read(InputStream stream, Class type) throws IOException {
        final ObjectInputStream objectStream = new ObjectInputStream(stream);
        try {
            return (T) objectStream.readObject();
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy