Example usage for java.io ObjectOutputStream flush

List of usage examples for java.io ObjectOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:Main.java

public static void writeObject(String root, String filename, Object object) {
    File file = new File(root, filename);
    try {//w w w.  j a va 2s.  c o  m
        FileOutputStream fos = new FileOutputStream(file);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(object);
        oos.flush();
        oos.close();
    } catch (Exception e) {
        Log.e(TAG, String.format("Failed to write [%s]", file), e);
    }
}

From source file:Main.java

/**
 * Sends an object through bluetooth./*from   w ww .j a  v  a  2  s  .  c om*/
 */
public static boolean bluetoothWriteObject(Object object, BluetoothSocket socket) {
    try {
        ObjectOutputStream oOS = new ObjectOutputStream(socket.getOutputStream());
        oOS.writeObject(object);
        oOS.flush();
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Util.java

public static byte[] compress(Object data) {
    if (data == null) {
        return null;
    }//from w  w w. jav  a2 s.  c  o m
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gout = new GZIPOutputStream(baos);
        ObjectOutputStream oos = new ObjectOutputStream(gout);
        oos.writeObject(data);
        oos.flush();
        gout.finish();
        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

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.  java  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:com.eviware.loadui.util.serialization.SerializationUtils.java

public static byte[] serialize(Object object) throws IOException {
    if (object == null)
        return null;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(object);/*from  w w w .  j a  va2  s. c  o m*/
    oos.flush();

    return baos.toByteArray();
}

From source file:org.rhq.coregui.server.util.SerialUtility.java

public static int serialSize(Object value) {

    try {/*from   ww  w. j ava2  s.com*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream(50000);
        ObjectOutputStream o = new ObjectOutputStream(baos);
        o.writeObject(value);
        o.flush();
        return baos.size();
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:org.gradle.api.internal.tasks.compile.incremental.DummySerializer.java

public static void writeTargetTo(File outputFile, Object target) {
    try {//from  w w w .  ja v a 2 s .c  o  m
        FileOutputStream out = new FileOutputStream(outputFile);
        ObjectOutputStream objectStr = new ObjectOutputStream(out);
        objectStr.writeObject(target);
        objectStr.flush();
        objectStr.close();
        out.close();
    } catch (IOException e) {
        throw new RuntimeException("Problems writing to the output file " + outputFile, e);
    }
}

From source file:Main.java

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

From source file:Main.java

/**
 * This method serializes an object to an output stream.
 *
 * @param file The output file//w w  w .j a  v a2 s . c  o m
 * @param object The object to be serialized
 * @exception IOException IOError
        
 */
public static void serializeObject(File file, Object object) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    try {
        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos));
        oos.writeObject(object);
        oos.flush();
    } finally {
        fos.close();
    }
}

From source file:Main.java

public static void writeDataFile(String filename, Context context, Object object) {
    File file = new File(context.getDir("data", 0), filename);
    try {/*from  w  w w  .  j a  va 2s .  co  m*/
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file, false));
        outputStream.writeObject(object);
        outputStream.flush();
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}