下面列出了java.io.ObjectOutput#writeObject ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
MonthDateFormat mf1 = new MonthDateFormat();
MonthDateFormat mf2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(mf1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray())
);
mf2 = (MonthDateFormat) in.readObject();
in.close();
}
catch (Exception e) {
fail(e.toString());
}
assertTrue(mf1.equals(mf2));
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0);
PowerFunction2D f2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(f1);
out.close();
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
buffer.toByteArray()));
f2 = (PowerFunction2D) in.readObject();
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertEquals(f1, f2);
}
/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
out.writeBoolean(restEnabled);
out.writeBoolean(tcpSslEnabled);
U.writeString(out, jettyPath);
U.writeString(out, jettyHost);
out.writeObject(jettyPort);
U.writeString(out, tcpHost);
out.writeInt(tcpPort);
U.writeString(out, tcpSslCtxFactory);
U.writeString(out, secretKey);
out.writeBoolean(noDelay);
out.writeBoolean(directBuf);
out.writeInt(sndBufSize);
out.writeInt(rcvBufSize);
out.writeLong(idleQryCurTimeout);
out.writeLong(idleQryCurCheckFreq);
out.writeInt(sndQueueLimit);
out.writeInt(selectorCnt);
out.writeLong(idleTimeout);
out.writeBoolean(sslClientAuth);
U.writeString(out, sslFactory);
out.writeInt(portRange);
U.writeString(out, msgInterceptor);
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(pid);
out.writeInt(cid);
out.writeObject(decision);
out.writeObject(consMsgs);
}
/**
* Write endpoint to output stream.
*/
public void write(ObjectOutput out) throws IOException {
if (csf == null) {
out.writeByte(FORMAT_HOST_PORT);
out.writeUTF(host);
out.writeInt(port);
} else {
out.writeByte(FORMAT_HOST_PORT_FACTORY);
out.writeUTF(host);
out.writeInt(port);
out.writeObject(csf);
}
}
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(factoryTyp);
U.writeString(out, clsName);
out.writeObject(payload);
U.writeMap(out, props);
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(this.expr);
out.writeUTF((this.expectedType != null) ? this.expectedType.getName()
: "");
out.writeObject(ReflectionUtil.toTypeNameArray(this.paramTypes));
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
final int[] dice = new int[rolls.size()];
for (int i = 0; i < rolls.size(); i++) {
dice[i] = rolls.get(i).getCompressedValue();
}
out.writeObject(dice);
out.writeInt(hits);
out.writeDouble(expectedHits);
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeInt(explainString.size());
for (int i = 0; i < explainString.size(); ++i) {
out.writeUTF(explainString.get(i));
}
out.writeUTF(sparkExplainKind.toString());
if (!sparkExplainKind.equals(ExplainNode.SparkExplainKind.NONE))
out.writeObject(source);
}
/**
* Write out external representation for remote ref.
*/
public void writeExternal(ObjectOutput out) throws IOException
{
RemoteRef localRef = ref;
out.writeObject(id);
if (localRef == null) {
out.writeUTF("");
} else {
out.writeUTF(localRef.getRefClass(out));
localRef.writeExternal(out);
}
}
/** {@inheritDoc} */
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(interpolator);
out.writeInt(y.length);
out.writeInt(dydp[0].length);
writeArray(out, y);
writeArray(out, dydy0);
writeArray(out, dydp);
writeArray(out, yDot);
writeArray(out, dydy0Dot);
writeArray(out, dydpDot);
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(this.id);
out.writeObject(this.user);
out.writeInt(this.ddr16Phase);
}
/** Save the base state of the instance.
* This method performs step finalization if it has not been done
* before.
* @param out stream where to save the state
* @exception IOException in case of write error
*/
protected void writeBaseExternal(final ObjectOutput out)
throws IOException {
if (currentState == null) {
out.writeInt(-1);
} else {
out.writeInt(currentState.length);
}
out.writeDouble(globalPreviousTime);
out.writeDouble(globalCurrentTime);
out.writeDouble(softPreviousTime);
out.writeDouble(softCurrentTime);
out.writeDouble(h);
out.writeBoolean(forward);
out.writeObject(primaryMapper);
out.write(secondaryMappers.length);
for (final EquationsMapper mapper : secondaryMappers) {
out.writeObject(mapper);
}
if (currentState != null) {
for (int i = 0; i < currentState.length; ++i) {
out.writeDouble(currentState[i]);
}
}
out.writeDouble(interpolatedTime);
// we do not store the interpolated state,
// it will be recomputed as needed after reading
try {
// finalize the step (and don't bother saving the now true flag)
finalizeStep();
} catch (MaxCountExceededException mcee) {
final IOException ioe = new IOException(mcee.getLocalizedMessage());
ioe.initCause(mcee);
throw ioe;
}
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(type);
out.writeLong(seqno);
out.writeObject(gossip);
out.writeObject(xmit_reqs);
}
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(filter);
}
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeObject(this.getAttribute());
TimestampAttribute timestampAttribute = (TimestampAttribute) this.getAttribute();
timestampAttribute.writeToStream(out, (Timestamp)this.getParameter());
}
@Override
public void writeExternal(ObjectOutput out) throws IOException{
out.writeObject(template);
writeScan(out);
out.writeBoolean(rowColumnMap!=null);
if(rowColumnMap!=null){
out.writeInt(rowColumnMap.length);
//noinspection ForLoopReplaceableByForEach
for(int i=0;i<rowColumnMap.length;++i){
out.writeInt(rowColumnMap[i]);
}
}
writeTxn(out);
ArrayUtil.writeByteArray(out, token);
ArrayUtil.writeIntArray(out,keyColumnEncodingOrder);
ArrayUtil.writeIntArray(out,partitionByColumns);
out.writeBoolean(keyColumnSortOrder!=null);
if(keyColumnSortOrder!=null){
ArrayUtil.writeBooleanArray(out,keyColumnSortOrder);
}
ArrayUtil.writeIntArray(out,keyColumnTypes);
out.writeBoolean(keyDecodingMap!=null);
if(keyDecodingMap!=null){
ArrayUtil.writeIntArray(out,keyDecodingMap);
}
out.writeBoolean(baseColumnMap!=null);
if(baseColumnMap!=null){
ArrayUtil.writeIntArray(out,baseColumnMap);
}
out.writeObject(accessedKeys);
out.writeBoolean(reuseRowLocation);
out.writeBoolean(oneSplitPerRegion);
out.writeBoolean(indexName!=null);
if(indexName!=null)
out.writeUTF(indexName);
out.writeBoolean(tableVersion!=null);
if(tableVersion!=null)
out.writeUTF(tableVersion);
out.writeBoolean(fieldLengths!=null);
if(fieldLengths!=null){
out.writeInt(fieldLengths.length);
//noinspection ForLoopReplaceableByForEach
for(int i=0;i<fieldLengths.length;++i){
out.writeInt(fieldLengths[i]);
}
out.writeInt(columnPositionMap.length);
//noinspection ForLoopReplaceableByForEach
for(int i=0;i<columnPositionMap.length;++i){
out.writeInt(columnPositionMap[i]);
}
out.writeLong(baseTableConglomId);
}
out.writeLong(demarcationPoint);
out.writeBoolean(optionalProbeValue !=null);
if (optionalProbeValue!=null)
out.writeObject(optionalProbeValue);
out.writeBoolean(pin);
writeNullableString(delimited,out);
writeNullableString(escaped,out);
writeNullableString(lines,out);
writeNullableString(storedAs,out);
writeNullableString(location,out);
out.writeBoolean(useSample);
out.writeDouble(sampleFraction);
out.writeBoolean(defaultRow != null);
if (defaultRow != null)
out.writeObject(defaultRow);
out.writeBoolean(defaultValueMap != null);
if (defaultValueMap != null)
out.writeObject(defaultValueMap);
out.writeBoolean(ignoreRecentTransactions);
}
@Override
public void writeExternal(ObjectOutput objectOutput) throws IOException {
objectOutput.writeShort(fEvalFlags);
objectOutput.writeObject(vector);
}
protected void writeParameter(ObjectOutput out, Object o) throws IOException
{
out.writeObject(o);
}
/**
* Method for class's implementing externalizable to delegate to if not custom implementing.
*
* @param out
* @throws IOException
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
public void writeObject(ObjectOutput out) throws IOException {
out.writeObject(getProperties());
}