protected void writePackager(ObjectOutput out) throws IOException { out.writeByte('P'); String pclass = packager.getClass().getName(); byte[] b = pclass.getBytes(); out.writeShort(b.length); out.write(b); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { boolean done; boolean cancelled; Object res; Throwable err; boolean syncNotify; boolean concurNotify; synchronized (mux) { done = this.done; cancelled = this.cancelled; res = this.res; err = this.err; syncNotify = this.syncNotify; concurNotify = this.concurNotify; } out.writeBoolean(done); out.writeBoolean(syncNotify); out.writeBoolean(concurNotify); // Don't write any further if not done, as deserialized future // will be invalid anyways. if (done) { out.writeBoolean(cancelled); out.writeObject(res); out.writeObject(err); } }
public void writeExternal(ObjectOutput out) throws IOException { out.writeByte(0); // reserved for future expansion (version id) out.writeShort(fieldNumber); if (header != null) writeHeader(out); if (packager != null) writePackager(out); if (direction > 0) writeDirection(out); // List keySet = new ArrayList (fields.keySet()); // Collections.sort (keySet); Iterator iter = fields.values().iterator(); while (iter.hasNext()) { ISOComponent c = (ISOComponent) iter.next(); if (c instanceof ISOMsg) { writeExternal(out, 'M', c); } else if (c instanceof ISOBinaryField) { writeExternal(out, 'B', c); } else if (c instanceof ISOAmount) { writeExternal(out, 'A', c); } else if (c instanceof ISOField) { writeExternal(out, 'F', c); } } out.writeByte('E'); }
@Override public void writeExternal(ObjectOutput out) throws IOException { byte[] bytes = getBytes(); out.writeInt(bytes.length); out.writeInt(this.numFields); out.write(bytes); }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(size()); for (int i = 0; i < size(); i++) { out.writeObject(get(i)); } }
/** * Serialize an instance, restore it, and check for equality. In addition, test for a bug that was * reported where the listener list is 'null' after deserialization. */ public void testSerialization() { BarRenderer r1 = new BarRenderer(); r1.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 4)); r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.green)); r1.setBaseLegendShape(new Line2D.Double(1.0, 2.0, 3.0, 4.0)); BarRenderer r2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(r1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); r2 = (BarRenderer) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(r1, r2); try { r2.notifyListeners(new RendererChangeEvent(r2)); } catch (NullPointerException e) { assertTrue(false); // failed } }
public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(1); // version if (first instanceof Serializable) out.writeObject(first); else out.writeObject(null); if (second instanceof Serializable) out.writeObject(second); else out.writeObject(null); }
public static byte[] convertToBytes(Object object) throws IOException { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos)) { out.writeObject(object); return bos.toByteArray(); } }
// Implements Externalizable public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // MAP out.writeObject(_map); }
// deprecated in ObjectOutputStream.PutField public void write(ObjectOutput out) throws IOException { /* * Applications should *not* use this method to write PutField * data, as it will lead to stream corruption if the PutField * object writes any primitive data (since block data mode is not * unset/set properly, as is done in OOS.writeFields()). This * broken implementation is being retained solely for behavioral * compatibility, in order to support applications which use * OOS.PutField.write() for writing only non-primitive data. * * Serialization of unshared objects is not implemented here since * it is not necessary for backwards compatibility; also, unshared * semantics may not be supported by the given ObjectOutput * instance. Applications which write unshared objects using the * PutField API must use OOS.writeFields(). */ if (InteropObjectOutputStream.this != out) { throw new IllegalArgumentException("wrong stream"); } out.write(primVals, 0, primVals.length); ObjectStreamField[] fields = desc.getFields(false); int numPrimFields = fields.length - objVals.length; // REMIND: warn if numPrimFields > 0? for (int i = 0; i < objVals.length; i++) { if (fields[numPrimFields + i].isUnshared()) { throw new IOException("cannot write unshared object"); } out.writeObject(objVals[i]); } }
/** * compare the byte-array representation of two TaskObjects. * * @param f TaskObject * @param s TaskObject * @return true if the two arguments have the same byte-array */ private boolean sameBytes(TaskObject f, TaskObject s) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(f); byte[] fs = bos.toByteArray(); out.writeObject(s); byte[] ss = bos.toByteArray(); if (fs.length != ss.length) return false; for (int i = 0; i < fs.length; i++) { if (fs[i] != ss[i]) return false; } return true; } catch (IOException e) { e.printStackTrace(); return false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { // ignore } try { bos.close(); } catch (IOException e) { // ignore } } } }
// Implements Externalizable @Override public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // SET out.writeObject(_set); }
public void writeExternal(final ObjectOutput out) throws IOException { out.writeByte(0); out.writeInt(this._size); final SerializationProcedure writeProcedure = new SerializationProcedure(out); if (!this.forEach(writeProcedure)) { throw writeProcedure.exception; } }
public byte[] getByteContent() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(baos); out.writeObject(content); out.close(); return baos.toByteArray(); }
protected void writeHeader(ObjectOutput out) throws IOException { int len = header.getLength(); if (len > 0) { out.writeByte('H'); out.writeShort(len); out.write(header.pack()); } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(firstName); out.writeUTF(lastName); out.writeInt(age); out.writeObject(mother); out.writeObject(father); out.writeObject(children); }
public void writeExternal(final ObjectOutput out) throws IOException { out.writeByte(1); out.writeInt(this._pos); final int len = this._pos; out.writeInt(this._pos); for (int i = 0; i < len; ++i) { out.writeShort(this._data[i]); } }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, jobName); U.writeString(out, user); out.writeBoolean(hasCombiner); out.writeInt(numReduces); U.writeStringMap(out, props); }
/** Serializes this <code>DataFlavor</code>. */ public synchronized void writeExternal(ObjectOutput os) throws IOException { if (mimeType != null) { mimeType.setParameter("humanPresentableName", humanPresentableName); os.writeObject(mimeType); mimeType.removeParameter("humanPresentableName"); } else { os.writeObject(null); } os.writeObject(representationClass); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { GridUtils.writeUuid(out, nodeId); CU.writeVersion(out, ver); out.writeLong(timeout); out.writeLong(threadId); out.writeLong(id); out.writeShort(flags()); }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(id); boolean writable = innerSplit instanceof Writable; out.writeUTF(writable ? innerSplit.getClass().getName() : null); if (writable) ((Writable) innerSplit).write(out); else out.writeObject(innerSplit); }
// write data to server's database file private void updateFile(String file_name, Object data) { try { OutputStream file_data = new FileOutputStream(file_name); OutputStream buffer = new BufferedOutputStream(file_data); ObjectOutput data_out = new ObjectOutputStream(buffer); data_out.writeObject(data); data_out.close(); } catch (Exception e) { System.out.println("updateFile: Failed to update data to " + file_name); } }
public void writeExternal(ObjectOutput out) { try { out.writeObject("LEVEL"); out.writeObject(new Integer(level)); out.writeObject("TIMESUSED"); out.writeObject(new Integer(timesUsed)); out.writeObject("SKILL END"); } catch (Exception e) { e.printStackTrace(); } }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeBoolean(depEnabled); if (depEnabled) { U.writeByteArray(out, topicBytes); U.writeByteArray(out, predBytes); U.writeString(out, clsName); out.writeObject(depInfo); } else { out.writeObject(topic); out.writeObject(pred); } }
private static void writeOnPrimitive( final ObjectOutput out, final Object obj, final ClassMetadataField metaField) throws IOException { try { final Field field = metaField.getField(); final Class clazz = field.getType(); if (clazz == Integer.TYPE) { out.writeInt(FieldsManager.getFieldsManager().getInt(obj, metaField)); } else if (clazz == Byte.TYPE) { out.writeByte(FieldsManager.getFieldsManager().getByte(obj, metaField)); } else if (clazz == Long.TYPE) { out.writeLong(FieldsManager.getFieldsManager().getLong(obj, metaField)); } else if (clazz == Float.TYPE) { out.writeFloat(FieldsManager.getFieldsManager().getFloat(obj, metaField)); } else if (clazz == Double.TYPE) { out.writeDouble(FieldsManager.getFieldsManager().getDouble(obj, metaField)); } else if (clazz == Short.TYPE) { out.writeShort(FieldsManager.getFieldsManager().getShort(obj, metaField)); } else if (clazz == Character.TYPE) { out.writeChar(field.getChar(obj)); } else if (clazz == Boolean.TYPE) { out.writeBoolean(field.getBoolean(obj)); } else { throw new RuntimeException("Unexpected datatype " + clazz.getName()); } } catch (IllegalAccessException access) { IOException io = new IOException(access.getMessage()); io.initCause(access); throw io; } }
/** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); out.writeLong(threadId); out.writeBoolean(commit); out.writeBoolean(invalidate); out.writeBoolean(reply); U.writeGridUuid(out, futId); CU.writeVersion(out, commitVer); CU.writeVersion(out, baseVer); U.writeCollection(out, writeEntries); }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.write(this.cardinality & 0xFF); out.write((this.cardinality >>> 8) & 0xFF); if (BufferUtil.isBackedBySimpleArray(content)) { short[] a = content.array(); for (int k = 0; k < this.cardinality; ++k) { out.writeShort(Short.reverseBytes(a[k])); } } else { for (int k = 0; k < this.cardinality; ++k) { out.writeShort(Short.reverseBytes(content.get(k))); } } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(2); out.writeInt(548); out.writeInt(348); byte[] bytes = new byte[1024]; for (int i = 0; i < 548; i++) { bytes[i] = 1; } out.write(bytes, 0, 548); bytes = new byte[1024]; for (int i = 0; i < 348; i++) { bytes[i] = 2; } out.write(bytes, 0, 348); }
/** * @param out Output stream. * @param err Error cause. */ private void sendErrorResponse(ObjectOutput out, Exception err) { try { out.writeObject(new IpcSharedMemoryInitResponse(err)); } catch (IOException e) { U.error(log, "Failed to send error response to client.", e); } }
/** {@inheritDoc} */ public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // SUPER super.writeExternal(out); // NUMBER OF ENTRIES out.writeInt(_size); // ENTRIES for (int i = _states.length; i-- > 0; ) { if (_states[i] == FULL) { out.writeInt(_set[i]); out.writeInt(_values[i]); } } }