List of usage examples for org.apache.hadoop.io WritableUtils isNegativeVInt
public static boolean isNegativeVInt(byte value)
From source file:cn.iie.haiep.hbase.value.Bytes.java
License:Apache License
/** * @param buffer buffer to convert/*from www .ja va2s . c o m*/ * @return vint bytes as an integer. */ public static long bytesToVint(final byte[] buffer) { int offset = 0; byte firstByte = buffer[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset++]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
From source file:cn.iie.haiep.hbase.value.Bytes.java
License:Apache License
/** * Reads a zero-compressed encoded long from input stream and returns it. * @param buffer Binary array//ww w .ja v a 2 s. c om * @param offset Offset into array at which vint begins. * @throws java.io.IOException e * @return deserialized long from stream. */ public static long readVLong(final byte[] buffer, final int offset) throws IOException { byte firstByte = buffer[offset]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); }
From source file:com.chinamobile.bcbsp.util.Bytes.java
License:Apache License
/** * Converts a byte array to a long./*from w w w.j a v a 2s . c o m*/ * * @param buffer * buffer to convert * @return vint bytes as an integer. */ public static long bytesToVint(final byte[] buffer) { int offset = 0; byte firstByte = buffer[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset++]; i = i << 8; i = i | (b & 0xFF); } return WritableUtils.isNegativeVInt(firstByte) ? ~i : i; }
From source file:com.chinamobile.bcbsp.util.Bytes.java
License:Apache License
/** * Reads a zero-compressed encoded long from input stream and returns it. * * @param buffer// w w w.j av a2 s .c o m * Binary array * @param offset * Offset into array at which vint begins. * @throws java.io.IOException * e * @return deserialized long from stream. */ public static long readVLong(final byte[] buffer, final int offset) throws IOException { byte firstByte = buffer[offset]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } return WritableUtils.isNegativeVInt(firstByte) ? ~i : i; }
From source file:com.facebook.presto.hive.ColumnarBinaryHiveRecordCursor.java
License:Apache License
private void parseLongColumn(int column, byte[] bytes, int start, int length) { if (length == 0) { nulls[column] = true;/*from w w w .j a va 2 s.c om*/ return; } nulls[column] = false; switch (hiveTypes[column]) { case SHORT: // the file format uses big endian checkState(length == SIZE_OF_SHORT, "Short should be 2 bytes"); longs[column] = Short.reverseBytes(ByteArrays.getShort(bytes, start)); break; case TIMESTAMP: checkState(length >= 1, "Timestamp should be at least 1 byte"); long seconds = TimestampWritable.getSeconds(bytes, start); long nanos = TimestampWritable.getNanos(bytes, start + SIZE_OF_INT); longs[column] = (seconds * 1000) + (nanos / 1_000_000); break; case BYTE: checkState(length == 1, "Byte should be 1 byte"); longs[column] = bytes[start]; break; case INT: checkState(length >= 1, "Int should be at least 1 byte"); if (length == 1) { longs[column] = bytes[start]; } else { int value = 0; for (int i = 1; i < length; i++) { value <<= 8; value |= (bytes[start + i] & 0xFF); } longs[column] = WritableUtils.isNegativeVInt(bytes[start]) ? ~value : value; } break; case LONG: checkState(length >= 1, "Long should be at least 1 byte"); if (length == 1) { longs[column] = bytes[start]; } else { long value = 0; for (int i = 1; i < length; i++) { value <<= 8; value |= (bytes[start + i] & 0xFF); } longs[column] = WritableUtils.isNegativeVInt(bytes[start]) ? ~value : value; } break; default: throw new RuntimeException(String.format("%s is not a valid LONG type", hiveTypes[column])); } }
From source file:com.facebook.presto.hive.rcfile.RcBinaryBlockLoader.java
License:Apache License
private static long readVInt(byte[] bytes, int start, int length) { long value = 0; for (int i = 1; i < length; i++) { value <<= 8;/* w ww . java 2 s. co m*/ value |= (bytes[start + i] & 0xFF); } return WritableUtils.isNegativeVInt(bytes[start]) ? ~value : value; }
From source file:edu.uci.ics.hivesterix.serde.lazy.LazyUtils.java
License:Apache License
/** * Reads a zero-compressed encoded long from a byte array and returns it. * /* ww w. jav a 2 s . co m*/ * @param bytes * the byte array * @param offset * offset of the array to read from * @param vlong * storing the deserialized long and its size in byte */ public static void readVLong(byte[] bytes, int offset, VLong vlong) { byte firstByte = bytes[offset]; vlong.length = (byte) WritableUtils.decodeVIntSize(firstByte); if (vlong.length == 1) { vlong.value = firstByte; return; } long i = 0; for (int idx = 0; idx < vlong.length - 1; idx++) { byte b = bytes[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } vlong.value = (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
From source file:edu.uci.ics.hivesterix.serde.lazy.LazyUtils.java
License:Apache License
/** * Reads a zero-compressed encoded int from a byte array and returns it. * /* w w w . ja va 2 s . c o m*/ * @param bytes * the byte array * @param offset * offset of the array to read from * @param vInt * storing the deserialized int and its size in byte */ public static void readVInt(byte[] bytes, int offset, VInt vInt) { byte firstByte = bytes[offset]; vInt.length = (byte) WritableUtils.decodeVIntSize(firstByte); if (vInt.length == 1) { vInt.value = firstByte; return; } int i = 0; for (int idx = 0; idx < vInt.length - 1; idx++) { byte b = bytes[offset + 1 + idx]; i = i << 8; i = i | (b & 0xFF); } vInt.value = (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1) : i); }
From source file:org.apache.gora.util.ByteUtils.java
License:Apache License
/** * @param buffer//www .ja v a2 s . co m * @return vint bytes as an integer. */ public static long bytesToVlong(final byte[] buffer) { int offset = 0; byte firstByte = buffer[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset++]; i = i << 8; i = i | (b & 0xFF); } return (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }
From source file:org.apache.gora.util.ByteUtils.java
License:Apache License
/** * @param buffer/*w w w. j av a 2 s.co m*/ * @return vint bytes as an integer. */ public static int bytesToVint(final byte[] buffer) { int offset = 0; byte firstByte = buffer[offset++]; int len = WritableUtils.decodeVIntSize(firstByte); if (len == 1) { return firstByte; } long i = 0; for (int idx = 0; idx < len - 1; idx++) { byte b = buffer[offset++]; i = i << 8; i = i | (b & 0xFF); } return (int) (WritableUtils.isNegativeVInt(firstByte) ? (i ^ -1L) : i); }