java.io.ObjectOutputStream#writeInt ( )源码实例Demo

下面列出了java.io.ObjectOutputStream#writeInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: flink   文件: RemoteRpcInvocation.java
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);
	}
}
 
源代码2 项目: coming   文件: Cardumen_0084_s.java
/**
 * 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);
        }
    }

}
 
源代码3 项目: ccu-historian   文件: AbstractObjectList.java
/**
 * 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);
        }
    }

}
 
源代码4 项目: openjdk-8-source   文件: ImageIcon.java
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);
}
 
源代码5 项目: astor   文件: MathRuntimeException.java
/**
 * 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));
        }
    }
}
 
源代码6 项目: WorldGrower   文件: WorldImpl.java
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));
}
 
源代码7 项目: PauselessHashMap   文件: OriginalHashMap.java
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;
    }
}
 
源代码8 项目: geoar-app   文件: DataSourceHolder.java
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);
		}
	}
}
 
源代码9 项目: gemfirexd-oss   文件: TDoubleIntHashMap.java
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;
    }
}
 
源代码10 项目: openjdk-8-source   文件: StubIORImpl.java
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]);
    }
}
 
源代码11 项目: RipplePower   文件: BCDHPublicKey.java
private void writeObject(
    ObjectOutputStream  out)
    throws IOException
{
    out.defaultWriteObject();

    out.writeObject(dhSpec.getP());
    out.writeObject(dhSpec.getG());
    out.writeInt(dhSpec.getL());
}
 
源代码12 项目: morpheus-core   文件: DenseArrayOfInts.java
/** Custom serialization */
private void writeObject(ObjectOutputStream os) throws IOException {
    os.writeInt(values.length);
    for (int value : values) {
        os.writeInt(value);
    }
}
 
源代码13 项目: laser   文件: AdClusteringsInfo.java
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();
}
 
源代码14 项目: ats-framework   文件: DbAppenderConfiguration.java
/**
 * 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());
}
 
源代码15 项目: settlers-remake   文件: DoubleLinkedList.java
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;
	}
}
 
源代码16 项目: netbeans   文件: MonitoredNumbersResponse.java
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);
}
 
源代码17 项目: visualvm   文件: GetClassIdCommand.java
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeUTF(className);
    out.writeInt(classLoaderId);
}
 
源代码18 项目: visualvm   文件: InstrumentMethodGroupData.java
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;
}
 
源代码19 项目: astor   文件: MatrixUtils.java
/** 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));
        }
    }
}
 
源代码20 项目: astor   文件: MatrixUtils.java
/** 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));
        }
    }
}