/** * Will first write the data lenght (or -1 if data null) and then write the data if non-null. * * @param data Data to write * @throws IOException */ public void writeData(byte[] data) throws IOException { writeData(this, data); }
public void writeNullableByte(Byte value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeByte(value); } }
public void writeNullableInt(Integer value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeInt(value); } }
public void writeNullableDouble(Float value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeDouble(value); } }
public void write(DataOutputStream ss) throws IOException { BitSet flags = new BitSet(); if (specificClass) { setFlag(flags, Flags.SPECIFIC); } boolean longId = classId != null && classId.getLibraryId() instanceof LongLibraryId; if (longId) { setFlag(flags, Flags.LONGLIBID); } long[] flagsBytes = flags.toLongArray(); if (flagsBytes.length == 0) { flagsBytes = EMPTYFLAGS; } ss.writeUnsignedNumber(flagsBytes[0]); ss.writeUnsignedNumber(version); if (!specificClass) { if (classId != null) { ss.writeUnsignedNumber(classId.getClassId() + 1); if (longId) { ss.writeUTF(classId.getLibraryId().toString()); } else { ss.writeByte(((ShortLibraryId) classId.getLibraryId()).getId()); } } else { ss.writeUnsignedNumber(0); ss.writeUTF(classType.getName()); } } }
public void serialize(DataOutputStream os) throws IOException { os.writeUnsignedNumber(dataList.size()); for (byte[] data : dataList) { os.writeData(data); } }
public void writeEnum(@Nullable Enum<?> enumeration) throws IOException { writeUnsignedNumber(enumValue(enumeration)); }
public void writeNullableFloat(Float value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeFloat(value); } }
public void writeNullableShort(Short value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeShort(value); } }
public void writeNullableLong(Long value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeLong(value); } }
public void writeShortEnum(Enum<?> enumeration) throws IOException { writeShort(enumValue(enumeration)); }
public void writeNullableBoolean(Boolean value) throws IOException { final boolean isNotNull = value != null; writeBoolean(isNotNull); if (isNotNull) { writeBoolean(value); } }
public void writeUnsignedNumber(long number) throws IOException { if (number < 0) { throw new IllegalArgumentException("Number isn't unsigned"); } int shift = 0; final int maxBounds = BOUNDS.length; for (int i = 0; i < maxBounds; i++) { long bound = BOUNDS[i]; boolean more = number > bound; write((int) ((number & bound) >> shift) | (more ? 128 : 0)); if (!more) { break; } shift += 7; } }