Java Code Examples for java.io.ObjectOutputStream#writeInt()
The following examples show how to use
java.io.ObjectOutputStream#writeInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteRpcInvocation.java From flink with Apache License 2.0 | 6 votes |
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); } }
Example 2
Source File: MathRuntimeException.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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)); } } }
Example 3
Source File: ImageIcon.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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); }
Example 4
Source File: AbstractObjectList.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * 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); } } }
Example 5
Source File: Cardumen_0084_s.java From coming with MIT License | 6 votes |
/** * 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); } } }
Example 6
Source File: TDoubleIntHashMap.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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; } }
Example 7
Source File: StubIORImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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]); } }
Example 8
Source File: DataSourceHolder.java From geoar-app with Apache License 2.0 | 5 votes |
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); } } }
Example 9
Source File: BCDHPublicKey.java From RipplePower with Apache License 2.0 | 5 votes |
private void writeObject( ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeObject(dhSpec.getP()); out.writeObject(dhSpec.getG()); out.writeInt(dhSpec.getL()); }
Example 10
Source File: OriginalHashMap.java From PauselessHashMap with Apache License 2.0 | 5 votes |
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; } }
Example 11
Source File: DenseArrayOfInts.java From morpheus-core with Apache License 2.0 | 5 votes |
/** Custom serialization */ private void writeObject(ObjectOutputStream os) throws IOException { os.writeInt(values.length); for (int value : values) { os.writeInt(value); } }
Example 12
Source File: AdClusteringsInfo.java From laser with Apache License 2.0 | 5 votes |
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(); }
Example 13
Source File: WorldImpl.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
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)); }
Example 14
Source File: DbAppenderConfiguration.java From ats-framework with Apache License 2.0 | 5 votes |
/** * 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()); }
Example 15
Source File: DoubleLinkedList.java From settlers-remake with MIT License | 5 votes |
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; } }
Example 16
Source File: GetClassIdCommand.java From visualvm with GNU General Public License v2.0 | 4 votes |
void writeObject(ObjectOutputStream out) throws IOException { out.writeUTF(className); out.writeInt(classLoaderId); }
Example 17
Source File: InstrumentMethodGroupData.java From visualvm with GNU General Public License v2.0 | 4 votes |
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; }
Example 18
Source File: MonitoredNumbersResponse.java From netbeans with Apache License 2.0 | 4 votes |
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); }
Example 19
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** 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)); } } }
Example 20
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** 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)); } } }