/** Returns whether a data type is encoded as all zeroes. */ private static boolean isEncodedAsAllZeroBytes(Object value) { if (value == null) { return false; // Nulls are usually encoded as -1. } if (value instanceof Number) { Number number = (Number) value; return number.longValue() == 0 && number.doubleValue() == 0; } if (value instanceof byte[]) { byte[] array = (byte[]) value; return isAllZeroes(array, 0, array.length); } // NOTE: While empty string is all zeros, trying to read an empty string as zeroes is // probably unintended; the reverse is supported just so all-zero buffers don't fail. return false; }
ByteBuffer byteBuffer = new ByteBuffer(); if (isAllZeroes(array, offset, length)) {