Example usage for java.io ObjectOutputStream writeObject

List of usage examples for java.io ObjectOutputStream writeObject

Introduction

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

Prototype

public final void writeObject(Object obj) throws IOException 

Source Link

Document

Write the specified object to the ObjectOutputStream.

Usage

From source file:com.moz.fiji.hive.utils.FijiDataRequestSerializer.java

/**
 * Serializes a data request./*from   w  w  w . jav a  2s  . c  o  m*/
 *
 * @param dataRequest A data request.
 * @return The serialized data request.
 * @throws IOException If there is an error.
 */
public static String serialize(FijiDataRequest dataRequest) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    try {
        oos.writeObject(dataRequest);
        oos.flush();
        return Base64.encodeBase64String(baos.toByteArray());
    } finally {
        IOUtils.closeQuietly(oos);
    }
}

From source file:de.kbs.acavis.service.SerializationHelper.java

public static String serializePublicationIdentifier(PublicationIdentifier identifier) throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    ObjectOutputStream so = new ObjectOutputStream(bo);

    so.writeObject(identifier);
    so.flush();/* w  w w .  j  a v  a  2  s .  c o m*/

    String serialization = bo.toString();

    so.close();
    bo.close();

    return serialization;
}

From source file:de.kbs.acavis.service.SerializationHelper.java

public static String serializeAuthorIdentifier(AuthorIdentifier identifier) throws IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    ObjectOutputStream so = new ObjectOutputStream(bo);

    so.writeObject(identifier);
    so.flush();//from   ww  w.  j  a  v a2 s  .  c  om

    String serialization = bo.toString();

    so.close();
    bo.close();

    return serialization;
}

From source file:com.koda.common.lcm.Tool.java

public static String doObject(Serializable obj) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    return doStuff(baos.toByteArray());
}

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

public static void saveSettings(ProfileSettings settings, String fileName)
        throws IOException, ClassNotFoundException {
    ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(fileName));
    oo.writeObject(settings);
    oo.close();//from  w w  w  . j av a  2s  . c  om
}

From source file:be.vdab.util.Programma.java

private static void schrijweg(TreeSet<Voertuig> verzameling, String file)
        throws FileNotFoundException, IOException {

    FileOutputStream outputStream = new FileOutputStream(file);
    ObjectOutputStream oos = new ObjectOutputStream(outputStream);
    oos.writeObject(verzameling);//TreeSet implements Serializable, superklasse AbstractSet implements NIET Serializable, maar heeft een no-args constructor-->dus serialiseerbaar
    oos.close();//from   www  . j  a  va2s .  com
    //voertuig serialiseerbaar maken want die zit in de treeSet, maar de comparator als innerclasses moeten ook serialiseerbaar gemaaakt worden!

}

From source file:Serialization.java

/**
 * Gets an array of bytes corresponding to the given object.
 * @param object the object to serialize
 * @return an array of bytes./*from w w  w .  ja  va  2 s  .  c om*/
 * @throws IOException if the object can't be turned into an array of bytes.
 */
public static byte[] storeObject(final Serializable object) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(baos);
        oos.writeObject(object);
        oos.flush();
        return baos.toByteArray();
    } finally {
        if (oos != null) {
            oos.close();
        }
        if (baos != null) {
            baos.close();
        }
    }
}

From source file:com.algodefu.yeti.md5.MD5HashGenerator.java

private static byte[] objectToByteArray(Object obj) {

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream o = null;
    try {//from w w w .  j  av a 2s  .co m
        o = new ObjectOutputStream(b);
        o.writeObject(obj);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return b.toByteArray();
}

From source file:Main.java

/**
 * serialize to file//from  ww w  .  j a  v a  2s .  com
 * 
 * @param filePath
 * @param obj
 * @return
 * @throws RuntimeException if an error occurs
 */
public static void serialization(String filePath, Object obj) {
    ObjectOutputStream out = null;
    try {
        out = new ObjectOutputStream(new FileOutputStream(filePath));
        out.writeObject(obj);
        out.close();
    } catch (FileNotFoundException e) {
        throw new RuntimeException("FileNotFoundException occurred. ", e);
    } catch (IOException e) {
        throw new RuntimeException("IOException occurred. ", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                throw new RuntimeException("IOException occurred. ", e);
            }
        }
    }
}

From source file:Main.java

/**
 * Serialize any object into String//from w ww.j  a v  a2  s.  co  m
 * @param object Object
 * @return String
 * @throws IOException If unable to access Stream
 */
public static String serialize(Object object) throws java.io.IOException {
    if (object == null)
        return null;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(
            new Base64OutputStream(byteArrayOutputStream, 0));
    objectOutputStream.writeObject(object);
    objectOutputStream.flush();
    objectOutputStream.close();
    return byteArrayOutputStream.toString();
}