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:com.manning.blogapps.chapter11.rome.DiskFeedInfoCache.java

public void setFeedInfo(URL url, SyndFeedInfo feedInfo) {

    String fileName = cachePath + File.separator + "feed_" + url.hashCode();
    FileOutputStream fos;/*from www.  j ava2  s.  c  om*/
    try {
        fos = new FileOutputStream(fileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(feedInfo);
        fos.flush();
        fos.close();
    } catch (Exception e) {
        // Error writing to cahce is fatal
        throw new RuntimeException("Attempting to write to cache", e);
    }
}

From source file:MSUmpire.SpectrumParser.DIA_Setting.java

public void WriteDIASettingSerialization(String mzXMLFileName) {
    try {/*w w  w. j  a v  a2  s.  c o m*/
        Logger.getRootLogger().info("Writing DIA setting to file:" + FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.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:com.conwet.silbops.model.JSONvsRMIPerfT.java

@SuppressWarnings("unchecked")
public static void sizeSeveralJSONWithTypes(JSONizable[] objects, String feature, String type) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream stream;
    FeatureMap featureMap = mock(FeatureMap.class);
    when(featureMap.getPrefix(feature)).thenReturn("ps");

    try {//from w w  w  .  java  2  s  .  c om
        stream = new ObjectOutputStream(baos);

        for (JSONizable object : objects) {

            JSONObject payLoad = new JSONObject();
            payLoad.put(type, object.toJSON());

            ImmutableMessage msg = new ImmutableMessage(feature, type, payLoad, "0");
            String codedMsg = msg.toJSONObject(featureMap).toJSONString();

            stream.writeObject(codedMsg);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    int size = baos.size();
    int sizePerMessage = size / objects.length;
    System.out.println("   Size indicating type " + objects.length + " messages - JSON: " + size + " bytes ("
            + sizePerMessage + " bytes/msg)");
}

From source file:com.g3net.tool.ObjectUtils.java

/**
 * //from   w  w  w  .j  a  v a 2s  .c om
 * @param o   ???java??,???
 * @return     
 * @throws Exception
 */
public static byte[] serializeObject(Object o) throws Exception {
    ByteArrayOutputStream bos = null;
    ObjectOutputStream oos = null;
    if (o == null) {
        return null;
    }

    try {
        bos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(bos);
        oos.writeObject(o);
        oos.flush();
        return bos.toByteArray();
    } finally {
        if (oos != null) {
            oos.close();
        }
    }
}

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

/**
 * Criar um arquivo temporario/*from   w  w w.  j  a va 2  s .  c om*/
 * @param gumgaFile
 * @return dados do arquivo
 */
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();
        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.btoddb.trellis.common.serialization.JavaSerializer.java

private void serializeToOutputStream(Serializable obj, OutputStream os) {
    try {/*from w  ww  .j ava 2s.  com*/
        ObjectOutputStream oos = new ObjectOutputStream(os);
        oos.writeObject(obj);
        oos.close();
    } catch (IOException e) {
        throw new TrellisException("exception while serializing Java Serializable object", e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.weka.util.WekaUtils.java

/**
 * Writes a file with all necessary information for evaluation.
 *
 * @param result the result file// w w  w  . j av  a  2 s . c o m
 * @param file the file to write to
 * @throws IOException i/o error
 * @throws FileNotFoundException file not found
 */
public static void writeMlResultToFile(MultilabelResult result, File file)
        throws FileNotFoundException, IOException {
    //file.mkdirs();
    //file.createNewFile();
    ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(file));
    stream.writeObject(result);
    stream.close();
}

From source file:com.vnomicscorp.spring.security.cas.authentication.redis.DefaultCasAuthenticationTokenSerializer.java

@Override
public String serialize(CasAuthenticationToken token) throws CasAuthenticationTokenSerializerException {
    if (token == null) {
        throw new NullPointerException("Expected given token to be non-null");
    }/*from w  w  w.  jav a  2  s  .  c o  m*/
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(token);
        oos.flush();
        return new String(Base64.encode(baos.toByteArray()), charset);
    } catch (IOException e) {
        throw new CasAuthenticationTokenSerializerException(e);
    }
}

From source file:bancvirt.Recurso.java

public Boolean commit(Long tId) {
    FileOutputStream fout = null;
    try {//from ww  w  .  jav a 2  s.c  o  m
        fout = new FileOutputStream(getResourceId());
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(this);
        oos.close();
        fout.close();
        return true;
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        return false;
    } catch (IOException ex) {
        ex.printStackTrace();
        return false;
    } finally {
        try {
            fout.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        }
    }
}

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);
    return bos.toByteArray();
}