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:com.mayalogy.mayu.io.LocalDataManager.java

public static void serializeAndWriteToFile(String outFile, Object o) throws IOException {
    FileOutputStream fout = new FileOutputStream(outFile + ".ser");
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    oos.writeObject(o);//  w w  w.  jav a2s .  c o m
    oos.close();
}

From source file:Main.java

private static void writePageNameHashesToFile(Map<UUID, String> map, File folder) {
    if (uuidsToNames != null) {
        String mapString = "Map: ";
        for (Map.Entry<UUID, String> entry : uuidsToNames.entrySet()) {
            mapString += entry.toString();
            mapString += "\n";
        }/*w w  w  .j  av a  2  s.  c om*/
    }

    if (map == null) { // TODO: Do I need this?
        map = new HashMap<UUID, String>();
    }

    try {
        FileOutputStream fos = new FileOutputStream(folder.getAbsolutePath() + fileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(map);
        oos.close();
    } catch (Exception e) {
        Log.e("Write to file", e.toString());
    }
}

From source file:com.yfiton.oauth.OAuthUtils.java

public static void writeAuthorizationInfo(Path file, AuthorizationData data) throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(file));
    oos.writeObject(data);//  w ww  . ja v a  2  s. c  o  m
    oos.close();
}

From source file:Util.java

/**
  * Serializes an object to a file, masking out annoying exceptions.
  *  Any IO exceptions are caught, and printed to standard error.
  *  Consider using {@link #writeGzippedObject(java.io.File, java.io.Serializable)}
  *  instead, for that method will compress the serialized file, and it'll still
  * be reaoable by {@link #readObject}.//from w  w  w  . ja v a  2s  . c  om
  * @param f File to write to
  * @param obj Object to serialize
  * @see #writeGzippedObject(java.io.File, java.io.Serializable)
  */
public static void writeObject(File f, Serializable obj) {
    try {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
        oos.writeObject(obj);
        oos.close();
    } catch (IOException e) {
        System.err.println("Exception writing file " + f + ": " + e);
    }
}

From source file:Main.java

public static void saveObj(String fileName, Object obj) {

    try {// www  .  ja  v a 2s  . c  o m
        FileOutputStream fout = new FileOutputStream(fileName);
        ObjectOutputStream oout = new ObjectOutputStream(fout);
        oout.writeObject(obj);
        fout.close();
        oout.close();
    } catch (Exception e) {
        printE("OpusTool", e);
    }
}

From source file:IO.serializer.java

public static void Serialize(Object object, String destinationFilename) {
    String serializedFilename = String.format("%s\\%s.%s", m_systemTempDirectory, destinationFilename,
            m_serializedFileExtension);//from   ww  w.j  a va  2s.co  m

    try (FileOutputStream fos = new FileOutputStream(serializedFilename)) {
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(object);
        oos.close();
    } catch (IOException ex) {
        Console.PrintLine(
                String.format("Error serilizing object '%s': %s", destinationFilename, ex.getMessage()), true,
                false);
    }
}

From source file:Main.java

public static String objectToString(Serializable serializableObject) throws Exception {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(serializableObject);
    objectOutputStream.close();
    return new String(Base64.encode(byteArrayOutputStream.toByteArray(), 0));
}

From source file:Main.java

public static void saveObj(Object obj, String fileName) throws IOException {
    File f = new File(fileName + ".tmp");
    f.getParentFile().mkdirs();//from w  w w.j  av a 2  s  .  c o m
    FileOutputStream fos = new FileOutputStream(f);
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeObject(obj);
    out.flush();
    out.close();
    fos.flush();
    fos.close();
    File file = new File(fileName);
    file.delete();
    f.renameTo(file);
}

From source file:Main.java

public static byte[] serialize(Object obj) throws Exception {
    //System.err.println(" ser ##"+obj);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream oout = new ObjectOutputStream(bout);
    oout.writeObject(obj);/*from w w  w  . jav  a  2  s.  co m*/
    oout.flush();
    byte array[] = bout.toByteArray();
    oout.close();
    bout.close();
    //System.err.println(" ser #"+new String(array));
    return array;
}

From source file:Main.java

public static byte[] serialize(Object o) throws ObjectStreamException {
    ByteArrayOutputStream array = new ByteArrayOutputStream();
    ObjectOutputStream out = null;
    try {//from   w  w w  .  j  av a  2  s .c o m
        out = new ObjectOutputStream(array);
        out.writeObject(o);
        out.close();
    } catch (ObjectStreamException e) {
        throw e;
    } catch (IOException e) {
        // no handle
    }
    return array.toByteArray();
}