Search in sources :

Example 1 with ByteArray

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");
    }
}
Also used : SequenceValue(org.neo4j.values.SequenceValue) AnyValue(org.neo4j.values.AnyValue) ByteArray(org.neo4j.values.storable.ByteArray) Point(org.neo4j.graphdb.spatial.Point)

Aggregations

Point (org.neo4j.graphdb.spatial.Point)1 AnyValue (org.neo4j.values.AnyValue)1 SequenceValue (org.neo4j.values.SequenceValue)1 ByteArray (org.neo4j.values.storable.ByteArray)1