Example usage for java.io ObjectOutputStream ObjectOutputStream

List of usage examples for java.io ObjectOutputStream ObjectOutputStream

Introduction

In this page you can find the example usage for java.io ObjectOutputStream ObjectOutputStream.

Prototype

public ObjectOutputStream(OutputStream out) throws IOException 

Source Link

Document

Creates an ObjectOutputStream that writes to the specified OutputStream.

Usage

From source file:gnomezgrave.gsyncj.auth.ProfileSettings.java

public void saveSettings() throws IOException, ClassNotFoundException {
    ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(filePath));
    oo.writeObject(this);
    oo.close();/*w  w  w.  ja  va 2 s  .c o  m*/
}

From source file:net.sf.ehcache.amqp.AMQEventMessage.java

public byte[] toBytes() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*from  w w  w.  jav a2s.c  o m*/
        ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(this);
    } catch (IOException e) {
        throw new CacheException(e);
    }
    return baos.toByteArray();
}

From source file:de.rnd7.urlcache.URLCacheLoader.java

private void saveToDisk(final CachedElement element, final URLCacheKey key) throws IOException {
    final File localFile = this.toLocalFile(key);

    try (FileOutputStream fos = new FileOutputStream(localFile);
            ObjectOutputStream out = new ObjectOutputStream(fos);) {

        out.writeObject(element);/*from w  w  w  . j av a  2s . c  o m*/
        out.flush();
    }
}

From source file:com.cloudera.kitten.util.LocalDataHelper.java

public static <T> String serialize(Map<String, T> mapping) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/* w  ww .  j ava2 s. co m*/
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(mapping);
        oos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Base64.encodeBase64String(baos.toByteArray());
}

From source file:com.brianjmelton.apcs.api.BasicCookieStoreSerializer.java

@Override
public void persist(Map<URI, List<SerializableCookie>> cookies) throws PersistenceException {
    try {/* w  ww.  j av a2 s  . c om*/
        OutputStream fout = new FileOutputStream(cookieFile);
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(cookies);
        IOUtils.closeQuietly(oos);
    } catch (Throwable t) {
        throw new PersistenceException(t);
    }
}

From source file:com.jaspersoft.jasperserver.util.JasperSerializationUtil.java

/**
 * Serialize to a byte array//from   w  w w .  ja  v  a2  s.  co  m
 * @param input
 * @return
 */
public static byte[] serialize(Object input) {

    byte[] output = null;
    Exception exp = null;

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    long startTime = System.currentTimeMillis();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Enter serialize .. Start Time" + System.currentTimeMillis());
        }

        oos = new ObjectOutputStream(bos);
        oos.writeObject(input);
        output = bos.toByteArray();
    } catch (IOException e) {
        exp = e;
    } finally {
        try {
            if (null != oos) {
                oos.close();
            }
            bos.close();
        } catch (IOException e) {
        }
        if (logger.isDebugEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.debug("Exit serialize .. Total Time Spent: " + elapsedTime);
        }

        if (null != exp) {
            throw new RuntimeException(exp);
        }
    }

    return output;
}

From source file:com.github.tell.codec.Base64Serializer.java

public byte[] encode(final Serializable o) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final Base64OutputStream b64os = new Base64OutputStream(baos, true);
    final ObjectOutputStream oos = new ObjectOutputStream(b64os);
    oos.writeObject(o);//from  ww w . ja v a 2s.c  om
    oos.close();
    return baos.toByteArray();
}

From source file:com.jaspersoft.jasperserver.api.metadata.data.cache.JavaDataSnapshotSerializer.java

public void writeSnapshot(DataSnapshot snapshot, OutputStream out) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("serializing data snapshot of type " + snapshot.getClass().getName());
    }/*from w  w w  .  j a va  2s . c  o m*/

    ObjectOutputStream objectOut = new ObjectOutputStream(out);
    objectOut.writeObject(snapshot);
}

From source file:io.cloudslang.orchestrator.services.ExecutionSerializationUtil.java

public byte[] objToBytes(Execution obj) {
    ObjectOutputStream oos;//from  w  w w  . j  av  a 2 s.  c  om
    try {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(bout);
        oos = new ObjectOutputStream(bos);

        oos.writeObject(obj);
        oos.close();

        @SuppressWarnings({ "UnnecessaryLocalVariable" })
        byte[] bytes = bout.toByteArray();
        return bytes;
    } catch (IOException ex) {
        throw new RuntimeException("Failed to serialize execution . Error: ", ex);
    }
}

From source file:glluch.com.ontotaxoseeker.TestsGen.java

public static String save(Object o, String className) throws FileNotFoundException, IOException {

    if (StringUtils.isEmpty(className)) {
        Out.p("TestsGen.save have received an anonomous object");
        className = "anonimousClass";
    }/*from  w  w w .j a va2  s  .  com*/

    FileOutputStream fileOut = new FileOutputStream("resources/test/" + className + ".ser");
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(o);
    out.close();
    fileOut.close();
    System.out.printf(
            "Serialized data is saved in " + "resources/test/" + className + ".ser" + System.lineSeparator());

    return "resources/test/" + className + ".ser";
}