Java Code Examples for java.io.ObjectOutput

The following examples show how to use java.io.ObjectOutput. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mph-table   Source File: MMapGOV4Function.java    License: Apache License 2.0 6 votes vote down vote up
public static <T> void writeTo(final GOV4Function<T> gov4Function, final String path) throws NoSuchFieldException,
        IllegalAccessException, IOException {
    final Field dataField = gov4Function.getClass().getDeclaredField("data");
    dataField.setAccessible(true);
    final AbstractBitVector.LongBigListView signaturesData = (AbstractBitVector.LongBigListView) dataField.get(gov4Function);
    final Field bitVectorField = signaturesData.getClass().getDeclaredField("bitVector");
    bitVectorField.setAccessible(true);
    final BitVector bitVector = (BitVector)bitVectorField.get(signaturesData);
    try (final LittleEndianDataOutputStream outputStream = new LittleEndianDataOutputStream(
            new BufferedOutputStream(new FileOutputStream(Files.buildPath(path, "signatures.bin"))))) {
        for (final long value : bitVector.bits()) {
            outputStream.writeLong(value);
        }
    }
    dataField.set(gov4Function, null);
    try (final OutputStream outputStream = new FileOutputStream(Files.buildPath(path, "GOV4Function.bin"));
         final ObjectOutput objectOutput = new ObjectOutputStream(outputStream)) {
        objectOutput.writeObject(gov4Function);
    }
}
 
Example 2
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
    r1.setShapePaint(Color.red);
    r1.setShapeStroke(new BasicStroke(1.23f));
    StackedXYAreaRenderer r2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (StackedXYAreaRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);
}
 
Example 3
Source Project: astor   Source File: VectorTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    Vector v1 = new Vector(1.0, 2.0);
    Vector v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (Vector) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 4
/** {@inheritDoc} */
@Override
public void writeExternal(final ObjectOutput out)
  throws IOException {

  try {
    // save the local attributes
    finalizeStep();
  } catch (DerivativeException e) {
    throw MathRuntimeException.createIOException(e);
  }
  final int dimension = (currentState == null) ? -1 : currentState.length;
  out.writeInt(dimension);
  for (int i = 0; i < dimension; ++i) {
    out.writeDouble(yDotKLast[0][i]);
    out.writeDouble(yDotKLast[1][i]);
    out.writeDouble(yDotKLast[2][i]);
  }

  // save the state of the base class
  super.writeExternal(out);

}
 
Example 5
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    ExtendedCategoryAxis a1 = new ExtendedCategoryAxis("Test");
    a1.setSubLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
            4.0f, Color.blue));
    ExtendedCategoryAxis a2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(a1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        a2 = (ExtendedCategoryAxis) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(a1, a2);
}
 
Example 6
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0, false, true);
    b1.setItemCount(123);
    SimpleHistogramBin b2 = null;        
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(b1);
        out.close();
        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        b2 = (SimpleHistogramBin) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(b1, b2);
}
 
Example 7
Source Project: astor   Source File: XYCoordinateTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYCoordinate v1 = new XYCoordinate(1.0, 2.0);
    XYCoordinate v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (XYCoordinate) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}
 
Example 8
/**
 * Returns an output stream (may put out header information
 * relating to the success of the call).
 * @param success If true, indicates normal return, else indicates
 * exceptional return.
 * @exception StreamCorruptedException If result stream previously
 * acquired
 * @exception IOException For any other problem with I/O.
 */
public ObjectOutput getResultStream(boolean success) throws IOException {
    /* make sure result code only marshaled once. */
    if (resultStarted)
        throw new StreamCorruptedException("result already in progress");
    else
        resultStarted = true;

    // write out return header
    // return header, part 1 (read by Transport)
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeByte(TransportConstants.Return);// transport op
    getOutputStream(true);  // creates a MarshalOutputStream
    // return header, part 2 (read by client-side RemoteCall)
    if (success)            //
        out.writeByte(TransportConstants.NormalReturn);
    else
        out.writeByte(TransportConstants.ExceptionalReturn);
    out.writeID();          // write id for gcAck
    return out;
}
 
Example 9
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator();
    SymbolicXYItemLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        g2 = (SymbolicXYItemLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);
}
 
Example 10
Source Project: astor   Source File: EmptyBlockTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    EmptyBlock b1 = new EmptyBlock(1.0, 2.0);
    EmptyBlock b2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(b1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        b2 = (EmptyBlock) in.readObject();
        in.close();
    }
    catch (Exception e) {
        fail(e.toString());
    }
    assertEquals(b1, b2);
}
 
