Example usage for java.io ObjectOutputStream ObjectOutputStream

List of usage examples for java.io ObjectOutputStream ObjectOutputStream

Introduction

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

Prototype

public ObjectOutputStream(OutputStream out) throws IOException 

Source Link

Document

Creates an ObjectOutputStream that writes to the specified OutputStream.

Usage

From source file:grails.plugin.cache.web.filter.redis.GrailsSerializer.java

public void serialize(Object object, OutputStream outputStream) throws IOException {
    if (!(object instanceof Serializable)) {
        throw new IllegalArgumentException(
                getClass().getSimpleName() + " requires a Serializable payload but received an object of type ["
                        + object.getClass().getName() + "]");
    }//www.jav  a 2 s .  c om

    ObjectOutputStream oos = new ObjectOutputStream(outputStream);
    oos.writeObject(object);
    oos.flush();
}

From source file:net.carinae.dev.async.util.SerializerJavaImpl.java

/**
 * {@inheritDoc}/*from   ww w . ja v a  2s  . c  o  m*/
 */
@Override
public byte[] serializeObject(Object obj) {

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out;
        out = new ObjectOutputStream(bos);
        out.writeObject(obj);
        out.close();

        byte[] buf = bos.toByteArray();
        return buf;
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Could not serialize object " + obj, e);
    }

}

From source file:de.dfki.asr.compass.model.AbstractCompassEntity.java

public AbstractCompassEntity deepCopy() throws IOException, ClassNotFoundException {
    AbstractCompassEntity entity = null;
    forceEagerFetch();// ww w.  j  ava 2 s . c o  m
    // Write the object out to a byte array
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(this);
    out.flush();
    out.close();

    // Make an input stream from the byte array and read
    // a copy of the object back in.
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
    entity = (AbstractCompassEntity) in.readObject();
    entity.clearIdsAfterDeepCopy();
    return entity;
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.meta.AbstractSequenceMetaDataFeatureGenerator.java

public static String encodeToString(Object object) throws TextClassificationException {
    try {//from www  . j  a v a  2 s . c  o m
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);

        objectOutputStream.writeObject(object);
        byteArrayOutputStream.close();

        return Base64.encodeBase64String(byteArrayOutputStream.toByteArray());
    } catch (IOException e) {
        throw new TextClassificationException(e);
    }
}

From source file:gui.CompressDecompress.java

private static byte[] serialize(List<List<BigInteger>> encBuffer) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(b);
    o.writeObject(encBuffer);/*from   www  .j a  v  a2 s.com*/
    return b.toByteArray();
}

From source file:gumga.framework.application.GumgaTempFileService.java

public String create(GumgaFile gumgaFile) {
    String tempFileName = "uploadData" + (System.currentTimeMillis() * 1000 + new Random().nextInt(1000));

    try { //TODO Arrumar o tratamento da Exception
        File folder = new File(gumgaValues.getUploadTempDir());
        folder.mkdirs();/*w  w w  .  j av a  2 s  .  c o m*/
        FileOutputStream fos = new FileOutputStream(gumgaValues.getUploadTempDir() + "/" + tempFileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(gumgaFile);
        oos.close();
        fos.close();
        return tempFileName;
    } catch (Exception ex) {
        log.error("erro ao criar arquivo temporario " + tempFileName, ex);
    }
    return "error";
}

From source file:com.thoughtworks.go.agent.testhelpers.FakeAgentCertificateServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ObjectOutputStream outputStream = null;
    try {//from   w  ww .j a  v  a2 s  .c  o m
        outputStream = new ObjectOutputStream(response.getOutputStream());
        outputStream.writeObject(AgentCertificateMother.agentCertificate());
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:cz.seznam.euphoria.hadoop.SerializableWritableTest.java

@SuppressWarnings("unchecked")
@Test/*from  www . ja  va2 s  .c  om*/
public void testSerialization() throws Exception {
    Configuration conf = new Configuration();
    conf.set("key", "value");

    SerializableWritable<Configuration> sw = new SerializableWritable<>(conf);

    // clone by serialization
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(sw);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);

    sw = (SerializableWritable<Configuration>) ois.readObject();
    Configuration newConf = sw.getWritable();

    assertEquals(conf.get("key"), newConf.get("key"));
}

From source file:com.thoughtworks.go.util.ObjectUtil.java

public static void writeObject(Object o, OutputStream outputStream) throws IOException {
    new ObjectOutputStream(outputStream).writeObject(o);
}

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

private static byte[] objectToByteArray(Object obj) {

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