Search in sources :

Example 81 with ObjectOutputStream

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 82 with ObjectOutputStream

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Injector(com.google.inject.Injector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) AbstractModule(com.google.inject.AbstractModule) ObjectInputStream(java.io.ObjectInputStream)

Example 83 with ObjectOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 84 with ObjectOutputStream

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;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) FileLock(java.nio.channels.FileLock) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 85 with ObjectOutputStream

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();
}
Also used : IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Socket(java.net.Socket) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectOutputStream (java.io.ObjectOutputStream)1102 ByteArrayOutputStream (java.io.ByteArrayOutputStream)760 ObjectInputStream (java.io.ObjectInputStream)428 ByteArrayInputStream (java.io.ByteArrayInputStream)375 IOException (java.io.IOException)358 FileOutputStream (java.io.FileOutputStream)161 Test (org.junit.Test)161 File (java.io.File)96 BufferedOutputStream (java.io.BufferedOutputStream)52 ObjectOutput (java.io.ObjectOutput)47 OutputStream (java.io.OutputStream)37 HashMap (java.util.HashMap)37 ArrayList (java.util.ArrayList)33 FileInputStream (java.io.FileInputStream)25 InputStream (java.io.InputStream)23 FileNotFoundException (java.io.FileNotFoundException)22 Serializable (java.io.Serializable)17 GZIPOutputStream (java.util.zip.GZIPOutputStream)16 Test (org.testng.annotations.Test)15 NotSerializableException (java.io.NotSerializableException)14