类java.io.ObjectOutput源码实例Demo

下面列出了怎么用java.io.ObjectOutput的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mph-table   文件: MMapGOV4Function.java
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);
    }
}
 
源代码2 项目: astor   文件: StackedXYAreaRendererTests.java
/**
 * 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);
}
 
源代码3 项目: astor   文件: VectorTests.java
/**
 * 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);
}
 
源代码4 项目: astor   文件: DormandPrince853StepInterpolator.java
/** {@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);

}
 
源代码5 项目: astor   文件: ExtendedCategoryAxisTests.java
/**
 * 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);
}
 
源代码6 项目: astor   文件: SimpleHistogramBinTests.java
/**
 * 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);
}
 
源代码7 项目: astor   文件: XYCoordinateTests.java
/**
 * 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);
}
 
源代码8 项目: openjdk-jdk9   文件: StreamRemoteCall.java
/**
 * 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;
}
 
源代码9 项目: astor   文件: SymbolicXYItemLabelGeneratorTests.java
/**
 * 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);
}
 
源代码10 项目: astor   文件: EmptyBlockTests.java
/**
 * 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);
}
 
源代码11 项目: astor   文件: BubbleXYItemLabelGeneratorTests.java
/**
 * 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);

}
 
源代码12 项目: directory-ldap-api   文件: LdifControl.java
/**
 * {@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();
}
 
源代码13 项目: astor   文件: CategoryPointerAnnotationTests.java
/**
 * 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);

}
 
源代码14 项目: astor   文件: DateTickTests.java
/**
 * 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);

}
 
源代码15 项目: spliceengine   文件: AbstractFileFunction.java
@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);
}
 
源代码16 项目: gemfirexd-oss   文件: ColumnInfo.java
/**
 * 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);
}
 
源代码17 项目: astor   文件: PieLabelRecordTests.java
/**
 * 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);

}
 
源代码18 项目: astor   文件: RungeKuttaStepInterpolator.java
/** {@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

}
 
源代码19 项目: astor   文件: XYPolygonAnnotationTests.java
/**
 * 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);

}
 
源代码20 项目: astor   文件: OHLCTests.java
/**
 * 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);
}
 
源代码21 项目: astor   文件: DormandPrince853StepInterpolator.java
/** {@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);

}
 
源代码22 项目: simple-spring-memcached   文件: AppUser.java
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(CLASS_VERSION);
    out.writeInt(userId);
    out.writeInt(applicationId);
    out.writeBoolean(enabled);
    out.writeInt(version);
}
 
源代码23 项目: jdk8u-dev-jdk   文件: DataFlavor.java
/**
 * 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);
}
 
源代码24 项目: blip   文件: TIntDoubleHash.java
/**
 * {@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);
}
 
源代码25 项目: library   文件: SMMessage.java
@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);
}
 
源代码26 项目: reladomo   文件: FastUnsafeOffHeapDataStorage.java
private void serializeSyncResultHeader(ObjectOutput out, int pageCountEstimate) throws IOException
{
    //header:
    out.writeLong(this.finder.getMithraObjectPortal().getLatestRefreshTime());
    out.writeLong(getPageSize());
    out.writeInt(pageCountEstimate);
}
 
源代码27 项目: gemfirexd-oss   文件: ByteBufferInputStream.java
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));
    }
  }
}
 
源代码28 项目: gemfirexd-oss   文件: ValueHolder.java
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeObject(myVersion);
  out.writeObject(myValue);
  out.writeObject(extraObject);
  out.writeObject(modVal);
}
 
源代码29 项目: gemfirexd-oss   文件: SingleHopInformation.java
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]);
    }
  }
}
 
源代码30 项目: netbeans   文件: DeveloperHtmlBrowserComponent.java
@Override
public void writeExternal (ObjectOutput out)
throws IOException {
    out.writeBoolean (bComp.isStatusLineVisible ());
    out.writeBoolean (bComp.isToolbarVisible ());
    out.writeObject (bComp.getDocumentURL ());
}
 
 类所在包
 同包方法