下面列出了java.io.ObjectInput#readObject ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
OHLCItem item2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(item1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray()));
item2 = (OHLCItem) in.readObject();
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertEquals(item1, item2);
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
OHLCSeries s1 = new OHLCSeries("s1");
s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
OHLCSeries s2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(s1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray()));
s2 = (OHLCSeries) in.readObject();
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertEquals(s1, s2);
}
/**
* 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);
}
@Override
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException{
super.readExternal(in);
oneRowScan=in.readBoolean();
lockMode=in.readInt();
isolationLevel=in.readInt();
scanInformation=(ScanInformation<ExecRow>)in.readObject();
tableVersion=in.readUTF();
rowIdKey = in.readBoolean();
pin = in.readBoolean();
delimited = in.readBoolean()?in.readUTF():null;
escaped = in.readBoolean()?in.readUTF():null;
lines = in.readBoolean()?in.readUTF():null;
storedAs = in.readBoolean()?in.readUTF():null;
location = in.readBoolean()?in.readUTF():null;
partitionRefItem = in.readInt();
splits = in.readInt();
}
/**
* 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);
}
/**
* 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);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
getProbeValsFuncName = SerializationUtils.readNullableString(in);
sortRequired = in.readInt();
inlistPosition = in.readInt();
if (in.readBoolean()) {
probeValues = new DataValueDescriptor[in.readInt()];
for (int i = 0; i < probeValues.length; i++) {
probeValues[i] = (DataValueDescriptor) in.readObject();
}
}
probeValue = (DataValueDescriptor)in.readObject();
inlistTypeArrayItem = in.readInt();
}
/**
* @see java.io.Externalizable#readExternal
*
* @exception IOException Thrown on read error
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
FormatableHashtable fh = (FormatableHashtable) in.readObject();
isUnique = fh.getBoolean("isUnique");
int bcpLength = fh.getInt("keyLength");
baseColumnPositions = new int[bcpLength];
isAscending = new boolean[bcpLength];
for (int i = 0; i < bcpLength; i++) {
baseColumnPositions[i] = fh.getInt("bcp" + i);
isAscending[i] = fh.getBoolean("isAsc" + i);
}
numberOfOrderedColumns = fh.getInt("orderedColumns");
indexType = (String) fh.get("indexType");
//isUniqueWithDuplicateNulls attribute won't be present if the index
//was created in older versions
isUniqueWithDuplicateNulls = fh.containsKey("isUniqueWithDuplicateNulls") && fh.getBoolean("isUniqueWithDuplicateNulls");
excludeNulls = fh.containsKey("excludeNulls") && fh.getBoolean("excludeNulls");
excludeDefaults = fh.containsKey("excludeDefaults") && fh.getBoolean("excludeDefaults");
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
isEnum = in.readBoolean();
enumName = (String) in.readObject();
fieldName = (String) in.readObject();
if ( !isEnum || enumName == null || fieldName == null ) {
value = (Serializable) in.readObject();
} else {
resolveEnumValue( (DroolsObjectInputStream) in );
}
setBooleans();
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
dataProvider = (DataProvider) in.readObject();
alphaConstraints = (AlphaNodeFieldConstraint[]) in.readObject();
betaConstraints = (BetaConstraints) in.readObject();
tupleMemoryEnabled = in.readBoolean();
send = (AsyncSend) in.readObject();
}
/**
* Read the whole tree from a file (serialized)
*/
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
_bitSize = in.readInt();
_intSize = (_bitSize >>> 5) + 1;
_mask = in.readInt();
_bits = (int[])in.readObject();
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
columnId = in.readInt();
storagePosition = in.readInt();
operator = in.readInt();
orderedNulls = in.readBoolean();
unknownRV = in.readBoolean();
negateCompareResult = in.readBoolean();
variantType = in.readInt();
orderableCache = (DataValueDescriptor) in.readObject();
}
/**
* Read this object from a stream of stored objects.
*
* @param in read this.
*
* @exception IOException thrown on error
* @exception ClassNotFoundException thrown on error
*/
public void readExternal( ObjectInput in )
throws IOException, ClassNotFoundException
{
FormatableHashtable fh = (FormatableHashtable)in.readObject();
uuid = (UUID)fh.get("uuid");
dFinder = (DependableFinder)fh.get("dFinder");
providerName = (String) fh.get("providerName");
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
hashTable = (AbstractHashTable) in.readObject();
table = (Entry[]) in.readObject();
row = in.readInt();
length = in.readInt();
entry = (Entry) in.readObject();
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
identifier=(Serializable)in.readObject();
}
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
arg = (String)in.readObject();
}
private void readRangeResolverData(ObjectInput in)
throws ClassNotFoundException, IOException {
this.rangeValuesHolderList = (ArrayList)in.readObject();
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
this.sinks = (LeftTupleSinkNodeList) in.readObject();
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
dataProvider = ( DataProvider ) in.readObject();
resultPattern = ( Pattern ) in.readObject();
resultClass = ( Class<?> ) in.readObject();
}
public void readExternal(final ObjectInput in) throws IOException,
ClassNotFoundException {
final short version = ShortPacker.unpackShort(in);
switch (version) {
case VERSION0:
case VERSION1:
case VERSION2:
break;
default:
throw new IOException("Unknown version: " + version);
}
if (version < VERSION2) {
partitionId = (int) LongPacker.unpackLong(in);
} else {
partitionId = in.readInt();
}
sourcePartitionId = in.readInt(); // MAY be -1.
final int nresources = ShortPacker.unpackShort(in);
final int leftLen = (int) LongPacker.unpackLong(in);
final int rightLen = (int) LongPacker.unpackLong(in);
leftSeparatorKey = new byte[leftLen];
in.readFully(leftSeparatorKey);
if (rightLen != 0) {
rightSeparatorKey = new byte[rightLen];
in.readFully(rightSeparatorKey);
} else {
rightSeparatorKey = null;
}
cause = (IndexPartitionCause)in.readObject();
if (version < VERSION2) {
/* history = */in.readUTF();
}
resources = nresources>0 ? new IResourceMetadata[nresources] : null;
for (int j = 0; j < nresources; j++) {
final boolean isIndexSegment = in.readBoolean();
final String filename = in.readUTF();
// long nbytes = LongPacker.unpackLong(in);
final UUID uuid = new UUID(in.readLong()/*MSB*/,in.readLong()/*LSB*/);
final long createTime = in.readLong();
long commitTime = 0L;
if (version >= VERSION1 && !isIndexSegment) {
commitTime = in.readLong();
}
resources[j] = (isIndexSegment //
? new SegmentMetadata(filename, /*nbytes,*/ uuid, createTime) //
: new JournalMetadata(filename, /*nbytes,*/ uuid, createTime, commitTime) //
);
}
}