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:org.openhie.openempi.matching.fellegisunter.FellegiSunterConfigurationManager.java

public static void saveParameters(String configDirectory, FellegiSunterParameters params) {
    File filename = getConfigurationFile(configDirectory);
    log.debug("Attempting to save the Fellegi-Sunter configuration file into: " + filename);
    try {/*from ww w  .  ja  v  a 2  s . c o  m*/
        ObjectOutputStream ois = new ObjectOutputStream(
                new BufferedOutputStream(new FileOutputStream(filename)));
        ois.writeObject(params);
        ois.flush();
        ois.close();
    } catch (Exception e) {
        log.error("Failed while saving the Fellegi-Sunter configuration file: " + e.getMessage(), e);
        throw new RuntimeException("Failed while saving the Fellegi-Sunter configuration: " + e.getMessage());
    }
}

From source file:org.globus.workspace.persistence.ErrorUtil.java

public static byte[] toByteArray(Throwable t) throws IOException {

    if (t == null) {
        return null;
    }/* ww w .  j a va  2s  . c  o m*/

    byte[] ret = null;
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oos = null;

    try {
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(t);
        oos.flush();
        baos.flush();
        ret = baos.toByteArray();
    } catch (IOException e) {
        logger.error("", e);
        throw e;
    } finally {
        if (baos != null) {
            baos.close();
        }
        if (oos != null) {
            oos.close();
        }
    }

    return ret;
}

From source file:org.calrissian.mango.io.Serializables.java

public static byte[] serialize(Serializable serializable, boolean compress) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream o;

    if (compress)
        o = new ObjectOutputStream(new GZIPOutputStream(baos));
    else// ww w  .  j  av  a2  s . co  m
        o = new ObjectOutputStream(baos);

    o.writeObject(serializable);
    o.flush();
    o.close();
    return baos.toByteArray();
}

From source file:Main.java

public static String objectSerializableToString(Serializable object) {
    ByteArrayOutputStream baos = null;
    ObjectOutputStream os = null;
    try {/*from   w w  w.  j av  a 2s .  com*/
        if (object != null) {
            baos = new ByteArrayOutputStream();
            os = new ObjectOutputStream(baos);
            os.writeObject(object);
            os.flush();
            baos.flush();
            return baos.toString("UTF-8");
        }
    } catch (Throwable e) {
    } finally {
        try {
            if (os != null) {
                os.close();
            }
        } catch (Throwable e2) {
        }

        try {
            if (baos != null) {
                baos.close();
            }
        } catch (Throwable e2) {
        }
    }
    return null;
}

From source file:com.talis.storage.s3.cache.RedisChunkHandler.java

public static byte[] serialize(S3Object chunk) throws IOException {
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    ObjectOutputStream objStream = new ObjectOutputStream(byteStream);
    objStream.writeObject(chunk);//from  w  w  w  .j av a2 s .  c  o m
    objStream.flush();
    objStream.close();
    return byteStream.toByteArray();
}

From source file:com.oprisnik.semdroid.utils.FileUtils.java

public static void writeObjectToStream(Object object, OutputStream output) throws IOException {
    ObjectOutputStream out = null;
    try {//from   w ww .  j  av a 2  s.  c  om
        out = new ObjectOutputStream(new BufferedOutputStream(output));
        out.writeObject(object);
        out.flush();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.ikon.util.Serializer.java

/**
 * @param obj//from   w ww  .j a v  a  2s  .c o  m
 */
public static byte[] write(Object obj) throws IOException {
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oos = null;

    try {
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(obj);
        oos.flush();
        baos.flush();
        return baos.toByteArray();
    } finally {
        IOUtils.closeQuietly(oos);
        IOUtils.closeQuietly(baos);
    }
}

From source file:org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil.java

public static byte[] getBytes(Object obj) throws java.io.IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(obj);/*from  w  w w  .  j a  v a2  s  .  c  o m*/
    oos.flush();
    oos.close();
    bos.close();
    byte[] data = bos.toByteArray();
    return data;
}

From source file:Main.java

public static Object clone(Object object) throws Exception {
    Object copy = null;//from w w  w  .  j a  v a  2s  .c  om

    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(bos);
        oos.writeObject(object);
        oos.flush();

        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        ois = new ObjectInputStream(bin);
        copy = ois.readObject();
    } finally {
        if (ois != null)
            ois.close();
        if (oos != null)
            oos.close();
    }
    return copy;
}

From source file:org.openspotlight.common.util.Serialization.java

/**
 * Serialize the object on a output stream passed as parameter.
 * //w  w  w  .j ava2s  .c  o m
 * @param <E>
 * @param object
 * @param outputStream
 * @throws SLException
 */
public static <E extends Serializable> void serializeToOutputStream(final E object,
        final OutputStream outputStream) throws SLException {
    checkNotNull("object", object);//$NON-NLS-1$
    checkNotNull("outputStream", outputStream);//$NON-NLS-1$
    try {
        final ObjectOutputStream oos = new ObjectOutputStream(outputStream);
        oos.writeObject(object);
        oos.flush();
        oos.close();
    } catch (final Exception e) {
        logAndThrowNew(e, SLException.class);
    }
}