private void checkAuths() { Set<ByteSequence> sortedAuths = new TreeSet<ByteSequence>(auths); for (ByteSequence bs : sortedAuths) { if (bs.length() == 0) { throw new IllegalArgumentException("Empty authorization"); } authsList.add(bs.toArray()); } }
/** * Compares the two given byte sequences, byte by byte, returning a negative, * zero, or positive result if the first sequence is less than, equal to, or * greater than the second. The comparison is performed starting with the * first byte of each sequence, and proceeds until a pair of bytes differs, * or one sequence runs out of byte (is shorter). A shorter sequence is * considered less than a longer one. * * @param bs1 first byte sequence to compare * @param bs2 second byte sequence to compare * @return comparison result */ public static int compareBytes(ByteSequence bs1, ByteSequence bs2) { int minLen = Math.min(bs1.length(), bs2.length()); for (int i = 0; i < minLen; i++) { int a = (bs1.byteAt(i) & 0xff); int b = (bs2.byteAt(i) & 0xff); if (a != b) { return a - b; } } return bs1.length() - bs2.length(); }
/** * Compares the two given byte sequences, byte by byte, returning a negative, * zero, or positive result if the first sequence is less than, equal to, or * greater than the second. The comparison is performed starting with the * first byte of each sequence, and proceeds until a pair of bytes differs, * or one sequence runs out of byte (is shorter). A shorter sequence is * considered less than a longer one. * * @param bs1 first byte sequence to compare * @param bs2 second byte sequence to compare * @return comparison result */ public static int compareBytes(ByteSequence bs1, ByteSequence bs2) { int minLen = Math.min(bs1.length(), bs2.length()); for (int i = 0; i < minLen; i++) { int a = (bs1.byteAt(i) & 0xff); int b = (bs2.byteAt(i) & 0xff); if (a != b) { return a - b; } } return bs1.length() - bs2.length(); }
private void checkAuths() { Set<ByteSequence> sortedAuths = new TreeSet<ByteSequence>(auths); for (ByteSequence bs : sortedAuths) { if (bs.length() == 0) { throw new IllegalArgumentException("Empty authorization"); } authsList.add(bs.toArray()); } }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }