Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:id.co.nlp.MachineTranslation.Utils.Util.java

public static void serializing(String pathfile, Object object) throws FileNotFoundException, IOException {
    FileOutputStream fileOut = new FileOutputStream(pathfile);
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(object);//from  w  w  w. j a v a 2 s . c  o  m
    out.close();
    fileOut.close();
}

From source file:com.evolveum.midpoint.util.SerializationUtil.java

public static String toString(Object object) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(object);
    objectOutputStream.close();
    return new String(Base64.encodeBase64(byteArrayOutputStream.toByteArray()));
}

From source file:Main.java

public static byte[] ObjectToByte(Serializable obj) {
    byte[] bytes = null;
    try {/*from  w w  w . j  a v a2 s .  co  m*/
        // object to bytearray
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(bo);
        oo.writeObject(obj);

        bytes = bo.toByteArray();

        bo.close();
        oo.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bytes;
}

From source file:Main.java

public static byte[] getBytes(Object obj) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);/*from w w w.j a va 2  s . c  om*/
    out.flush();
    byte[] bytes = bout.toByteArray();
    bout.close();
    out.close();
    return bytes;
}

From source file:com.test.todolist.ObjectSerializer.java

public static String serialize(Serializable obj) throws IOException {
    if (obj == null)
        return "";
    try {//from www  . j av  a2 s .  com
        ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
        ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
        objStream.writeObject(obj);
        objStream.close();
        return encodeBytes(serialObj.toByteArray());
    } catch (Exception e) {
        return "exception";
    }
}

From source file:com.ecyrd.jspwiki.util.Serializer.java

/**
 * Serializes a Map and formats it into a Base64-encoded String. For ease of serialization, the Map contents
 * are first copied into a HashMap, then serialized into a byte array that is encoded as a Base64 String.
 * @param map the Map to serialize// ww w  .j av a  2  s  .c om
 * @return a String representing the serialized form of the Map
 * @throws IOException If serialization cannot be done
 */
public static String serializeToBase64(Map<String, Serializable> map) throws IOException {
    // Load the Map contents into a defensive HashMap
    HashMap<String, Serializable> serialMap = new HashMap<String, Serializable>();
    serialMap.putAll(map);

    // Serialize the Map to an output stream
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bytesOut);
    out.writeObject(serialMap);
    out.close();

    // Transform to Base64-encoded String
    byte[] result = Base64.encodeBase64(bytesOut.toByteArray());
    return new String(result);
}

From source file:com.trin.nilmobile.serializer.ObjectSerializer.java

public static String serialize(Serializable obj) throws IOException {
    if (obj == null)
        return "";
    try {//from   w w  w .j a va  2 s . c  o m
        ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
        ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
        objStream.writeObject(obj);
        objStream.close();
        return encodeBytes(serialObj.toByteArray());
    } catch (Exception e) {
        throw new IOException("Serialization error: " + e.getMessage(), e);
    }
}

From source file:edu.virginia.jtd5qe.twitter.ObjectSerializer.java

public static String serialize(Serializable obj) throws IOException {
    if (obj == null)
        return "";
    try {/*from  w  ww .jav  a  2  s  . com*/
        ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
        ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
        objStream.writeObject(obj);
        objStream.close();
        return encodeBytes(serialObj.toByteArray());
    } catch (Exception e) {
        throw WrappedIOException.wrap("Serialization error: " + e.getMessage(), e);
    }
}

From source file:homemade.apps.framework.homerlibs.utils.ObjectSerializer.java

public static String serialize(Serializable obj) {
    if (obj == null)
        return "";
    try {/*w  w w .  jav  a 2 s.c o m*/
        ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
        ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
        objStream.writeObject(obj);
        objStream.close();
        return encodeBytes(serialObj.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mErrorReturn;
}

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);//  w ww .jav a2  s.  c  o  m
    oo.close();
}