List of usage examples for java.io ObjectOutput writeObject
public void writeObject(Object obj) throws IOException;
From source file:com.microsoft.applicationinsights.internal.channel.common.TransmissionFileSystemOutput.java
private boolean saveTransmission(File transmissionFile, Transmission transmission) { try {/*from w ww.j av a 2 s . co m*/ OutputStream fileOutput = new FileOutputStream(transmissionFile); OutputStream buffer = new BufferedOutputStream(fileOutput); ObjectOutput output = new ObjectOutputStream(buffer); try { output.writeObject(transmission); } catch (IOException e) { InternalLogger.INSTANCE.error("Failed to save transmission, exception: %s", e.getMessage()); } finally { try { output.close(); } catch (Exception e) { return false; } } return true; } catch (IOException e) { InternalLogger.INSTANCE.error("Failed to save transmission, exception: %s", e.getMessage()); } return false; }
From source file:org.jfree.data.category.junit.DefaultCategoryDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from ww w. ja v a2 s. c o m*/ public void testSerialization() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.setValue(23.4, "R1", "C1"); DefaultCategoryDataset d2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultCategoryDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:org.jfree.data.xy.junit.DefaultIntervalXYDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from w w w. j a v a2 s. c o m*/ public void testSerialization() { DefaultIntervalXYDataset d1 = new DefaultIntervalXYDataset(); DefaultIntervalXYDataset d2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); // try a dataset with some content... d1 = createSampleDataset1(); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:com.delphix.session.util.AbstractExternalCodec.java
/** * Encode the service exception into the output stream. *//*from ww w . j ava 2 s. co m*/ @Override public void encode(OutputStream out, ServiceException exception) throws IOException { @SuppressWarnings("resource") ObjectOutput oout = new ExternalObjectOutput(out); /* * If the ServiceException is not serializable then we need to convert it to a new service exception * that we can encode. */ if (isThrowableSerializable(exception)) { oout.writeObject(exception); } else { oout.writeObject(new ServiceException(ExceptionUtils.getStackTrace(exception))); } }
From source file:com.github.naoghuman.abclist.model.Link.java
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(this.getId()); out.writeLong(this.getGenerationTime()); out.writeObject(this.getAlias()); // TODO (de-/encrypt for db) out.writeObject(this.getDescription()); // TODO (de-/encrypt for db) out.writeObject(this.getUrl()); // TODO (de-/encrypt for db) out.writeObject(this.getImage()); out.writeBoolean(this.getFavorite()); }
From source file:com.github.naoghuman.abclist.model.Topic.java
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(this.getId()); out.writeLong(this.getParentId()); out.writeLong(this.getGenerationTime()); out.writeObject(this.getDescription()); out.writeObject(this.getTitle()); }
From source file:org.jfree.data.time.junit.DayTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w .j a v a 2s .c o m public void testSerialization() { Day d1 = new Day(15, 4, 2000); Day d2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); d2 = (Day) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:com.facebook.presto.bloomfilter.BloomFilter.java
public Slice serialize() { byte[] bytes = new byte[0]; byte[] bytesPre = new byte[0]; try {/* w w w. ja v a 2 s .c o m*/ ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(buffer); output.writeObject(instance); bytes = buffer.toByteArray(); ByteArrayOutputStream bufferPre = new ByteArrayOutputStream(); ObjectOutput outputPre = new ObjectOutputStream(bufferPre); outputPre.writeObject(instancePreFilter); bytesPre = bufferPre.toByteArray(); } catch (Exception ix) { log.error(ix); } // Create hash byte[] bfHash = Hashing.sha256().hashBytes(bytes).asBytes(); // Compress byte[] compressed; try { compressed = compress(bytes); } catch (IOException ix) { log.error(ix); compressed = new byte[0]; } int size = compressed.length; // Compress byte[] compressedPre; try { compressedPre = compress(bytesPre); } catch (IOException ix) { log.error(ix); compressedPre = new byte[0]; } int sizePre = compressedPre.length; // To slice DynamicSliceOutput output = new DynamicSliceOutput(size); // Write hash output.writeBytes(bfHash); // 32 bytes // Write the length of the bloom filter output.appendInt(size); // Write the length of the pre bloom filter output.appendInt(sizePre); // Params output.appendInt(expectedInsertions); output.appendDouble(falsePositivePercentage); // Write the bloom filter output.appendBytes(compressed); // Write the bloom filter output.appendBytes(compressedPre); return output.slice(); }
From source file:org.drools.core.io.impl.UrlResource.java
public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(this.url); out.writeObject(this.encoding); }
From source file:org.apache.openjpa.datacache.QueryKey.java
public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(_candidateClassName); out.writeBoolean(_subclasses);//from w w w . j a v a2 s . c o m out.writeObject(_accessPathClassNames); out.writeObject(_query); out.writeBoolean(_ignoreChanges); out.writeObject(_params); out.writeLong(_rangeStart); out.writeLong(_rangeEnd); out.writeInt(_timeout); }