use of org.neo4j.values.storable.ByteArray in project neo4j by neo4j.
the class ProcedureCompilation method toByteArray.
/**
* Byte arrays needs special treatment since it is not a proper Cypher type
* @param input either a ByteArray or ListValue of bytes
* @return input value converted to a byte[]
*/
public static byte[] toByteArray(AnyValue input) {
if (input instanceof ByteArray) {
return ((ByteArray) input).asObjectCopy();
}
if (input instanceof SequenceValue) {
SequenceValue list = (SequenceValue) input;
if (list.iterationPreference() == RANDOM_ACCESS) {
byte[] bytes = new byte[list.length()];
for (int a = 0; a < bytes.length; a++) {
bytes[a] = asByte(list.value(a));
}
return bytes;
} else {
// list.length may have linear complexity, still worth doing it upfront
byte[] bytes = new byte[list.length()];
int i = 0;
for (AnyValue anyValue : list) {
bytes[i++] = asByte(anyValue);
}
return bytes;
}
} else {
throw new IllegalArgumentException("Cannot convert " + input.getClass().getSimpleName() + " to byte[] for input to procedure");
}
}
Aggregations