Example 11
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    BubbleXYItemLabelGenerator g1 = new BubbleXYItemLabelGenerator();
    BubbleXYItemLabelGenerator g2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(g1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        g2 = (BubbleXYItemLabelGenerator) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(g1, g2);

}
 
Example 12
Source Project: directory-ldap-api   Source File: LdifControl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void writeExternal( ObjectOutput out ) throws IOException
{
    out.writeUTF( oid );
    out.writeBoolean( criticality );

    if ( hasValue() )
    {
        out.writeBoolean( true );
        out.writeInt( value.length );

        if ( value.length > 0 )
        {
            out.write( value );
        }
    }
    else
    {
        out.writeBoolean( false );
    }

    out.flush();
}
 
Example 13
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    CategoryPointerAnnotation a1 = new CategoryPointerAnnotation("Label",
            "A", 20.0, Math.PI);
    CategoryPointerAnnotation a2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(a1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
                buffer.toByteArray()));
        a2 = (CategoryPointerAnnotation) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(a1, a2);

}
 
Example 14
Source Project: astor   Source File: DateTickTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    DateTick t1 = new DateTick(new Date(0L), "Label", TextAnchor.CENTER,
            TextAnchor.CENTER, 10.0);
    DateTick t2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(t1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        t2 = (DateTick) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(t1, t2);

}
 
Example 15
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeBoolean(characterDelimiter!=null);
    if (characterDelimiter!=null)
        out.writeUTF(characterDelimiter);
    out.writeBoolean(columnDelimiter!=null);
    if (columnDelimiter!=null)
        out.writeUTF(columnDelimiter);
    writeNullableUTF(out, timeFormat);
    writeNullableUTF(out, dateFormat);
    writeNullableUTF(out,timestampFormat);
    try {
        ArrayUtil.writeIntArray(out, WriteReadUtils.getExecRowTypeFormatIds(execRow));
    } catch (StandardException se) {
        throw new IOException(se);
    }
    out.writeBoolean(columnIndex!=null);
    if (columnIndex!=null)
        ArrayUtil.writeIntArray(out,columnIndex);
}
 
Example 16
Source Project: gemfirexd-oss   Source File: ColumnInfo.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Write this object to a stream of stored objects.
 *
 * @param out write bytes here.
 *
 * @exception IOException		thrown on error
 */
public void writeExternal( ObjectOutput out )
	 throws IOException
{
	FormatableHashtable fh = new FormatableHashtable();
	fh.put("name", name);
	fh.put("dataType", dataType);
	fh.put("defaultValue", defaultValue);
	fh.put("defaultInfo", defaultInfo);
	fh.put("newDefaultUUID", newDefaultUUID);
	fh.put("oldDefaultUUID", oldDefaultUUID );
	fh.putInt("action", action);
	
	if (autoincInc != 0)
	{
		// only write out autoinc values if its an autoinc column.
		fh.putLong("autoincStart", autoincStart);
		fh.putLong("autoincInc", autoincInc);
	}
	out.writeObject(fh);
}
 
Example 17
Source Project: astor   Source File: PieLabelRecordTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    PieLabelRecord p1 = new PieLabelRecord("A", 1.0, 2.0, new TextBox("B"),
            3.0, 4.0, 5.0);
    PieLabelRecord p2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(p1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        p2 = (PieLabelRecord) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    boolean b = p1.equals(p2);
    assertTrue(b);

}
 
Example 18
/** {@inheritDoc} */
@Override
public void writeExternal(final ObjectOutput out)
  throws IOException {

  // save the state of the base class
  writeBaseExternal(out);

  // save the local attributes
  final int n = (currentState == null) ? -1 : currentState.length;
  final int kMax = (yDotK == null) ? -1 : yDotK.length;
  out.writeInt(kMax);
  for (int k = 0; k < kMax; ++k) {
    for (int i = 0; i < n; ++i) {
      out.writeDouble(yDotK[k][i]);
    }
  }

  // we do not save any reference to the equations

}
 
Example 19
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    Stroke stroke1 = new BasicStroke(2.0f);
    XYPolygonAnnotation a1 = new XYPolygonAnnotation(new double[] {1.0,
            2.0, 3.0, 4.0, 5.0, 6.0}, stroke1, Color.red, Color.blue);
    XYPolygonAnnotation a2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(a1);
        out.close();

        ObjectInput in = new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())
        );
        a2 = (XYPolygonAnnotation) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(a1, a2);

}
 
