@Override public void writeFloat(float v) { writeInt(Float.floatToIntBits(v)); }
@Override public void writeInt(int integer) { assureSize(4); // Make sure the buffer has enough space writeIntUnsafe(integer); }
/** * Same as writeVInt(), but without checking that there is enough space for it. */ private void writeVIntUnsafe(int i) { while ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7f) | 0x80)); i >>>= 7; } writeByteUnsafe((byte) i); }
/** * Writes an int in a variable-length format. Writes between one and * five bytes. Smaller values take fewer bytes. Negative numbers are not * supported. */ @Override public void writeVInt(int i) { assureSize(5); writeVIntUnsafe(i); }
@Override public byte[] toBytes() { if (uuidBytes == null) { DataOutput dataOutput = new DataOutputImpl(17); writeBytes(dataOutput); uuidBytes = dataOutput.toByteArray(); } return uuidBytes; }
/** * Serializes a list of {@link DependencyEntry}s into a byte array for * usage in the forward index table. It uses a variable length byte array encoding schema. * * @param dependencies list of dependencies to serialize * @return byte array with the serialized format */ byte[] serializeDependenciesForward(Collection<DependencyEntry> dependencies) throws IOException { final DataOutputImpl dataOutput = new DataOutputImpl(); // total number of dependencies dataOutput.writeInt(dependencies.size()); for (DependencyEntry dependencyEntry : dependencies) { // we store the master record id, because that is how they are stored in the backward table final byte[] masterTableBytes = Bytes.toBytes(dependencyEntry.getDependency().getTable()); final byte[] masterBytes = dependencyEntry.getDependency().getRecordId().getMaster().toBytes(); dataOutput.writeInt(masterTableBytes.length); dataOutput.writeBytes(masterTableBytes); dataOutput.writeInt(masterBytes.length); dataOutput.writeBytes(masterBytes); final byte[] variantPropertiesBytes = serializeVariantPropertiesPattern(createVariantPropertiesPattern( dependencyEntry.getDependency().getRecordId().getVariantProperties(), dependencyEntry.getMoreDimensionedVariants())); dataOutput.writeBytes(variantPropertiesBytes); } return dataOutput.toByteArray(); }
private void writeUTF(String string, boolean includeLength, boolean useVInt) { if (string == null) { if (useVInt) writeVInt(-1); else writeInt(-1); return; assureSize(4 + utflen); // Make sure the buffer has enough space to put the bytes for the length and the string writeVIntUnsafe(utflen); } else { writeIntUnsafe(utflen);
@Override public void writeBoolean(boolean b) { assureSize(1); writeByteUnsafe(b ? ONE : ZERO); }
/** * Writes a long in a variable-length format. Writes between one and five * bytes. Smaller values take fewer bytes. Negative numbers are not * supported. */ @Override public void writeVLong(long i) { assureSize(5); writeVLongUnsafe(i); }
@Override public void writeByte(byte b) { assureSize(1); buffer[pos++] = b; }
@Override public byte[] toBytes() { if (recordIdBytes == null) { DataOutput dataOutput = new DataOutputImpl(); writeBytes(dataOutput); recordIdBytes = dataOutput.toByteArray(); } return recordIdBytes; }
@Override public void writeShort(int value) { assureSize(2); writeByteUnsafe((byte) (value >> 8)); writeByteUnsafe((byte) value); }
@Override public void writeBytes(byte[] bytes) { int length = bytes.length; assureSize(length); System.arraycopy(bytes, 0, buffer, pos, length); pos += length; }
@Override public byte[] toBytes() { if (recordIdBytes == null) { DataOutput dataOutput = new DataOutputImpl(); writeBytes(dataOutput); recordIdBytes = dataOutput.toByteArray(); } return recordIdBytes; }
/** * Same as writeVLong(), but without checking that there is enough space for it. */ private void writeVLongUnsafe(long i) { while ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7f) | 0x80)); i >>>= 7; } writeByteUnsafe((byte) i); }
@Override public void writeLong(long value) { assureSize(8); writeIntUnsafe((int) (value >> 32)); writeIntUnsafe((int) value); }
private byte[] idToBytes(UUID uuid) { DataOutput dataOutput = new DataOutputImpl(16); dataOutput.writeLong(uuid.getMostSignificantBits()); dataOutput.writeLong(uuid.getLeastSignificantBits()); return dataOutput.toByteArray(); }
@Override public byte[] toBytes(Object value, IdentityRecordStack parentRecords) throws RepositoryException, InterruptedException { DataOutput dataOutput = new DataOutputImpl(); write(value, dataOutput, parentRecords); return dataOutput.toByteArray(); }
public static final byte[] write(Record record, LRepository repository) throws RepositoryException, InterruptedException { DataOutput output = new DataOutputImpl(); write(record, output, repository); return output.toByteArray(); }
public static final byte[] writeIdRecord(IdRecord record, LRepository repository) throws RepositoryException, InterruptedException { DataOutput output = new DataOutputImpl(); writeIdRecord(record, output, repository); return output.toByteArray(); }