@Override public void serialize(Object value, DataOutput dataOutput) { dataOutput.writeVInt((Integer) value); }
private static void writeBytes(byte[] bytes, DataOutput output) { output.writeVInt(bytes.length); output.writeBytes(bytes); }
private static void writeNullOrVInt(Integer value, DataOutput output) { if (value == null) { output.writeByte(NULL_MARKER); } else { output.writeByte(NOT_NULL_MARKER); output.writeVInt(value); } }
public static byte[] serialize(Set<String> strings) { DataOutput builder = new DataOutputImpl(); builder.writeVInt(strings.size()); for (String permission : strings) { builder.writeVUTF(permission); } return builder.toByteArray(); }
/** * Writes the metadata to the given output. It can be read back from a variable-length input using * {@link #read(DataInput)}. */ public static void write(Metadata metadata, DataOutput output) { // Write the fields Map<String, Object> map = metadata.getMap(); output.writeVInt(map.size()); for (Map.Entry<String, Object> entry : map.entrySet()) { // write the key output.writeVUTF(entry.getKey()); // write the value Object value = entry.getValue(); ValueSerDeser serdeser = CLASS_TO_SERDESER.get(value.getClass()); if (serdeser == null) { throw new IllegalArgumentException("Unsupported kind of metadata value: type of '" + value + "' is " + value.getClass().getName()); } output.writeByte(serdeser.getTypeByte()); serdeser.serialize(value, output); } // Write the deleted fields Set<String> fieldsToDelete = metadata.getFieldsToDelete(); output.writeVInt(fieldsToDelete.size()); for (String field : fieldsToDelete) { output.writeVUTF(field); } }
@Override public void serialize(Object value, DataOutput dataOutput) { dataOutput.writeVInt(((ByteArray)value).length()); dataOutput.writeBytes(((ByteArray) value).getBytesUnsafe()); }
public byte[] serialize() { DataOutput buffer = new DataOutputImpl(); buffer.writeVUTF(name); buffer.writeVUTF(tenant); buffer.writeVInt(roles.size()); for (String role : roles) { buffer.writeVUTF(role); } return buffer.toByteArray(); }
public static final void writeIdRecord(IdRecord record, DataOutput output, LRepository repository) throws RepositoryException, InterruptedException { write(record, output, repository); output.writeVInt(record.getFieldIdToNameMapping().size()); for (Map.Entry<SchemaId, QName> entry : record.getFieldIdToNameMapping().entrySet()) { writeBytes(entry.getKey().getBytes(), output); writeQName(entry.getValue(), output); } for (Scope scope : Scope.values()) { SchemaId schemaId = record.getRecordTypeId(scope); writeNullOrBytes(schemaId != null ? schemaId.getBytes() : null, output); } }
/** * Format of the bytes written : * - Length of the blob value : int of 4 bytes * - Blob Value * - Blob Media Type : UTF (which starts with an int of 4 bytes indicating its length) * - Blob size : long of 8 bytes * - Blob name : UTF (which starts with an int of 4 bytes indicating its length) * * <p> IMPORTANT: Any changes on this format has an impact on the {@link ContainsValueComparator} */ @Override public void write(Object value, DataOutput dataOutput, IdentityRecordStack parentRecords) { dataOutput.writeByte((byte)1); // Encoding version 1 Blob blob = (Blob)value; byte[] key = blob.getValue(); if (key == null) { dataOutput.writeVInt(0); } else { dataOutput.writeVInt(key.length); dataOutput.writeBytes(key); } dataOutput.writeUTF(blob.getMediaType()); Long size = blob.getSize(); if (size == null) { size = Long.valueOf(-1); } dataOutput.writeLong(size); dataOutput.writeUTF(blob.getName()); }
output.writeVInt(record.getFields().size()); for (Map.Entry<QName, Object> entry : record.getFields().entrySet()) { if (entry.getKey() == null) { output.writeVInt(record.getFieldsToDelete().size()); for (QName name : record.getFieldsToDelete()) { writeQName(name, output); output.writeVInt(record.getAttributes().size()); for (String key : record.getAttributes().keySet()) { String value = record.getAttributes().get(key); output.writeVInt(0); output.writeVInt(metadatas.size()); for (Map.Entry<QName, Metadata> entry : metadatas.entrySet()) { writeQName(entry.getKey(), output); output.writeVInt(0);
dataOutput.writeVInt(recordIdBytes.length); dataOutput.writeBytes(recordIdBytes); dataOutput.writeLong(recordType.getVersion());