Example 20
Source Project: astor   Source File: OHLCTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    OHLC i1 = new OHLC(2.0, 4.0, 1.0, 3.0);
    OHLC i2 = null;
    
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(i1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        i2 = (OHLC) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(i1, i2);
}
 
Example 21
/** {@inheritDoc} */
@Override
public void writeExternal(final ObjectOutput out)
  throws IOException {

  try {
    // save the local attributes
    finalizeStep();
  } catch (DerivativeException e) {
    throw MathRuntimeException.createIOException(e);
  }
  final int dimension = (currentState == null) ? -1 : currentState.length;
  out.writeInt(dimension);
  for (int i = 0; i < dimension; ++i) {
    out.writeDouble(yDotKLast[0][i]);
    out.writeDouble(yDotKLast[1][i]);
    out.writeDouble(yDotKLast[2][i]);
  }

  // save the state of the base class
  super.writeExternal(out);

}
 
Example 22
Source Project: simple-spring-memcached   Source File: AppUser.java    License: MIT License 5 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(CLASS_VERSION);
    out.writeInt(userId);
    out.writeInt(applicationId);
    out.writeBoolean(enabled);
    out.writeInt(version);
}
 
Example 23
Source Project: jdk8u-dev-jdk   Source File: DataFlavor.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serializes this <code>DataFlavor</code>.
 */

public synchronized void writeExternal(ObjectOutput os) throws IOException {
    if (mimeType != null) {
        mimeType.setParameter("humanPresentableName", humanPresentableName);
        os.writeObject(mimeType);
        mimeType.removeParameter("humanPresentableName");
    } else {
        os.writeObject(null);
    }

    os.writeObject(representationClass);
}
 
Example 24
Source Project: blip   Source File: TIntDoubleHash.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void writeExternal(ObjectOutput out) throws IOException {
    // VERSION
    out.writeByte(0);

    // SUPER
    super.writeExternal(out);

    // NO_ENTRY_KEY
    out.writeInt(no_entry_key);

    // NO_ENTRY_VALUE
    out.writeDouble(no_entry_value);
}
 
Example 25
Source Project: library   Source File: SMMessage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException{
    super.writeExternal(out);
    out.writeInt(sender);
    out.writeInt(cid);
    out.writeInt(type);
    out.writeInt(regency);
    out.writeInt(leader);
    out.writeObject(state);
    out.writeObject(view);
}
 
Example 26
Source Project: reladomo   Source File: FastUnsafeOffHeapDataStorage.java    License: Apache License 2.0 5 votes vote down vote up
private void serializeSyncResultHeader(ObjectOutput out, int pageCountEstimate) throws IOException
{
    //header:
    out.writeLong(this.finder.getMithraObjectPortal().getLatestRefreshTime());
    out.writeLong(getPageSize());
    out.writeInt(pageCountEstimate);
}
 
Example 27
Source Project: gemfirexd-oss   Source File: ByteBufferInputStream.java    License: Apache License 2.0 5 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeBoolean(this.buffer != null);
  if (this.buffer != null) {
    out.writeInt(this.buffer.capacity());
    out.writeInt(this.buffer.limit());
    out.writeInt(this.buffer.position());
    for (int i=0; i < this.buffer.capacity(); i++) {
      out.write(this.buffer.get(i));
    }
  }
}
 
Example 28
Source Project: gemfirexd-oss   Source File: ValueHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeObject(myVersion);
  out.writeObject(myValue);
  out.writeObject(extraObject);
  out.writeObject(modVal);
}
 
Example 29
Source Project: gemfirexd-oss   Source File: SingleHopInformation.java    License: Apache License 2.0 5 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeInt(bucketId.intValue());
  out.writeUTF(primaryBucketServersStr);
  if (this.secondaryBucketServersStr == null) {
    out.writeShort(-1); // for null
  }
  else {
    out.writeShort(this.secondaryBucketServersStr.length);
    for (int i = 0; i < this.secondaryBucketServersStr.length; i++) {
      out.writeUTF(this.secondaryBucketServersStr[i]);
    }
  }
}
 
Example 30
Source Project: netbeans   Source File: DeveloperHtmlBrowserComponent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal (ObjectOutput out)
throws IOException {
    out.writeBoolean (bComp.isStatusLineVisible ());
    out.writeBoolean (bComp.isToolbarVisible ());
    out.writeObject (bComp.getDocumentURL ());
}