public static byte[] encodeValueType(String valueTypeName) { DataOutput dataOutput = new DataOutputImpl(); dataOutput.writeByte(valueTypeEncodingVersion); dataOutput.writeUTF(valueTypeName); return dataOutput.toByteArray(); }
@Override public void writeBytes(DataOutput dataOutput) { if (recordIdBytes == null) { dataOutput.writeByte(IdGeneratorImpl.IdType.USER.getIdentifierByte()); dataOutput.writeUTF(basicRecordIdString, false); } else { dataOutput.writeBytes(recordIdBytes); } }
public static void writeMetadataWithLengthSuffix(Metadata metadata, DataOutput output) { DataOutput tmp = new DataOutputImpl(); MetadataSerDeser.write(metadata, tmp); byte[] metadataBytes = tmp.toByteArray(); output.writeBytes(metadataBytes); output.writeInt(metadataBytes.length); }
private static void writeNullOrVLong(Long value, DataOutput output) { if (value == null) { output.writeByte(NULL_MARKER); } else { output.writeByte(NOT_NULL_MARKER); output.writeVLong(value); } }
/** * 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()); }
/** * Serializes a variant properties pattern. The serialization format is simply a list of variable length strings. * <code>null</code> values (meaning "any value" in the pattern) are written literaly as <code>null</code> Strings. * * @param variantPropertiesPattern pattern to serialize * @return serialized pattern */ byte[] serializeVariantPropertiesPattern(DerefMapVariantPropertiesPattern variantPropertiesPattern) throws IOException { final DataOutput dataOutput = new DataOutputImpl(); // total number of entries dataOutput.writeInt(variantPropertiesPattern.pattern.size()); for (Map.Entry<String, String> patternEntry : variantPropertiesPattern.pattern.entrySet()) { // name final String name = patternEntry.getKey(); dataOutput.writeUTF(name); // value (potentially null) final String value = patternEntry.getValue(); dataOutput.writeUTF(value); } return dataOutput.toByteArray(); }
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 void write(DataOutput dataOutput) { // The bytes format is as follows: // [byte representation of table, byte representation of master record id, if not null][args: bytes of the string representation] byte[] tableBytes = table == null ? new byte[0] : table.getBytes(); dataOutput.writeInt(tableBytes.length); if (tableBytes.length > 0) { dataOutput.writeBytes(tableBytes); } byte[] recordIdBytes = masterRecordId == null ? new byte[0] : masterRecordId.toBytes(); dataOutput.writeInt(recordIdBytes.length); if (recordIdBytes.length > 0) { dataOutput.writeBytes(recordIdBytes); } StringBuilder argsBuilder = new StringBuilder(); argstoString(argsBuilder); dataOutput.writeUTF(argsBuilder.toString()); }
@Override public byte[] toBytes() { if (uuidBytes == null) { DataOutput dataOutput = new DataOutputImpl(17); writeBytes(dataOutput); uuidBytes = dataOutput.toByteArray(); } return uuidBytes; }
@Override public final void writeBytes(DataOutput dataOutput) { if (recordIdBytes == null) { masterRecordId.writeBytes(dataOutput); // TODO this needs to be designed some other way if (masterRecordId instanceof UserRecordId) { dataOutput.writeByte((byte) 0); } Set<Entry<String, String>> entrySet = variantProperties.entrySet(); for (Entry<String, String> entry : entrySet) { // entry consists of the dimension and the dimension value dataOutput.writeVUTF(entry.getKey()); dataOutput.writeVUTF(entry.getValue()); } } else { dataOutput.writeBytes(recordIdBytes); } }
public static byte[] encodeName(QName qname) { String name = qname.getName(); String namespace = qname.getNamespace(); int sizeEstimate = (((name == null) ? 1 : (name.length() * 2)) + ((namespace == null) ? 1 : (namespace.length() * 2))); DataOutput dataOutput = new DataOutputImpl(sizeEstimate); dataOutput.writeUTF(namespace); dataOutput.writeUTF(name); return dataOutput.toByteArray(); }
@Override public void writeBytes(DataOutput dataOutput) { if (uuidBytes == null) { dataOutput.writeByte(IdGeneratorImpl.IdType.UUID.getIdentifierByte()); dataOutput.writeLong(uuid.getMostSignificantBits()); dataOutput.writeLong(uuid.getLeastSignificantBits()); } else { dataOutput.writeBytes(uuidBytes); } }
/** * 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); } }
private static void writeBytes(byte[] bytes, DataOutput output) { output.writeVInt(bytes.length); output.writeBytes(bytes); }
output.writeShort(VERSION_2); output.writeVInt(record.getFields().size()); for (Map.Entry<QName, Object> entry : record.getFields().entrySet()) { if (entry.getKey() == null) { output.writeUTF(valueType.getName()); try { valueType.write(entry.getValue(), output, new IdentityRecordStack()); 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.writeUTF(key); output.writeUTF(value); output.writeVInt(0); output.writeVInt(metadatas.size()); for (Map.Entry<QName, Metadata> entry : metadatas.entrySet()) { writeQName(entry.getKey(), output); output.writeVInt(0);
private byte[] idToBytes(UUID uuid) { DataOutput dataOutput = new DataOutputImpl(16); dataOutput.writeLong(uuid.getMostSignificantBits()); dataOutput.writeLong(uuid.getLeastSignificantBits()); return dataOutput.toByteArray(); }
@Override public void write(Object value, DataOutput dataOutput, IdentityRecordStack parentRecords) { dataOutput.writeUTF(((URI)value).toString()); }
boolean hasMetadata = metadata != null && !metadata.getMap().isEmpty(); dataOutput.writeByte(hasMetadata ? FieldFlags.METADATA_V1 : FieldFlags.DEFAULT); try { valueType.write(fieldValue, dataOutput, new IdentityRecordStack(parentRecord)); return dataOutput.toByteArray();