use of java.io.ObjectOutputStream in project guava by google.
the class MultimapBuilderTest method reserialize.
// serialization
@GwtIncompatible
private static Object reserialize(Object object) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
new ObjectOutputStream(bytes).writeObject(object);
return new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject();
}
use of java.io.ObjectOutputStream in project guice by google.
the class MultibinderTest method testMultibinderSetIsSerializable.
public void testMultibinderSetIsSerializable() throws IOException, ClassNotFoundException {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), String.class).addBinding().toInstance("A");
}
});
Set<String> set = injector.getInstance(Key.get(setOfString));
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream);
try {
objectOutputStream.writeObject(set);
} finally {
objectOutputStream.close();
}
ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
try {
Object setCopy = objectInputStream.readObject();
assertEquals(set, setCopy);
} finally {
objectInputStream.close();
}
}
use of java.io.ObjectOutputStream in project spring-boot by spring-projects.
the class ClassPathChangeUploader method serialize.
private byte[] serialize(ClassLoaderFiles classLoaderFiles) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
objectOutputStream.writeObject(classLoaderFiles);
objectOutputStream.close();
return outputStream.toByteArray();
}
use of java.io.ObjectOutputStream in project PocketHub by pockethub.
the class RequestWriter method write.
/**
* Write request to file
*
* @param request
* @return request
*/
public <V> V write(V request) {
RandomAccessFile dir = null;
FileLock lock = null;
ObjectOutputStream output = null;
try {
createDirectory(handle.getParentFile());
dir = new RandomAccessFile(handle, "rw");
lock = dir.getChannel().lock();
output = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(dir.getFD()), 8192));
output.writeInt(version);
output.writeObject(request);
} catch (IOException e) {
Log.d(TAG, "Exception writing cache " + handle.getName(), e);
return null;
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
Log.d(TAG, "Exception closing stream", e);
}
}
if (lock != null) {
try {
lock.release();
} catch (IOException e) {
Log.d(TAG, "Exception unlocking file", e);
}
}
if (dir != null) {
try {
dir.close();
} catch (IOException e) {
Log.d(TAG, "Exception closing file", e);
}
}
}
return request;
}
use of java.io.ObjectOutputStream in project javatari by ppeccin.
the class RemoteReceiver method tryConnection.
private void tryConnection(String serverAddress) throws IOException, IllegalArgumentException {
this.serverAddress = serverAddress;
try {
String addr = getHost(serverAddress);
int port = getPort(serverAddress);
socket = new Socket(addr, port);
socket.setTcpNoDelay(true);
socketOutputStream = socket.getOutputStream();
outputStream = new ObjectOutputStream(socketOutputStream);
socketInputStream = socket.getInputStream();
inputStream = new ObjectInputStream(socketInputStream);
} catch (IOException ex) {
disconnection();
throw ex;
}
resetUpdatesPending();
updatesReceiver = new UpdatesReceiver();
updatesReceiver.start();
updatesConsumer = new UpdatesConsumer();
updatesConsumer.start();
console.connected();
notifyConnectionStatusListeners();
}
Aggregations