Example usage for java.io ObjectOutputStream writeObject

List of usage examples for java.io ObjectOutputStream writeObject

Introduction

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

Prototype

public final void writeObject(Object obj) throws IOException 

Source Link

Document

Write the specified object to the ObjectOutputStream.

Usage

From source file:slina.mb.controller.ObjectSaverFactory.java

@Ignore
public void createObjects() throws IOException, ClassNotFoundException {

    try {//from  w  ww.  ja  va  2s  .  c  o  m
        OutputStream os = new FileOutputStream("logEvent.ser");

        List<String> stringList = Arrays.asList(samples);
        ArrayList<LogEvent> resultaArray = (ArrayList<LogEvent>) stdLogParser.createLogEvents(1, stringList);
        assertEquals(7, resultaArray.size());

        ObjectOutputStream om = new ObjectOutputStream(os);
        om.writeObject(resultaArray);

        os.flush();
        os.close();
        om.close();

    } catch (FileNotFoundException e) {

        e.printStackTrace();
    }

}

From source file:mitm.application.djigzo.mail.MailContainer.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeLong(serialVersionUID);

    out.writeObject(mail);
}

From source file:com.pingcap.tikv.meta.TiTableInfoTest.java

@Test
public void testSerializable() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    TiTableInfo tableInfo = mapper.readValue(tableJson, TiTableInfo.class);
    ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(byteOutStream);
    oos.writeObject(tableInfo);

    ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteOutStream.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(byteInStream);
    TiTableInfo deserTable = (TiTableInfo) ois.readObject();
    assertEquals(deserTable.toProto(), tableInfo.toProto());
}

From source file:com.twosigma.beaker.cpp.utils.CppKernel.java

public int execute(String mainCell, String type, ArrayList<String> otherCells) {
    String tmpDir = System.getenv("beaker_tmp_dir");

    for (String cell : otherCells) {
        cLoad(tmpDir + "/lib" + cell + ".so");
    }/* w ww  .  j  av a  2s  .  c  om*/

    Object ret = cLoadAndRun(tmpDir + "/lib" + mainCell + ".so", type);

    try {
        FileOutputStream file = new FileOutputStream(tmpDir + "/" + mainCell + ".result");
        BufferedOutputStream buffer = new BufferedOutputStream(file);
        ObjectOutputStream output = new ObjectOutputStream(buffer);
        output.writeObject(ret);
        output.close();
    } catch (IOException ex) {
        logger.warn("Could not load file");
        return 1;
    }

    return 0;
}

From source file:net.sf.ehcache.constructs.asynchronous.ListAppenderCommand.java

private void checkSerializability(Serializable payload) throws IOException {
    ObjectOutputStream oout = new ObjectOutputStream(new ByteArrayOutputStream());
    oout.writeObject(payload);
}

From source file:PersisTest.java

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == clearBtn) {
        // Repaint with an empty display list.
        displayList = new ArrayList();
        repaint();//from   w w w  .  j a  va 2 s.  c om
    } else if (e.getSource() == saveBtn) {
        // Write display list array list to an object output stream.
        try {
            FileOutputStream fos = new FileOutputStream(pathname);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(displayList);
            oos.flush();
            oos.close();
            fos.close();
        } catch (IOException ex) {
            System.err.println("Trouble writing display list array list");
        }
    } else if (e.getSource() == restoreBtn) {
        // Read a new display list array list from an object input stream.
        try {
            FileInputStream fis = new FileInputStream(pathname);
            ObjectInputStream ois = new ObjectInputStream(fis);
            displayList = (ArrayList) (ois.readObject());
            ois.close();
            fis.close();
            repaint();
        } catch (ClassNotFoundException ex) {
            System.err.println("Trouble reading display list array list");
        } catch (IOException ex) {
            System.err.println("Trouble reading display list array list");
        }
    } else if (e.getSource() == quitBtn) {
        System.exit(0);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.annotator.EmbeddingsCachePreprocessor.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    try {//from  ww  w .  j ava  2  s  .c  o m
        Word2VecReader reader = new Word2VecReader(word2VecFile, true);

        String[] tokenArray = new ArrayList<>(tokens).toArray(new String[tokens.size()]);
        System.out.println("Vocabulary size: " + tokenArray.length);
        Embedding[] embeddings = reader.getEmbeddings(tokenArray);

        Map<String, no.uib.cipr.matrix.Vector> cache = new HashMap<>();
        if (tokenArray.length != embeddings.length) {
            throw new IllegalStateException();
        }

        for (int i = 0; i < tokenArray.length; i++) {
            String token = tokenArray[i];
            Embedding embedding = embeddings[i];

            if (embedding != null) {
                cache.put(token, embedding.getVector());
            } else {
                cache.put(token, null);
            }
        }

        FileOutputStream fos = new FileOutputStream(cacheFile);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject(cache);

        IOUtils.closeQuietly(fos);
    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    }
}

From source file:com.servioticy.queueclient.SimpleQueueClient.java

void writeQueue(LinkedList<Object> queue) throws IOException {
    File file = new File(filePath);
    file.delete();//from w w w  .  j  a v a  2s . c om
    file.createNewFile();
    FileOutputStream fileOut = new FileOutputStream(file);
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(queue);
    out.close();
    fileOut.close();
}

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 w  w  . j ava2  s .co m*/
        outputStream = new ObjectOutputStream(response.getOutputStream());
        outputStream.writeObject(AgentCertificateMother.agentCertificate());
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:com.cyberway.issue.crawler.datamodel.CrawlURITest.java

/**
 * Test serialization/deserialization works.
 * /*  w w w .ja v a2  s . c om*/
 * @throws IOException
 * @throws ClassNotFoundException
 */
final public void testSerialization() throws IOException, ClassNotFoundException {
    File serialize = new File(getTmpDir(), this.getClass().getName() + ".serialize");
    try {
        FileOutputStream fos = new FileOutputStream(serialize);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(this.seed);
        oos.reset();
        oos.writeObject(this.seed);
        oos.reset();
        oos.writeObject(this.seed);
        oos.close();
        // Read in the object.
        FileInputStream fis = new FileInputStream(serialize);
        ObjectInputStream ois = new ObjectInputStream(fis);
        CrawlURI deserializedCuri = (CrawlURI) ois.readObject();
        deserializedCuri = (CrawlURI) ois.readObject();
        deserializedCuri = (CrawlURI) ois.readObject();
        assertTrue("Deserialized not equal to original",
                this.seed.toString().equals(deserializedCuri.toString()));
        String host = this.seed.getUURI().getHost();
        assertTrue("Deserialized host not null", host != null && host.length() >= 0);
    } finally {
        serialize.delete();
    }
}