Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:ByteFIFOTest.java

private void makeSrcData() throws IOException {
    String[] list = { "The first string is right here", "The second string is a bit longer and also right here",
            "The third string", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "The last string in the list" };

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(list);//from   w  w w .  ja v  a 2 s  .com
    oos.flush();
    oos.close();

    srcData = baos.toByteArray();
}

From source file:com.farhad.ngram.lang.detector.profile.LanguageProfile.java

public void saveProfile(String filename, Map ngram_tfidf) {
    ObjectOutputStream out;

    try {//  w  ww  . ja v  a 2s . c  o  m
        out = new ObjectOutputStream(new FileOutputStream(filename));
        out.writeObject(ngram_tfidf);
        out.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(LanguageProfile.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LanguageProfile.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:TcpClient.java

/** Default constructor. */
public TcpServer()
{
    this.payload = new TcpPayload();
    initServerSocket();// w  w w.j a  v  a2s .co  m
    try
    {
        while (true)
        {
            // listen for and accept a client connection to serverSocket
            Socket sock = this.serverSocket.accept();
            OutputStream oStream = sock.getOutputStream();
            ObjectOutputStream ooStream = new ObjectOutputStream(oStream);
            ooStream.writeObject(this.payload);  // send serilized payload
            ooStream.close();
            Thread.sleep(1000);
        }
    }
    catch (SecurityException se)
    {
        System.err.println("Unable to get host address due to security.");
        System.err.println(se.toString());
        System.exit(1);
    }
    catch (IOException ioe)
    {
        System.err.println("Unable to read data from an open socket.");
        System.err.println(ioe.toString());
        System.exit(1);
    }
    catch (InterruptedException ie) { }  // Thread sleep interrupted
    finally
    {
        try
        {
            this.serverSocket.close();
        }
        catch (IOException ioe)
        {
            System.err.println("Unable to close an open socket.");
            System.err.println(ioe.toString());
            System.exit(1);
        }
    }
}

From source file:MSUmpire.BaseDataStructure.InstrumentParameter.java

public void WriteParamSerialization(String mzXMLFileName) {
    try {//from w w w .j  a v a  2  s  . co  m
        Logger.getRootLogger().info("Writing parameter to file:" + FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_params.ser...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_params.ser", false);
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(this);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

From source file:org.nuvola.tvshowtime.ApplicationLauncher.java

private void storeAccessToken() {
    try {/*from w  w w. j  a v a  2 s.c  o m*/
        File storeToken = new File(tvShowTimeConfig.getTokenFile());
        FileOutputStream fileOutputStream = new FileOutputStream(storeToken);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(accessToken);
        objectOutputStream.close();
        fileOutputStream.close();

        LOG.info("AccessToken store successfully inside a file...");
    } catch (Exception e) {
        LOG.error("Unexpected error did arrive when trying to store the AccessToken in a file ");
        LOG.error(e.getMessage());

        System.exit(1);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.UkbDictionaryInventory.java

public UkbDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath)
        throws FileNotFoundException, IOException {
    // Open the serialized version or create it from scratch
    try {/*from  ww w  .  jav  a 2 s  .  co m*/
        // System.out.println("Trying to load dictionary from serializable.");
        ObjectInputStream dictionaryReader = new ObjectInputStream(
                new BZip2CompressorInputStream(new FileInputStream(serializiblePath)));
        dictionary = (UkbDictionary) dictionaryReader.readObject();
        dictionaryReader.close();
        // System.out.println("Loaded dictionary from serializable.");
    } catch (Exception e) {
        // System.out.println("Trying to load dictionary from input.");
        dictionary = new UkbDictionary(inputPath, neededMentionsPath);
        System.out.println("Loaded dictionary from input.");

        ObjectOutputStream dictionaryWriter = new ObjectOutputStream(
                new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath)));
        dictionaryWriter.writeObject(dictionary);
        dictionaryWriter.close();
        // System.out.println("Stored dictionary in serializable.");
    }

}

From source file:de.ingrid.admin.elasticsearch.IndexScheduler.java

private void savePatternFile() {
    deletePatternFile();/*from ww  w  .  j  a  va 2s  . c  o m*/
    LOG.debug("saving pattern to file");
    try {

        final ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(_patternFile));
        writer.writeObject(_pattern);
        writer.close();
    } catch (final Exception e) {
        LOG.error(e);
    }
}

From source file:de.intranda.goobi.plugins.utils.ModsUtils.java

private static void writeFile(File file, Object obj) {
    try {//  w w w . j a va2s . c  o  m
        FileOutputStream fs = new FileOutputStream(file);
        ObjectOutputStream os = new ObjectOutputStream(fs);
        os.writeObject(obj);
        os.close();
    } catch (IOException e) {
        logger.error("Error writing binary file", e);
    }
}

From source file:fi.aalto.seqpig.io.FastqStorer.java

@Override
public void checkSchema(ResourceSchema s) throws IOException {

    allFastqFieldNames = new HashMap<String, Integer>();
    String[] fieldNames = s.fieldNames();

    for (int i = 0; i < fieldNames.length; i++) {
        //System.out.println("field: "+fieldNames[i]);
        allFastqFieldNames.put(fieldNames[i], new Integer(i));
    }/*  w ww.jav a  2s . c  o  m*/

    if (!( /*allFastqFieldNames.containsKey("instrument")
           && allFastqFieldNames.containsKey("run_number")
           && allFastqFieldNames.containsKey("flow_cell_id")
           && allFastqFieldNames.containsKey("lane")
           && allFastqFieldNames.containsKey("tile")
           && allFastqFieldNames.containsKey("xpos")
           && allFastqFieldNames.containsKey("ypos")
           && allFastqFieldNames.containsKey("read")
           && allFastqFieldNames.containsKey("filter")
           && allFastqFieldNames.containsKey("control_number")
           && allFastqFieldNames.containsKey("index_sequence")*/
    allFastqFieldNames.containsKey("sequence") && allFastqFieldNames.containsKey("quality")))
        throw new IOException("Error: Incorrect Fastq tuple-field name or compulsory field missing");

    //BASE64Encoder encode = new BASE64Encoder();
    Base64 codec = new Base64();
    Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass());
    String datastr;
    //p.setProperty("someproperty", "value");

    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
    ObjectOutputStream ostream = new ObjectOutputStream(bstream);
    ostream.writeObject(allFastqFieldNames);
    ostream.close();
    //datastr = encode.encode(bstream.toByteArray());
    datastr = codec.encodeBase64String(bstream.toByteArray());
    p.setProperty("allFastqFieldNames", datastr); //new String(bstream.toByteArray(), "UTF8"));
}

From source file:fi.aalto.seqpig.io.QseqStorer.java

@Override
public void checkSchema(ResourceSchema s) throws IOException {

    allQseqFieldNames = new HashMap<String, Integer>();
    String[] fieldNames = s.fieldNames();

    for (int i = 0; i < fieldNames.length; i++) {
        //System.out.println("field: "+fieldNames[i]);
        allQseqFieldNames.put(fieldNames[i], new Integer(i));
    }/*from   www .java 2s.c om*/

    if (!( /*allQseqFieldNames.containsKey("instrument")
           && allQseqFieldNames.containsKey("run_number")
           && allQseqFieldNames.containsKey("flow_cell_id")
           && allQseqFieldNames.containsKey("lane")
           && allQseqFieldNames.containsKey("tile")
           && allQseqFieldNames.containsKey("xpos")
           && allQseqFieldNames.containsKey("ypos")
           && allQseqFieldNames.containsKey("read")
           && allQseqFieldNames.containsKey("filter")
           && allQseqFieldNames.containsKey("control_number")
           && allQseqFieldNames.containsKey("index_sequence")*/
    allQseqFieldNames.containsKey("sequence") && allQseqFieldNames.containsKey("quality")))
        throw new IOException("Error: Incorrect Qseq tuple-field name or compulsory field missing");

    //BASE64Encoder encode = new BASE64Encoder();
    Base64 codec = new Base64();
    Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass());
    String datastr;
    //p.setProperty("someproperty", "value");

    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
    ObjectOutputStream ostream = new ObjectOutputStream(bstream);
    ostream.writeObject(allQseqFieldNames);
    ostream.close();
    //datastr = encode.encode(bstream.toByteArray());
    datastr = codec.encodeBase64String(bstream.toByteArray());
    p.setProperty("allQseqFieldNames", datastr); //new String(bstream.toByteArray(), "UTF8"));
}