/** * See write for the byte format. */ @Override @SuppressWarnings("unchecked") public Blob read(DataInput dataInput) { // Read the encoding version byte, but ignore it for the moment since there is only one encoding dataInput.readByte(); int keyLength = dataInput.readVInt(); byte[] key = null; if (keyLength > 0) { key = dataInput.readBytes(keyLength); } String mediaType = dataInput.readUTF(); Long size = dataInput.readLong(); if (size == -1) { size = null; } String filename = dataInput.readUTF(); return new Blob(key, mediaType, size, filename); }
DerefMapVariantPropertiesPattern deserializeVariantPropertiesPattern(DataInput dataInput) { final Map<String, String> pattern = new HashMap<String, String>(); final int nEntries = dataInput.readInt(); while (pattern.size() < nEntries) { final String name = dataInput.readUTF(); final String value = dataInput.readUTF(); pattern.put(name, value); } return new DerefMapVariantPropertiesPattern(pattern); }
@Override public Object deserialize(DataInput dataInput) { return dataInput.readVUTF(); } }
int pos = dataInput.getPosition(); int size = dataInput.getSize(); dataInput.setPosition(size - 1); byte identifierByte = dataInput.readByte(); dataInput.setPosition(pos); dataInput.setSize(size - 1); switch (idIdentifier) { case UUID: UUID uuid = new UUID(dataInput.readLong(), dataInput.readLong()); recordId = (RecordId)UUID_CONSTRUCTOR.newInstance(uuid, idGenerator); break; case USER: String basicRecordIdString = dataInput.readUTF(); checkIdString(basicRecordIdString, "record id"); recordId = (RecordId)USER_CONSTRUCTOR.newInstance(basicRecordIdString, idGenerator); break; case VARIANT: int position = dataInput.getPosition(); int length = dataInput.getSize(); dataInput.setPosition(length - 8); int nrOfVariants = dataInput.readInt(); int masterRecordIdLength = dataInput.readInt(); dataInput.setPosition(masterRecordIdLength); String dimension = dataInput.readUTF(); String dimensionValue = dataInput.readUTF();
public static Link read(DataInput dataInput, IdGenerator idGenerator) { // Format: see write(DataOutput). int tableLength = dataInput.readInt(); byte[] tableBytes = dataInput.readBytes(tableLength); int recordIdLength = dataInput.readInt(); byte[] recordIdBytes = null; if (recordIdLength > 0) { recordIdBytes = dataInput.readBytes(recordIdLength); } String args = dataInput.readUTF(); if (recordIdLength == 0 && args == null) { return new Link(); } LinkBuilder builder = Link.newBuilder(); if (tableLength > 0) { builder.table(new String(tableBytes)); } if (recordIdLength > 0) { RecordId id = idGenerator.fromBytes(recordIdBytes); builder.recordId(id); } if (args != null && args.length() > 0) { argsFromString(args, builder, args /* does not matter, should never be invalid */); } return builder.create(); }
@Override public RecordId fromBytes(DataInput dataInput, IdGeneratorImpl idGenerator) { if (dataInput.indexOf((byte) 0) != -1) { throw new IllegalArgumentException("The NULL character is not allowed in USER record id's."); } String id = dataInput.readUTF(dataInput.getSize() - dataInput.getPosition()); // read the remainder of the data input return new UserRecordId(id, idGenerator); }
public ListValueType(TypeManager typeManager, DataInput typeParamsDataInput) throws RepositoryException, InterruptedException { this(typeManager, typeParamsDataInput.readUTF()); }
public static Metadata read(DataInput input) { MetadataBuilder metadataBuilder = new MetadataBuilder(); // read fields int size = input.readVInt(); for (int i = 0; i < size; i++) { String key = input.readVUTF(); byte valueType = input.readByte(); ValueSerDeser serdeser = BYTE_TO_SERDESER.get(valueType); if (serdeser == null) { throw new IllegalArgumentException("Unsupported kind of metadata value: type byte " + (int)valueType); } Object value = serdeser.deserialize(input); metadataBuilder.object(key, value); } // read deleted fields size = input.readVInt(); for (int i = 0; i < size; i++) { metadataBuilder.delete(input.readVUTF()); } return metadataBuilder.build(); }
public static final Record read(DataInput input, LRepository repository) throws RepositoryException, InterruptedException { int version = input.readShort(); if (version != VERSION_1 && version != VERSION_2) { throw new RuntimeException("Unsupported record serialization version: " + version); int size = input.readVInt(); for (int i = 0; i < size; i++) { QName name = readQName(input); String valueTypeName = input.readUTF(); ValueType valueType = typeManager.getValueType(valueTypeName); Object value = valueType.read(input); size = input.readVInt(); for (int i = 0; i < size; i++) { record.getFieldsToDelete().add(readQName(input)); size = input.readVInt(); for (int i = 0; i < size; i++) { String key = input.readUTF(); String value = input.readUTF(); size = input.readVInt(); for (int i = 0; i < size; i++) { QName fieldName = readQName(input);
protected VariantRecordId(RecordId masterRecordId, DataInput dataInput, IdGeneratorImpl idGenerator) { this.masterRecordId = masterRecordId; this.idGenerator = idGenerator; SortedMap<String, String> varProps = createVariantPropertiesMap(); while (dataInput.getPosition() < dataInput.getSize()) { String dimension = dataInput.readVUTF(); String dimensionValue = dataInput.readVUTF(); IdGeneratorImpl.checkVariantPropertyNameValue(dimension); IdGeneratorImpl.checkVariantPropertyNameValue(dimensionValue); varProps.put(dimension, dimensionValue); } this.variantProperties = Collections.unmodifiableSortedMap(varProps); }
public static AuthorizationContext deserialiaze(byte[] data) { DataInput input = new DataInputImpl(data); String name = input.readVUTF(); String tenant = input.readVUTF(); Set<String> roles = new HashSet<String>(); int roleCnt = input.readVInt(); for (int i = 0; i < roleCnt; i++) { roles.add(input.readVUTF()); } return new AuthorizationContext(name, tenant, roles); } }
@Override @SuppressWarnings("unchecked") public ByteArray read(DataInput dataInput) { int length = dataInput.readInt(); // We can use ByteArray.wrap here since in this use case the dataInput // will always be a DataInputImpl which copies the bytes when reading // them. return ByteArray.wrap(dataInput.readBytes(length)); }
@Override @SuppressWarnings("unchecked") public DateTime read(DataInput dataInput) { // Read the encoding version byte, but ignore it for the moment since there is only one encoding dataInput.readByte(); // Always construct UTC such that it is not depending on the default timezone of the current host return new DateTime(dataInput.readLong(), DateTimeZone.UTC); }
@Override public DataInput[] splitInMasterAndVariant(DataInput dataInput) { // Search for separator byte int sepPos = dataInput.indexOf(VARIANT_SEPARATOR); if (sepPos == -1) { return new DataInput[]{dataInput, null}; } else { DataInput keyInput = new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition(), sepPos - dataInput.getPosition()); DataInput variantInput = new DataInputImpl(((DataInputImpl) dataInput), sepPos + 1, dataInput.getSize() - (sepPos + 1)); return new DataInput[]{keyInput, variantInput}; } }
private static QName readNullOrQName(DataInput input) { byte nullMarker = input.readByte(); if (nullMarker == NULL_MARKER) { return null; } else { return readQName(input); } }
@Override public DataInput[] splitInMasterAndVariant(DataInput dataInput) { if (dataInput.getSize() - dataInput.getPosition() > UUID_LENGTH) { DataInput keyInput = new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition(), dataInput.getPosition() + 16); DataInput variantInput = new DataInputImpl(((DataInputImpl) dataInput), dataInput.getPosition() + 16, dataInput.getSize() - 17); return new DataInput[]{keyInput, variantInput}; } else { return new DataInput[]{dataInput, null}; } }