List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void sizeExternalizeSeveralWithType(String type, Externalizable[] objects) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w w w. j ava2 s . c o m*/ ObjectOutputStream out = new ObjectOutputStream(baos); for (Externalizable object : objects) { Message msg = new MessageImpl(type, object, null); out.writeObject(msg); } out.close(); } catch (IOException ex) { ex.printStackTrace(); } int size = baos.size(); int sizePerMessage = size / objects.length; System.out.println(" Size indicating types " + objects.length + " messages - RMI: " + size + " bytes (" + sizePerMessage + " bytes/msg)"); }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void externalizeSeveralObjects(Externalizable[] objects, ByteArrayOutputStream baos) { long start = 0, end = 0; try {/*from w w w.j a v a2 s . c o m*/ ObjectOutputStream out = new ObjectOutputStream(baos); //Measure the elapsed time start = System.nanoTime(); for (Externalizable object : objects) { out.writeObject(object); } end = System.nanoTime(); out.close(); } catch (IOException ex) { ex.printStackTrace(); } long elapsed = (end - start); long elapsedPerMessage = elapsed / objects.length; System.out.println(" Elapsed Time " + objects.length + " messages - Externalize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void sizeSeveralJSONWithoutTypes(JSONizable[] objects) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream stream; try {/*from ww w . j av a 2s .c om*/ stream = new ObjectOutputStream(baos); for (JSONizable object : objects) { String json = object.toJSONString(); stream.writeObject(json); } } catch (Exception ex) { ex.printStackTrace(); } int size = baos.size(); int sizePerMessage = size / objects.length; System.out.println(" Size no indicating type " + objects.length + " messages - JSON: " + size + " bytes (" + sizePerMessage + " bytes/msg)"); }
From source file:com.navercorp.pinpoint.web.filter.Base64.java
public static String encodeObject(Serializable serializableObject, int options) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream b64os = null;//from w ww . java2 s .com ObjectOutputStream oos = null; String var6; try { b64os = new Base64.Base64OutputStream(baos, 1 | options); oos = (options & 2) == 2 ? new ObjectOutputStream(new GZIPOutputStream(b64os)) : new ObjectOutputStream(b64os); oos.writeObject(serializableObject); String var5 = new String(baos.toByteArray(), "UTF-8"); return var5; } catch (UnsupportedEncodingException var28) { var6 = new String(baos.toByteArray()); return var6; } catch (IOException var29) { LOG.error("error encoding object", var29); var6 = null; } finally { if (oos != null) { try { oos.close(); } catch (Exception var27) { LOG.error("error closing ObjectOutputStream", var27); } } if (b64os != null) { try { b64os.close(); } catch (Exception var26) { LOG.error("error closing Base64OutputStream", var26); } } try { baos.close(); } catch (Exception var25) { LOG.error("error closing ByteArrayOutputStream", var25); } } return var6; }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void jSONizeObjects(JSONizable[] objects, ByteArrayOutputStream baos) { long start = 0, end = 0; try {//from w w w . j a v a 2 s . c o m ObjectOutputStream stream = new ObjectOutputStream(baos); start = System.nanoTime(); for (JSONizable object : objects) { String json = object.toJSONString(); stream.writeObject(json); } end = System.nanoTime(); } catch (Exception ex) { ex.printStackTrace(); } long elapsed = end - start; long elapsedPerMessage = elapsed / objects.length; System.out.println(" Elapsed Time " + objects.length + " messages - JSONize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:edu.iu.daal_nn.NNDaalCollectiveMapper.java
private static ByteArray serializeNumericTable(NumericTable dataTable) throws IOException { /* Create an output stream to serialize the numeric table */ ByteArrayOutputStream outputByteStream = new ByteArrayOutputStream(); ObjectOutputStream outputStream = new ObjectOutputStream(outputByteStream); /* Serialize the numeric table into the output stream */ dataTable.pack();/*from w w w . j av a 2s.co m*/ outputStream.writeObject(dataTable); /* Store the serialized data in an array */ byte[] buffer = outputByteStream.toByteArray(); ByteArray numericTableHarp = new ByteArray(buffer, 0, buffer.length); return numericTableHarp; }
From source file:com.likya.myra.jef.utils.JobQueueOperations.java
public static boolean persistDisabledJobQueue(ConfigurationManager configurationManager, HashMap<String, String> jobQueue) { FileOutputStream fos = null;/*from w w w. j a v a 2 s .c o m*/ ObjectOutputStream out = null; if (jobQueue.size() == 0) { return true; } try { File fileTemp = new File(configurationManager.getFileToPersist() + "_disabled.temp"); //$NON-NLS-1$ fos = new FileOutputStream(fileTemp); out = new ObjectOutputStream(fos); out.writeObject(jobQueue); out.close(); File file = new File(configurationManager.getFileToPersist() + "_disabled"); if (file.exists()) { file.delete(); } fileTemp.renameTo(file); } catch (IOException ex) { ex.printStackTrace(); } return true; }
From source file:jade.mtp.http.XMLCodec.java
/** * A user-defined property (String name, Object value) is encoded the following way: * <user-defined href="name" type="type">value</user-defined> * /* www . j ava 2 s .co m*/ */ private static void encodeProp(StringBuffer sb, Property p) { String v = null; Object o = p.getValue(); String type = PROP_STRING_TYPE; if (o instanceof String) { v = (String) o; } else if (o instanceof byte[]) { type = PROP_BYTE_TYPE; try { v = new String(Base64.encodeBase64((byte[]) o), "US-ASCII"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else if (o instanceof Serializable) { type = PROP_SER_TYPE; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(o); oos.close(); byte[] bytes = bos.toByteArray(); if (bytes != null) v = new String(Base64.encodeBase64(bytes), "US-ASCII"); } catch (IOException ioe) { return; } } else { return; } sb.append(OT).append(PROP_TAG).append(" "); sb.append(PROP_ATTR).append("=\"").append(p.getName()).append("\" "); sb.append(PROP_ATTR_TYPE).append("=\"").append(type).append("\""); sb.append(CT); sb.append(v); sb.append(ET).append(PROP_TAG).append(CT); }
From source file:SystemUtils.java
public static void StoreObject(Object target, String filePath) throws IOException { FileOutputStream fos = null;/*from ww w . j a v a 2 s. c om*/ ObjectOutputStream oos = null; try { fos = new FileOutputStream(filePath); oos = new ObjectOutputStream(fos); oos.writeObject(target); } finally { if (oos != null) { try { oos.close(); } catch (Exception e) { } oos = null; } if (fos != null) { try { fos.close(); } catch (Exception e) { } fos = null; } } }
From source file:gov.nasa.ensemble.common.CommonUtils.java
/** * Serializes an object and return the byte array. * /*w ww . j av a 2 s. c o m*/ * @param o * @return a byte[] containing the object or null if exceptions are encountered */ public static byte[] serializeObject(Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos; try { oos = new ObjectOutputStream(baos); oos.writeObject(o); } catch (IOException e) { trace.error(e, e); return null; } return baos.toByteArray(); }