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:com.amazonaws.hbase.kinesis.BatchedStreamSource.java

private byte[] bufferToBytes() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(buffer);/*from   w  w  w .ja v  a  2s.  c  o  m*/
    return bos.toByteArray();
}

From source file:com.actelion.research.mapReduceExecSpark.executors.MapReduceExecutorSparkProxy.java

public Map<K, V> execute(final Collection<T> elements, final IMapReduce<T, K, V> mapReduce) {
    String serUUID = UUID.randomUUID().toString();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte[] bytes = null;
    try {/*w  w w. j a  v a2  s.c o  m*/
        ObjectOutputStream oos = new ObjectOutputStream(outputStream);
        oos.writeObject(mapReduce);
        oos.writeObject(elements);
        outputStream.flush();
        bytes = outputStream.toByteArray();
        System.out.println("serialization done");
    } catch (IOException e) {
        e.printStackTrace();
    }

    writeToSMB(serUUID, bytes);

    System.out.println("executing task on cluster");
    try {
        deployTask(serUUID, elements.size(), resultDir);
        System.out.println("task deployment successfull");
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:net.sf.dynamicreports.googlecharts.test.AbstractJasperTest.java

private JasperReportBuilder serializableTest(JasperReportBuilder report)
        throws IOException, ClassNotFoundException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(report);//w ww. j av a2 s  .co m
    oos.flush();
    oos.close();

    InputStream stream = new ByteArrayInputStream(bos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(stream);
    return (JasperReportBuilder) ois.readObject();
}

From source file:com.edsoft.teknosaproject.bean.TreeNodeBean.java

public void saveFile() {
    Path path = Paths.get("E:", "TREE", "hiyerari.txt");
    //Path path = Paths.get("E:", "Hiyerari", "hiyerari.txt");
    OutputStream stream;/*w  w  w  . j av a2s . c o m*/
    ObjectOutput object;
    try {
        stream = new FileOutputStream(path.toFile());
        object = new ObjectOutputStream(stream);
        object.writeObject(root);
        object.flush();
        object.close();
        stream.close();
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "TAMMA", "Baarl"));
    } catch (IOException ex) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "HATA", "Kayt srasnda hata oldu"));
    }
}

From source file:com.l2jfree.gameserver.scripting.CompiledScriptCache.java

public void save() throws IOException {
    synchronized (_compiledScriptCache) {
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream(new File(L2ScriptEngineManager.SCRIPT_FOLDER, "CompiledScripts.cache")));
        oos.writeObject(this);
        _modified = false;/*from  w  ww.j a v a2  s . c  o m*/
    }
}

From source file:com.github.stephanarts.cas.ticket.registry.RegistryClient.java

/**
 * addTicket Method.//from  ww w  .  j av  a2  s  .co  m
 *
 * @param ticket CAS Ticket object
 *
 * @throws JSONRPCException Throws JSONRPCException containing any error.
 */
public final void addTicket(final Ticket ticket) throws JSONRPCException {

    byte[] serializedTicket = {};
    JSONObject params = new JSONObject();

    /* Check if it's not null */
    if (ticket == null) {
        throw new JSONRPCException(-32501, "Could not encode Ticket");
    }

    try {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream so = new ObjectOutputStream(bo);
        so.writeObject(ticket);
        so.flush();
        serializedTicket = bo.toByteArray();
    } catch (final Exception e) {
        throw new JSONRPCException(-32501, "Could not encode Ticket");
    }

    params.put("ticket-id", ticket.getId());
    params.put("ticket", DatatypeConverter.printBase64Binary(serializedTicket));

    this.call("cas.addTicket", params);
}

From source file:com.thoughtworks.go.server.service.builders.KillAllChildProcessTaskBuilderTest.java

@Test
public void builderReturnedByThisTaskBuilderShouldBeSerializable() throws Exception {
    KillAllChildProcessTaskBuilder killAllChildProcessTaskBuilder = new KillAllChildProcessTaskBuilder();
    Builder builder = killAllChildProcessTaskBuilder.createBuilder(null, null, null, null);
    new ObjectOutputStream(new NullOutputStream()).writeObject(builder);
}

From source file:com.artistech.tuio.dispatch.TuioSink.java

private void broadcast(Object obj) {
    String type = obj.getClass().getSimpleName();
    switch (serialization) {
    case PROTOBUF: {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            boolean success = false;
            for (ProtoConverter service : services) {
                if (service.supportsConversion(obj)) {
                    service.convertToProtobuf(obj).build().writeTo(baos);
                    baos.flush();//from ww  w.  j  a v  a2s .  c  o  m
                    success = true;
                    break;
                }
            }
            if (success) {
                mailbox.addMessage(new ImmutablePair<>(type, baos.toByteArray()));
            }
        } catch (IOException ex) {
            Logger.getLogger(TuioSink.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
        break;
    case JSON:
        try {
            mailbox.addMessage(new ImmutablePair<>(type, mapper.writeValueAsString(obj).getBytes()));
        } catch (JsonProcessingException ex) {
            Logger.getLogger(TuioSink.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;
    case OBJECT:
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutput out = new ObjectOutputStream(bos)) {
            out.writeObject(obj);
            mailbox.addMessage(new ImmutablePair<>(type, bos.toByteArray()));
        } catch (java.io.IOException ex) {
            logger.error(null, ex);
        }
        break;
    }
}

From source file:com.servoy.extensions.plugins.http.AllowedCertTrustStrategy.java

public void add(X509Certificate[] certificates) {
    getCertificatesHolder();//  w w w. j  a v  a2 s .co  m
    holder.add(certificates);
    File file = new File(System.getProperty("user.home"), J2DBGlobals.CLIENT_LOCAL_DIR + "servoy.ks"); //$NON-NLS-1$//$NON-NLS-2$
    if (!file.getParentFile().exists())
        file.getParentFile().mkdirs();
    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
        oos.writeObject(holder);
    } catch (Exception e) {
        Debug.error(e);
    } finally {
        try {
            if (oos != null)
                oos.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.gamesalutes.utils.ByteUtils.java

/**
 * Returns a <code>byte[]</code> containing the byte representation
 * of the serializable object <code>obj</code>.
 * /*from   w  w w .  jav  a  2s.com*/
 * @param obj the <code>Object</code> to convert to a byte array
 * @return <code>byte[]</code> containing the byte representation
 * of <code>obj</code>.
 * 
 * @throws IOException if <code>obj</code> is not serializable or error occurs while writing the bytes
 */
public static byte[] getObjectBytes(Object obj) throws IOException {
    ByteArrayOutputStream bout = null;
    ObjectOutputStream out = null;
    byte[] data = null;
    try {
        bout = new ByteArrayOutputStream(READ_BUFFER_SIZE);
        out = new ObjectOutputStream(bout);
        out.writeObject(obj);
        out.flush();

        data = bout.toByteArray();
    } finally {
        MiscUtils.closeStream(out);
    } //end finally

    return data;
}