下面列出了java.io.ObjectOutputStream#writeInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeUTF(methodName);
oos.writeInt(parameterTypes.length);
for (Class<?> parameterType : parameterTypes) {
oos.writeObject(parameterType);
}
if (args != null) {
oos.writeBoolean(true);
for (int i = 0; i < args.length; i++) {
try {
oos.writeObject(args[i]);
} catch (IOException e) {
throw new IOException("Could not serialize " + i + "th argument of method " +
methodName + ". This indicates that the argument type " +
args.getClass().getName() + " is not serializable. Arguments have to " +
"be serializable for remote rpc calls.", e);
}
}
} else {
oos.writeBoolean(false);
}
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
int count = size();
stream.writeInt(count);
for (int i = 0; i < count; i++) {
Shape shape = getShape(i);
if (shape != null) {
stream.writeInt(i);
SerialUtilities.writeShape(shape, stream);
}
else {
stream.writeInt(-1);
}
}
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(final ObjectOutputStream stream)
throws IOException {
stream.defaultWriteObject();
final int count = size();
stream.writeInt(count);
for (int i = 0; i < count; i++) {
final Object object = get(i);
if (object != null && object instanceof Serializable) {
stream.writeInt(i);
stream.writeObject(object);
}
else {
stream.writeInt(-1);
}
}
}
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
int w = getIconWidth();
int h = getIconHeight();
int[] pixels = image != null? new int[w * h] : null;
if (image != null) {
try {
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
pg.grabPixels();
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
throw new IOException("failed to load image contents");
}
}
catch (InterruptedException e) {
throw new IOException("image load interrupted");
}
}
s.writeInt(w);
s.writeInt(h);
s.writeObject(pixels);
}
/**
* Serialize {@link #context}.
*
* @param out Stream.
* @throws IOException This should never happen.
*/
private void serializeContext(ObjectOutputStream out)
throws IOException {
// Step 1.
final int len = context.keySet().size();
out.writeInt(len);
for (String key : context.keySet()) {
// Step 2.
out.writeObject(key);
final Object value = context.get(key);
if (value instanceof Serializable) {
// Step 3a.
out.writeObject(value);
} else {
// Step 3b.
out.writeObject(nonSerializableReplacement(value));
}
}
}
private void saveGameStatistics(ObjectOutputStream objectOutputStream) throws IOException {
WorldObject playerCharacter = getPlayerCharacter();
objectOutputStream.writeObject(playerCharacter.getProperty(Constants.NAME));
objectOutputStream.writeInt(playerCharacter.getProperty(Constants.LEVEL));
objectOutputStream.writeInt(currentTurn.getValue());
objectOutputStream.writeObject(playerCharacter.getProperty(Constants.IMAGE_ID));
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
stream.writeInt(elementData.length);
stream.writeInt(elementCount);
Iterator<?> iterator = entrySet().iterator();
while (iterator.hasNext()) {
Entry<?, ?> entry = (Entry<?, ?>) iterator.next();
stream.writeObject(entry.key);
stream.writeObject(entry.value);
entry = entry.next;
}
}
public void saveState(ObjectOutputStream objectOutputStream)
throws IOException {
if (!mInstanceable) {
// TODO ensure size == 1
objectOutputStream.writeBoolean(mDataSourceInstances != null
&& mDataSourceInstances.get(0).isChecked());
mDataSourceInstances.get(0).saveState(objectOutputStream);
} else {
objectOutputStream.writeInt(mDataSourceInstances.size());
for (DataSourceInstanceHolder dataSourceInstance : mDataSourceInstances) {
dataSourceInstance.saveState(objectOutputStream);
}
}
}
private void writeObject(ObjectOutputStream stream)
throws IOException {
stream.defaultWriteObject();
// number of entries
stream.writeInt(_size);
SerializationProcedure writeProcedure = new SerializationProcedure(stream);
if (! forEachEntry(writeProcedure)) {
throw writeProcedure.exception;
}
}
public void doWrite( ObjectOutputStream stream )
throws IOException
{
// write the IOR to the ObjectOutputStream
stream.writeInt(typeData.length);
stream.write(typeData);
stream.writeInt(profileTags.length);
for (int i = 0; i < profileTags.length; i++) {
stream.writeInt(profileTags[i]);
stream.writeInt(profileData[i].length);
stream.write(profileData[i]);
}
}
private void writeObject(
ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
out.writeObject(dhSpec.getP());
out.writeObject(dhSpec.getG());
out.writeInt(dhSpec.getL());
}
/** Custom serialization */
private void writeObject(ObjectOutputStream os) throws IOException {
os.writeInt(values.length);
for (int value : values) {
os.writeInt(value);
}
}
public void write(DataOutputStream out) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(out);
synchronized (this) {
oos.writeInt(infos.size());
Iterator<SparseVector> iterator = infos.iterator();
while (iterator.hasNext()) {
SparseVector sv = iterator.next();
oos.writeObject(sv.index);
oos.writeObject(sv.value);
}
}
oos.close();
}
/**
* Serialize DbAppenderConfiguration.
* @param s serialization stream.
* @throws IOException if exception during serialization.
*/
private void writeObject(
final ObjectOutputStream s ) throws IOException {
s.defaultWriteObject();
if (loggingThreshold == null) {
// should be set in RemoteLoggingConfiguration
throw new IllegalStateException("Logging level should not be null");
}
s.writeInt(loggingThreshold.toInt());
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeInt(size);
T curr = head.next;
for (int i = 0; i < size; i++) {
oos.writeObject(curr);
curr = curr.next;
}
}
void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(mode);
for (int i = 0; i < generalNumbers.length; i++) {
out.writeLong(generalNumbers[i]);
}
if (mode == CommonConstants.MODE_THREADS_SAMPLING) {
out.writeInt(nThreads);
out.writeInt(nThreadStates);
for (int i = 0; i < nThreads; i++) {
out.writeInt(threadIds[i]);
}
for (int i = 0; i < nThreadStates; i++) {
out.writeLong(stateTimestamps[i]);
}
int len = nThreads * nThreadStates;
out.write(threadStates, 0, len);
} else if (mode == CommonConstants.MODE_THREADS_EXACT) {
out.writeInt(exactThreadStates.length);
for (int i = 0; i < exactThreadIds.length; i++) {
out.writeInt(exactThreadIds[i]);
out.writeByte(exactThreadStates[i]);
out.writeLong(exactTimeStamps[i]);
}
}
if (nNewThreads == 0) {
out.writeInt(0);
} else {
out.writeInt(nNewThreads);
for (int i = 0; i < nNewThreads; i++) {
out.writeInt(newThreadIds[i]);
out.writeUTF(newThreadNames[i]);
out.writeUTF(newThreadClassNames[i]);
}
}
out.writeInt(gcStarts.length);
for (int i = 0; i < gcStarts.length; i++) {
out.writeLong(gcStarts[i]);
}
out.writeInt(gcFinishs.length);
for (int i = 0; i < gcFinishs.length; i++) {
out.writeLong(gcFinishs[i]);
}
out.writeInt(serverState);
out.writeInt(serverProgress);
}
void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(className);
out.writeInt(classLoaderId);
}
void writeObject(ObjectOutputStream out) throws IOException {
if (instrMethodClasses == null) {
out.writeInt(0);
return;
}
out.writeInt(nClasses);
for (int i = 0; i < nClasses; i++) {
out.writeUTF(instrMethodClasses[i]);
out.writeInt(instrMethodClassLoaderIds[i]);
}
out.writeInt(nMethods);
if (instrMethodLeaf != null) {
out.write(1);
for (int i = 0; i < nMethods; i++) {
out.writeBoolean(instrMethodLeaf[i]);
}
} else {
out.write(0);
}
out.writeInt(addInfo);
for (int i = 0; i < nClasses; i++) {
if (replacementClassFileBytes[i] == null) {
out.writeInt(0);
} else {
out.writeInt(replacementClassFileBytes[i].length);
out.write(replacementClassFileBytes[i]);
}
}
instrMethodClasses = null;
instrMethodClassLoaderIds = null;
instrMethodLeaf = null;
replacementClassFileBytes = null;
}
/** Serialize a {@link RealMatrix}.
* <p>
* This method is intended to be called from within a private
* <code>writeObject</code> method (after a call to
* <code>oos.defaultWriteObject()</code>) in a class that has a
* {@link RealMatrix} field, which should be declared <code>transient</code>.
* This way, the default handling does not serialize the matrix (the {@link
* RealMatrix} interface is not serializable by default) but this method does
* serialize it specifically.
* </p>
* <p>
* The following example shows how a simple class with a name and a real matrix
* should be written:
* <pre><code>
* public class NamedMatrix implements Serializable {
*
* private final String name;
* private final transient RealMatrix coefficients;
*
* // omitted constructors, getters ...
*
* private void writeObject(ObjectOutputStream oos) throws IOException {
* oos.defaultWriteObject(); // takes care of name field
* MatrixUtils.serializeRealMatrix(coefficients, oos);
* }
*
* private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
* ois.defaultReadObject(); // takes care of name field
* MatrixUtils.deserializeRealMatrix(this, "coefficients", ois);
* }
*
* }
* </code></pre>
* </p>
*
* @param matrix real matrix to serialize
* @param oos stream where the real matrix should be written
* @exception IOException if object cannot be written to stream
* @see #deserializeRealMatrix(Object, String, ObjectInputStream)
*/
public static void serializeRealMatrix(final RealMatrix matrix,
final ObjectOutputStream oos)
throws IOException {
final int n = matrix.getRowDimension();
final int m = matrix.getColumnDimension();
oos.writeInt(n);
oos.writeInt(m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
oos.writeDouble(matrix.getEntry(i, j));
}
}
}
/** Serialize a {@link RealMatrix}.
* <p>
* This method is intended to be called from within a private
* <code>writeObject</code> method (after a call to
* <code>oos.defaultWriteObject()</code>) in a class that has a
* {@link RealMatrix} field, which should be declared <code>transient</code>.
* This way, the default handling does not serialize the matrix (the {@link
* RealMatrix} interface is not serializable by default) but this method does
* serialize it specifically.
* </p>
* <p>
* The following example shows how a simple class with a name and a real matrix
* should be written:
* <pre><code>
* public class NamedMatrix implements Serializable {
*
* private final String name;
* private final transient RealMatrix coefficients;
*
* // omitted constructors, getters ...
*
* private void writeObject(ObjectOutputStream oos) throws IOException {
* oos.defaultWriteObject(); // takes care of name field
* MatrixUtils.serializeRealMatrix(coefficients, oos);
* }
*
* private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
* ois.defaultReadObject(); // takes care of name field
* MatrixUtils.deserializeRealMatrix(this, "coefficients", ois);
* }
*
* }
* </code></pre>
* </p>
*
* @param matrix real matrix to serialize
* @param oos stream where the real matrix should be written
* @exception IOException if object cannot be written to stream
* @see #deserializeRealMatrix(Object, String, ObjectInputStream)
*/
public static void serializeRealMatrix(final RealMatrix matrix,
final ObjectOutputStream oos)
throws IOException {
final int n = matrix.getRowDimension();
final int m = matrix.getColumnDimension();
oos.writeInt(n);
oos.writeInt(m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
oos.writeDouble(matrix.getEntry(i, j));
}
}
}