/** * Serializes a list of Integers. The argument may be null. Deserialize with * readListOfIntegers(). * * TODO: writeListOfIntegers is unused */ public void writeListOfIntegers(List<Integer> list, DataOutput out) throws IOException { if (list != null) { InternalDataSerializer.writeArrayLength(list.size(), out); for (Integer entry : list) { out.writeInt(entry); } } else { InternalDataSerializer.writeArrayLength(-1, out); } }
public static void writePdxEnumId(int eId, DataOutput out) throws IOException { out.writeByte(DSCODE.PDX_ENUM.toByte()); out.writeByte(eId >> 24); writeArrayLength(eId & 0xFFFFFF, out); }
/** this will deserialize as an ArrayList */ private void writeAsArrayList(List list, DataOutput out) throws IOException { int size; if (list == null) { size = -1; } else { size = list.size(); } InternalDataSerializer.writeArrayLength(size, out); if (size > 0) { for (int i = 0; i < size; i++) { DataSerializer.writeObject(list.get(i), out); } } }
/** * Writes the <code>Enum constant</code> to <code>DataOutput</code>. Unlike standard java * serialization which serializes both the enum name String and the ordinal, GemFire only * serializes the ordinal byte, so for backward compatibility new enum constants should only be * added to the end of the enum type.<br /> * Example: <code>DataSerializer.writeEnum(DAY_OF_WEEK.SUN, out);</code> * * @see #readEnum(Class, DataInput) * @since GemFire 6.5 */ public static void writeEnum(Enum e, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); if (e == null) { throw new NullPointerException( "The enum constant to serialize is null"); } if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing enum {}", e); } InternalDataSerializer.writeArrayLength(e.ordinal(), out); }
/** * Writes given number of characters from array of {@code char}s to a {@code DataOutput}. * * @throws IOException A problem occurs while writing to {@code out} * @see DataSerializer#readCharArray * @since GemFire 6.6 */ public static void writeCharArray(char[] array, DataOutput out) throws IOException { checkOut(out); if (array == null) { writeArrayLength(-1, out); } else { final int length = array.length; if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing char array of length {}", length); } writeArrayLength(length, out); for (char character : array) { out.writeChar(character); } } }
/** * Writes an array of <code>short</code>s to a <code>DataOutput</code>. This method will serialize * a <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readShortArray */ public static void writeShortArray(short[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing short array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeShort(array[i]); } } }
/** * Writes an <code>int</code> array to a <code>DataOutput</code>. This method will serialize a * <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readIntArray */ public static void writeIntArray(int[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing int array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeInt(array[i]); } } }
@Override public void sendTo(DataOutput out) throws IOException { out.writeByte(DSCODE.PDX_INLINE_ENUM.toByte()); DataSerializer.writeString(this.className, out); DataSerializer.writeString(this.enumName, out); InternalDataSerializer.writeArrayLength(this.enumOrdinal, out); }
@Override public void toData(DataOutput out) throws IOException { out.writeInt(windowId); InternalDataSerializer.writeString(packetId, out); InternalDataSerializer.writeObject(sender, out); InternalDataSerializer.writeArrayLength(records.length, out); for (SnapshotRecord rec : records) { InternalDataSerializer.invokeToData(rec, out); } }
/** * Writes an array of <code>boolean</code>s to a <code>DataOutput</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readBooleanArray * @since GemFire 5.7 */ public static void writeBooleanArray(boolean[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing boolean array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeBoolean(array[i]); } } }
/** * Writes an array of <code>float</code>s to a <code>DataOutput</code>. This method will serialize * a <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readFloatArray */ public static void writeFloatArray(float[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing float array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeFloat(array[i]); } } }
/** * Writes an array of <code>double</code>s to a <code>DataOutput</code>. This method will * serialize a <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readDoubleArray */ public static void writeDoubleArray(double[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing double array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeDouble(array[i]); } } }
/** * Writes an array of <code>long</code>s to a <code>DataOutput</code>. This method will serialize * a <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readLongArray */ public static void writeLongArray(long[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing long array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { out.writeLong(array[i]); } } }
@Override public void sendTo(DataOutput out) throws IOException { // When serialized it needs to look just as if writeObject was called on a HASH_MAP out.writeByte(DSCODE.HASH_MAP.toByte()); int size = size(); InternalDataSerializer.writeArrayLength(size, out); if (size > 0) { DataSerializer.writeObject(this.name[0], out); DataSerializer.writeObject(Integer.valueOf(this.op), out); } }
private static void writeGemFireEnum(Enum<?> e, DataOutput out) throws IOException { boolean isGemFireObject = isGemfireObject(e); DataSerializer.writePrimitiveByte( isGemFireObject ? DSCODE.GEMFIRE_ENUM.toByte() : DSCODE.PDX_INLINE_ENUM.toByte(), out); DataSerializer.writeString(e.getDeclaringClass().getName(), out); DataSerializer.writeString(e.name(), out); if (!isGemFireObject) { InternalDataSerializer.writeArrayLength(e.ordinal(), out); } }
public static void writeObjectArray(Object[] array, DataOutput out, boolean ensureCompatibility) throws IOException { InternalDataSerializer.checkOut(out); int length = -1; if (array != null) { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing Object array of length {}", length); } if (length >= 0) { writeClass(array.getClass().getComponentType(), out); for (int i = 0; i < length; i++) { basicWriteObject(array[i], out, ensureCompatibility); } } }
@Override public void sendAsByteArray(DataOutput out) throws IOException { if (!isCompressed() && out instanceof HeapDataOutputStream) { ByteBuffer bb = createDirectByteBuffer(); if (bb != null) { HeapDataOutputStream hdos = (HeapDataOutputStream) out; InternalDataSerializer.writeArrayLength(bb.remaining(), hdos); hdos.write(bb); return; } } super.sendAsByteArray(out); }
/** * Writes an array of <tt>byte[]</tt> to a <tt>DataOutput</tt>. * * @throws IOException A problem occurs while writing to <tt>out</tt>. * */ public static void writeArrayOfByteArrays(byte[][] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) { logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing byte[][] of length {}", length); } if (length >= 0) { for (int i = 0; i < length; i++) { writeByteArray(array[i], out); } } }
@Override public void sendTo(DataOutput out) throws IOException { if (!this.isCompressed() && out instanceof HeapDataOutputStream) { ByteBuffer bb = createDirectByteBuffer(); if (bb != null) { HeapDataOutputStream hdos = (HeapDataOutputStream) out; if (this.isSerialized()) { hdos.write(bb); } else { hdos.writeByte(DSCODE.BYTE_ARRAY.toByte()); InternalDataSerializer.writeArrayLength(bb.remaining(), hdos); hdos.write(bb); } return; } } super.sendTo(out); }
@Override public void toData(DataOutput out) throws IOException { InternalDataSerializer.invokeToData(memberID, out); InternalDataSerializer.writeSetOfLongs(this.allKeyClients.getSnapshot(), this.clientMap.hasLongID, out); DataSerializer.writeHashMap(this.keysOfInterest.getSnapshot(), out); DataSerializer.writeHashMap(this.patternsOfInterest.getSnapshot(), out); DataSerializer.writeHashMap(this.filtersOfInterest.getSnapshot(), out); InternalDataSerializer.writeSetOfLongs(this.allKeyClientsInv.getSnapshot(), this.clientMap.hasLongID, out); DataSerializer.writeHashMap(this.keysOfInterestInv.getSnapshot(), out); DataSerializer.writeHashMap(this.patternsOfInterestInv.getSnapshot(), out); DataSerializer.writeHashMap(this.filtersOfInterestInv.getSnapshot(), out); // Write CQ info. Map<String, ServerCQ> theCQs = this.cqs.getSnapshot(); int size = theCQs.size(); InternalDataSerializer.writeArrayLength(size, out); for (Iterator<Map.Entry<String, ServerCQ>> it = theCQs.entrySet().iterator(); it.hasNext();) { Map.Entry<String, ServerCQ> entry = it.next(); String name = entry.getKey(); ServerCQ cq = entry.getValue(); DataSerializer.writeString(name, out); InternalDataSerializer.invokeToData(cq, out); } }