Example usage for java.io ObjectOutputStream flush

List of usage examples for java.io ObjectOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java

/**
 * Set disk cache path to store downloaded rss images
 * @param cachePath - disk cache path//from  www .  ja  v a 2 s  .  c o  m
 */
public void setCachePath(String cachePath) {
    this.cachePath = cachePath;
    try {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cachePath + "/cache.data"));
        oos.writeObject(items);
        oos.flush();
        oos.close();
    } catch (Exception e) {
    }
}

From source file:com.asual.summer.sample.domain.Technology.java

public void setImage(Image image) {
    if (image != null) {
        File file = new File(new File(System.getProperty("java.io.tmpdir")), value);
        try {/*ww  w. j a va2 s.  c o m*/
            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(image);
            oos.flush();
            fos.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    } else if (value != null) {
        image = findImage(value);
    }
    this.image = image;
}

From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java

private void downloadRegistration(int position, String value) {
    this.items.get(position).setImagePath(value);
    try {/*  w ww .  j  a  va  2  s.  c o m*/
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cachePath + "/cache.data"));
        oos.writeObject(items);
        oos.flush();
        oos.close();
        Log.d("IMAGES PLUGIN CACHE DATA", "SUCCESS");
    } catch (Exception e) {
        Log.w("IMAGES PLUGIN CACHE DATA", e);
    }
}

From source file:com.tecapro.inventory.common.util.CommonUtil.java

/**
 * encodeBase64 object/*from w  ww  .  j  a v a2s . c  o  m*/
 *
 * @param obj
 * @return
 * @throws Exception
 */
public byte[] serialize(Object obj) throws Exception {
    ByteArrayOutputStream byteStream = null;
    ObjectOutputStream ostream = null;
    byte[] result = null;

    try {
        byteStream = new ByteArrayOutputStream();
        ostream = new ObjectOutputStream(new BufferedOutputStream(byteStream));
        ostream.writeObject(obj);
        ostream.flush();
        result = Base64.encodeBase64(byteStream.toByteArray());
    } finally {
        if (byteStream != null) {
            byteStream.close();
        }
        if (ostream != null) {
            ostream.close();
        }
    }
    return result;
}

From source file:com.hs.mail.imap.processor.fetch.BodyStructureBuilder.java

public void writeBodyStructure(File file, MimeDescriptor descriptor) {
    if (descriptor != null) {
        ObjectOutputStream os = null;
        try {/*from  w  ww  . j a va  2s.c  o  m*/
            OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
            os = new ObjectOutputStream(out);
            os.writeObject(descriptor);
            os.flush();
        } catch (Exception e) {
            //
        } finally {
            IOUtils.closeQuietly(os);
        }
    }
}

From source file:org.apache.jcs.auxiliary.lateral.http.broadcast.LateralCacheThread.java

/** Description of the Method */
public void writeObj(URLConnection connection, ICacheElement cb) {
    try {//from  ww  w.  ja v  a  2  s  . co m
        connection.setUseCaches(false);
        connection.setRequestProperty("CONTENT_TYPE", "application/octet-stream");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        ObjectOutputStream os = new ObjectOutputStream(connection.getOutputStream());
        log.debug("os = " + os);

        // Write the ICacheItem to the ObjectOutputStream
        log.debug("Writing  ICacheItem.");

        os.writeObject(cb);
        os.flush();

        log.debug("closing output stream");

        os.close();
    } catch (IOException e) {
        log.error(e);
    }
    // end catch
}

From source file:com.ibm.sbt.test.lib.MockSerializer.java

private String serialize(Object o) throws IOException {
    if (o instanceof EofSensorInputStream)
        return serialize((EofSensorInputStream) o);
    if (o instanceof Node)
        return serialize((Node) o);
    if (o instanceof Header[])
        return serialize((Header[]) o);
    ByteArrayOutputStream w = new ByteArrayOutputStream();
    Base64OutputStream base64OutputStream = new Base64OutputStream(w);
    ObjectOutputStream os = new ObjectOutputStream(base64OutputStream);
    os.writeObject(o);//from www  .  java2  s .c om
    os.flush();
    os.close();
    base64OutputStream.flush();
    base64OutputStream.close();
    return w.toString("UTF-8");
}

From source file:it.unimi.di.big.mg4j.document.SimpleCompressedDocumentCollectionBuilder.java

public void nonTextField(Object o) throws IOException {
    final ObjectOutputStream oos = new ObjectOutputStream(nonTextZipDataOutputStream);
    oos.writeObject(o);/*from w w  w .  ja v a2  s .  c  o m*/
    oos.flush();
}

From source file:org.bremersee.common.jms.DefaultJmsConverter.java

private Message createSerializedMessage(Serializable object, Session session) throws JMSException {
    try {/*from   www.  ja v  a2s.  co m*/
        BytesMessage msg = session.createBytesMessage();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(object);
        objectOutputStream.flush();
        msg.writeBytes(outputStream.toByteArray());
        msg.setJMSType(object.getClass().getName());
        return msg;

    } catch (Throwable t) { // NOSONAR
        log.info("Creating Serialized JMS from object of type ["
                + (object == null ? "null" : object.getClass().getName()) + "] failed.");
        return null;
    }
}

From source file:org.springframework.session.data.mongo.JdkMongoSessionConverter.java

private byte[] serializeAttributes(Session session) {
    try {//from  w  ww. j  a v  a 2s  .co m
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(out);
        Map<String, Object> attributes = new HashMap<String, Object>();
        for (String attrName : session.getAttributeNames()) {
            attributes.put(attrName, session.getAttribute(attrName));
        }
        outputStream.writeObject(attributes);
        outputStream.flush();
        return out.toByteArray();
    } catch (IOException e) {
        LOG.error("Exception during session serialization", e);
        throw new IllegalStateException("Cannot serialize session", e);
    }
}