/** * @param t operands * @return Array of byte arrays made from passed array of Text */ public static byte [][] toByteArrays(final String [] t) { byte [][] result = new byte[t.length][]; for (int i = 0; i < t.length; i++) { result[i] = Bytes.toBytes(t[i]); } return result; }
private static boolean isNullText(byte[] val, int offset, int length, byte[] nullBytes) { return length > 0 && length == nullBytes.length && Bytes.equals(val, offset, length, nullBytes, 0, nullBytes.length); } }
/** * Converts a byte array to a short value * @param bytes byte array * @return the short value */ public static short toShort(byte[] bytes) { return toShort(bytes, 0, SIZEOF_SHORT); }
/** * @param column operand * @return A byte array of a byte array where first and only entry is * <code>column</code> */ public static byte [][] toByteArrays(final String column) { return toByteArrays(toBytes(column)); }
/** * Convert a BigDecimal value to a byte array * * @param val * @return the byte array */ public static byte[] toBytes(BigDecimal val) { byte[] valueBytes = val.unscaledValue().toByteArray(); byte[] result = new byte[valueBytes.length + SIZEOF_INT]; int offset = putInt(result, 0, val.scale()); putBytes(result, offset, valueBytes, 0, valueBytes.length); return result; }
/** * Converts the given byte buffer to a printable representation, * from the index 0 (inclusive) to the limit (exclusive), * regardless of the current position. * The position and the other index parameters are not changed. * * @param buf a byte buffer * @return a string representation of the buffer's binary contents * @see #toBytes(ByteBuffer) * @see #getBytes(ByteBuffer) */ public static String toStringBinary(ByteBuffer buf) { if (buf == null) return "null"; if (buf.hasArray()) { return toStringBinary(buf.array(), buf.arrayOffset(), buf.limit()); } return toStringBinary(toBytes(buf)); }
case INT1: case INT2: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt2(Bytes.toShort(bytes)); break; case INT4: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt4(Bytes.toInt(bytes)); break; case INT8: } else { if (bytes.length == 4) { datum = DatumFactory.createInt8(Bytes.toInt(bytes)); } else { datum = bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt8(Bytes.toLong(bytes)); datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat4(Bytes.toFloat(bytes)); break; case FLOAT8: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat8(Bytes.toDouble(bytes)); break; case TEXT:
datum = DatumFactory.createInt2(Bytes.toShort(bytes, offset, length)); break; case INT4: datum = DatumFactory.createInt4((int) Bytes.readVLong(bytes, offset)); break; case INT8: datum = DatumFactory.createInt8(Bytes.readVLong(bytes, offset)); break; case FLOAT4: System.arraycopy(bytes, offset, chars, 0, length); if (Bytes.equals(INVALID_UTF__SINGLE_BYTE, chars)) { datum = DatumFactory.createText(new byte[0]); } else {
byte [] bPadded; if (a.length < b.length) { aPadded = padTail(a, b.length - a.length); bPadded = b; } else if (b.length < a.length) { aPadded = a; bPadded = padTail(b, a.length - b.length); } else { aPadded = a; bPadded = b; if (compareTo(aPadded,bPadded) >= 0) { throw new IllegalArgumentException("b <= a"); final BigInteger startBI = new BigInteger(add(prependHeader, aPadded)); final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded)); BigInteger diffBI = stopBI.subtract(startBI); if (inclusive) {
/** * Converts a byte array to a long value. Reverses * {@link #toBytes(long)} * @param bytes array * @return the long value */ public static long toLong(byte[] bytes) { return toLong(bytes, 0, SIZEOF_LONG); }
HRegionLocation location = htable.getRegionLocation(tableRange.getFirst()[i], false); if (location == null) { throw new IOException("Can't find the region of the key: " + Bytes.toStringBinary(tableRange.getFirst()[i])); byte[] stopRow = selectedRange.getSecond().get(j); if ((startRow.length == 0 || regionStopKey.length == 0 || Bytes.compareTo(startRow, regionStopKey) < 0) && (stopRow.length == 0 || Bytes.compareTo(stopRow, regionStartKey) > 0)) { final byte[] fragmentStart = (startRow.length == 0 || Bytes.compareTo(regionStartKey, startRow) >= 0) ? regionStartKey : startRow; final byte[] fragmentStop = (stopRow.length == 0 || Bytes.compareTo(regionStopKey, stopRow) <= 0) && regionStopKey.length > 0 ? regionStopKey : stopRow; if (Bytes.compareTo(fragmentStart, prevFragment.getStartRow()) < 0) { prevFragment.setStartRow(fragmentStart); if (Bytes.compareTo(fragmentStop, prevFragment.getStopRow()) > 0) { prevFragment.setStopRow(fragmentStop);
return true; Bytes.putInt(candidateBytesVal, 0, candidateIntVal); return Bytes.compareTo(mergedRange.getEnd().getBytes(colId), candidateBytesVal) < 0; } else { candidateIntVal = tuple.getInt4(i) - incDecimal.intValue(); return true; Bytes.putInt(candidateBytesVal, 0, candidateIntVal); return Bytes.compareTo(candidateBytesVal, mergedRange.getEnd().getBytes(colId)) < 0;
@Override public int compare(byte [] left, byte [] right) { return compareTo(left, right); } @Override
/** * @param a array * @param length new array size * @return Value in <code>a</code> plus <code>length</code> prepended 0 bytes */ public static byte [] padHead(final byte [] a, final int length) { byte [] padding = new byte[length]; for (int i = 0; i < length; i++) { padding[i] = 0; } return add(padding,a); }
/** * @param bytes byte array * @param offset offset to write to * @param f float value * @return New offset in <code>bytes</code> */ public static int putFloat(byte [] bytes, int offset, float f) { return putInt(bytes, offset, Float.floatToRawIntBits(f)); }
/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes byte array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes) { return toFloat(bytes, 0); }
/** * @param bytes byte array * @return Return double made from passed bytes. */ public static double toDouble(final byte [] bytes) { return toDouble(bytes, 0); }
case INT1: case INT2: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt2(Bytes.toShort(bytes)); break; case INT4: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt4(Bytes.toInt(bytes)); break; case INT8: } else { if (bytes.length == 4) { datum = DatumFactory.createInt8(Bytes.toInt(bytes)); } else { datum = bytes.length == 0 ? NullDatum.get() : DatumFactory.createInt8(Bytes.toLong(bytes)); datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat4(Bytes.toFloat(bytes)); break; case FLOAT8: datum = bytes == null || bytes.length == 0 ? NullDatum.get() : DatumFactory.createFloat8(Bytes.toDouble(bytes)); break; case TEXT:
datum = DatumFactory.createInt2(Bytes.toShort(bytes, offset, length)); break; case INT4: datum = DatumFactory.createInt4((int) Bytes.readVLong(bytes, offset)); break; case INT8: datum = DatumFactory.createInt8(Bytes.readVLong(bytes, offset)); break; case FLOAT4: System.arraycopy(bytes, offset, chars, 0, length); if (Bytes.equals(INVALID_UTF__SINGLE_BYTE, chars)) { datum = DatumFactory.createText(new byte[0]); } else {
/** * Converts the given byte buffer to a printable representation, * from the index 0 (inclusive) to the limit (exclusive), * regardless of the current position. * The position and the other index parameters are not changed. * * @param buf a byte buffer * @return a string representation of the buffer's binary contents * @see #toBytes(ByteBuffer) * @see #getBytes(ByteBuffer) */ public static String toStringBinary(ByteBuffer buf) { if (buf == null) return "null"; if (buf.hasArray()) { return toStringBinary(buf.array(), buf.arrayOffset(), buf.limit()); } return toStringBinary(toBytes(buf)); }