/** * Wraps a byte[] instead of copying it like the constructor does. * <p> * Warning! This method should only be used when the user is absolutely * certain that the provided byte[] will not be modified anymore. * * @param bytes * the byte[] to wrap * @return a ByteArray */ public static ByteArray wrap(byte[] bytes) { ByteArray byteArray = new ByteArray(); byteArray.bytes = bytes; return byteArray; }
@Override public void serialize(Object value, DataOutput dataOutput) { dataOutput.writeVInt(((ByteArray)value).length()); dataOutput.writeBytes(((ByteArray) value).getBytesUnsafe()); }
result = toJson((Record)value, options, namespaces, repository); } else if (name.equals("BYTEARRAY")) { result = factory.binaryNode(((ByteArray) value).getBytes()); } else { throw new RuntimeException("Unsupported value type: " + name);
@Override public int compare(ByteArray o1, ByteArray o2) { return Bytes.compareTo(o1.getBytesUnsafe(), o2.getBytesUnsafe()); } };
@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)); }
ObjectNode binaryNode = metadataNode.putObject(metadata.getKey()); binaryNode.put("type", "binary"); binaryNode.put("value", ((ByteArray)value).getBytes()); } else if (value instanceof DateTime){ ObjectNode dateTimeNode = metadataNode.putObject(metadata.getKey());
@Override public Object deserialize(DataInput dataInput) { int size = dataInput.readVInt(); return new ByteArray(dataInput.readBytes(size)); } }
@Override public void write(Object value, DataOutput dataOutput, IdentityRecordStack parentRecords) { ByteArray byteArray = (ByteArray) value; dataOutput.writeInt(byteArray.length()); // We can use getBytesUnsafe here since we know that in this use case // the // dataOutput will be a DataOutputImpl which copies the byte[] when // writing it. dataOutput.writeBytes(byteArray.getBytesUnsafe()); }
protected ByteArray readByteArray(ValueHandle handle, ReadContext context) throws JsonFormatException, RepositoryException, InterruptedException { if (!handle.node.isTextual()) { throw new JsonFormatException("Expected base64 encoded value for property '" + handle.prop + "'"); } try { return new ByteArray(handle.node.getBinaryValue()); } catch (IOException e) { throw new JsonFormatException("Could not read base64 value for property '" + handle.prop + "'", e); } }
builder.value(name, new ByteArray(binaryValue.getBinaryValue())); } catch (IOException e) { throw new JsonFormatException("Invalid binary value for metadata field '"