下面列出了java.io.ObjectOutputStream#writeBoolean ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Writes a map of (<code>Comparable</code>, <code>Paint</code>)
* elements to a stream.
*
* @param map the map (<code>null</code> permitted).
*
* @param out
* @throws IOException
*
* @see #readPaintMap(ObjectInputStream)
*/
private void writePaintMap(Map map, ObjectOutputStream out)
throws IOException {
if (map == null) {
out.writeBoolean(true);
}
else {
out.writeBoolean(false);
Set keys = map.keySet();
int count = keys.size();
out.writeInt(count);
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Comparable key = (Comparable) iterator.next();
out.writeObject(key);
SerialUtilities.writePaint((Paint) map.get(key), out);
}
}
}
/**
* Writes a Constructor or Method object.
*
* Methods and Constructors are not serializable, so we must serialize
* information about the class, the name, and the parameters and
* recreate upon deserialization.
*/
private static void writeMember(ObjectOutputStream out, Member member)
throws IOException
{
if (member == null) {
out.writeBoolean(false);
return;
}
out.writeBoolean(true);
if (!(member instanceof Method || member instanceof Constructor))
throw new IllegalArgumentException("not Method or Constructor");
out.writeBoolean(member instanceof Method);
out.writeObject(member.getName());
out.writeObject(member.getDeclaringClass());
if (member instanceof Method) {
writeParameters(out, ((Method) member).getParameterTypes());
} else {
writeParameters(out, ((Constructor<?>) member).getParameterTypes());
}
}
/**
* Writes a map of (<code>Comparable</code>, <code>Paint</code>)
* elements to a stream.
*
* @param map the map (<code>null</code> permitted).
*
* @param out
* @throws IOException
*
* @see #readPaintMap(ObjectInputStream)
*/
private void writePaintMap(Map map, ObjectOutputStream out)
throws IOException {
if (map == null) {
out.writeBoolean(true);
}
else {
out.writeBoolean(false);
Set keys = map.keySet();
int count = keys.size();
out.writeInt(count);
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Comparable key = (Comparable) iterator.next();
out.writeObject(key);
SerialUtilities.writePaint((Paint) map.get(key), out);
}
}
}
@Override
public void save(ObjectOutputStream oos) throws IOException {
oos.writeUTF(userId);
oos.writeUTF(name);
oos.writeUTF(dn);
oos.writeBoolean(isInitialized);
oos.writeBoolean(isInitializedHIA);
oos.writeObject(a005Certificate);
oos.writeObject(e002Certificate);
oos.writeObject(x002Certificate);
oos.writeObject(a005PrivateKey);
oos.writeObject(e002PrivateKey);
oos.writeObject(x002PrivateKey);
oos.flush();
oos.close();
needSave = false;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeBoolean(false);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readBoolean();
}
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeBoolean(z);
out.writeByte(b);
out.writeChar(c);
out.writeShort(s);
out.writeInt(i);
out.writeFloat(f);
out.writeLong(j);
out.writeDouble(d);
out.writeObject(str);
out.writeObject(parent);
out.writeObject(left);
out.writeObject(right);
}
private void writeObject(ObjectOutputStream out) throws IOException
{
log.debug("Serializing PortletState [action={}]", action);
out.writeObject(id);
out.writeBoolean(action);
out.writeBoolean(secure);
out.writeObject(parameters);
out.writeObject(portletMode.toString());
out.writeObject(windowState.toString());
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
if (principal instanceof Serializable) {
out.writeBoolean(true);
out.writeObject(principal);
} else {
out.writeBoolean(false);
}
}
/** 将cookie写到对象流中 */
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(this.cookie.name());
out.writeObject(this.cookie.value());
out.writeLong(this.cookie.expiresAt());
out.writeObject(this.cookie.domain());
out.writeObject(this.cookie.path());
out.writeBoolean(this.cookie.secure());
out.writeBoolean(this.cookie.httpOnly());
out.writeBoolean(this.cookie.hostOnly());
out.writeBoolean(this.cookie.persistent());
}
/**
* Custom serialization routine used during serialization of a
* Session/PersistenceContext for increased performance.
*
* @param oos The stream to which we should write the serial data.
* @throws IOException
*/
void serialize(ObjectOutputStream oos) throws IOException {
oos.writeObject( identifier );
oos.writeObject( rootEntityName );
oos.writeObject( entityName );
oos.writeObject( identifierType );
oos.writeBoolean( isBatchLoadable );
oos.writeObject( entityMode.toString() );
}
void writeObject(ObjectOutputStream out) throws IOException {
out.writeBoolean(lockContentionMonitoringEnabled);
out.writeInt(nProfiledThreadsLimit);
out.writeInt(stackDepthLimit);
out.writeInt(samplingInterval);
out.writeInt(objAllocStackSamplingInterval);
out.writeInt(objAllocStackSamplingDepth);
out.writeBoolean(runGCOnGetResultsInMemoryProfiling);
out.writeBoolean(waitTrackingEnabled);
out.writeBoolean(sleepTrackingEnabled);
out.writeBoolean(threadsSamplingEnabled);
out.writeInt(threadsSamplingFrequency);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getDomain());
out.writeObject(cookie.getExpiryDate());
out.writeObject(cookie.getPath());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.isSecure());
}
private void writeObject(final ObjectOutputStream out) throws IOException {
// write all the non-transient fields
out.defaultWriteObject();
// write the non-serializable default value field
if (defaultValue == null) {
// we don't have a default value
out.writeBoolean(false);
} else {
TypeSerializer<T> serializer = serializerAtomicReference.get();
checkNotNull(serializer, "Serializer not initialized.");
// we have a default value
out.writeBoolean(true);
byte[] serializedDefaultValue;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputViewStreamWrapper outView = new DataOutputViewStreamWrapper(baos)) {
TypeSerializer<T> duplicateSerializer = serializer.duplicate();
duplicateSerializer.serialize(defaultValue, outView);
outView.flush();
serializedDefaultValue = baos.toByteArray();
}
catch (Exception e) {
throw new IOException("Unable to serialize default value of type " +
defaultValue.getClass().getSimpleName() + ".", e);
}
out.writeInt(serializedDefaultValue.length);
out.write(serializedDefaultValue);
}
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeObject(logDir.toAbsolutePath().toString());
stream.writeObject(outputDir.toAbsolutePath().toString());
stream.writeObject(validationDir.toAbsolutePath().toString());
stream.writeBoolean(outputRequired);
stream.writeBoolean(validationRequired);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.name());
out.writeObject(cookie.value());
out.writeLong(cookie.expiresAt());
out.writeObject(cookie.domain());
out.writeObject(cookie.path());
out.writeBoolean(cookie.secure());
out.writeBoolean(cookie.httpOnly());
out.writeBoolean(cookie.hostOnly());
out.writeBoolean(cookie.persistent());
}
public void saveState(ObjectOutputStream objectOutputStream)
throws IOException {
// Store filter, serializable
objectOutputStream.writeObject(currentFilter);
// Store data source instance settings using settings framework
SettingsHelper.storeSettings(objectOutputStream, this.dataSource);
objectOutputStream.writeBoolean(isChecked());
}
private void writeObject(final ObjectOutputStream out) throws IOException {
// write all the non-transient fields
out.defaultWriteObject();
// write the non-serializable default value field
if (defaultValue == null) {
// we don't have a default value
out.writeBoolean(false);
} else {
TypeSerializer<T> serializer = serializerAtomicReference.get();
checkNotNull(serializer, "Serializer not initialized.");
// we have a default value
out.writeBoolean(true);
byte[] serializedDefaultValue;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputViewStreamWrapper outView = new DataOutputViewStreamWrapper(baos)) {
TypeSerializer<T> duplicateSerializer = serializer.duplicate();
duplicateSerializer.serialize(defaultValue, outView);
outView.flush();
serializedDefaultValue = baos.toByteArray();
}
catch (Exception e) {
throw new IOException("Unable to serialize default value of type " +
defaultValue.getClass().getSimpleName() + ".", e);
}
out.writeInt(serializedDefaultValue.length);
out.write(serializedDefaultValue);
}
}
private void writeObject(ObjectOutputStream out) throws IOException
{
out.writeObject(cookie.name());
out.writeObject(cookie.value());
out.writeLong(cookie.expiresAt());
out.writeObject(cookie.domain());
out.writeObject(cookie.path());
out.writeBoolean(cookie.secure());
out.writeBoolean(cookie.httpOnly());
out.writeBoolean(cookie.hostOnly());
out.writeBoolean(cookie.persistent());
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeInt(mAllAtoms);
stream.writeInt(mAllBonds);
stream.writeBoolean(mIsFragment);
for (int atom=0; atom<mAllAtoms; atom++) {
stream.writeInt(mAtomicNo[atom]);
stream.writeInt(mAtomCharge[atom]);
stream.writeInt(mAtomMass[atom]);
stream.writeInt(mAtomFlags[atom] & ~cAtomFlagsHelper);
stream.writeInt(mAtomQueryFeatures[atom]);
stream.writeDouble(mCoordinates[atom].x); // for compatibility with earlier double based coords
stream.writeDouble(mCoordinates[atom].y);
stream.writeDouble(mCoordinates[atom].z);
stream.writeInt(mAtomMapNo[atom]);
if (mAtomList != null && mAtomList[atom] != null) {
stream.writeInt(mAtomList[atom].length);
for (int i=0; i<mAtomList[atom].length; i++)
stream.writeInt(mAtomList[atom][i]);
}
else
stream.writeInt(0);
if (mAtomCustomLabel != null && mAtomCustomLabel[atom] != null) {
stream.writeInt(mAtomCustomLabel[atom].length);
for (int i=0; i<mAtomCustomLabel[atom].length; i++)
stream.writeByte(mAtomCustomLabel[atom][i]);
}
else
stream.writeInt(0);
}
for (int bond=0; bond<mAllBonds;bond++) {
stream.writeInt(mBondAtom[0][bond]);
stream.writeInt(mBondAtom[1][bond]);
stream.writeInt(mBondType[bond]);
stream.writeInt(mBondFlags[bond]);
stream.writeInt(mBondQueryFeatures[bond]);
}
stream.writeObject(mName);
}
private void writeObject(ObjectOutputStream oos) throws IOException {
LOG.trace("Serializing reference to {}", this);
oos.writeUTF(entityType.getInterfaceName());
oos.writeBoolean(loaded);
oos.writeObject(reference);
}