List of usage examples for com.google.common.primitives Shorts BYTES
int BYTES
To view the source code for com.google.common.primitives Shorts BYTES.
Click Source Link
From source file:org.apache.kylin.common.util.BytesUtil.java
public static byte[] writeShort(short num) { byte[] output = new byte[Shorts.BYTES]; writeShort(num, output, 0, output.length); return output; }
From source file:net.bither.xrandom.audio.AmplitudeData.java
public AmplitudeData(byte[] rawData) { if (rawData == null) { amplitude = 0;/* w ww. j a va 2 s . com*/ return; } int step = rawData.length / Shorts.BYTES / sampleCount; int count = 0; double sum = 0; for (int i = 0; i < rawData.length - Shorts.BYTES; i += step) { byte[] bytes = new byte[Shorts.BYTES]; for (int j = 0; j < Shorts.BYTES; j++) { bytes[j] = rawData[i + j]; } short s = Shorts.fromByteArray(bytes); sum += s * s; count++; } amplitude = (int) Math.sqrt(sum / count); }
From source file:org.apache.kylin.common.util.BytesUtil.java
public static short readShort(byte[] bytes) { return (short) readShort(bytes, 0, Shorts.BYTES); }
From source file:com.yandex.yoctodb.util.UnsignedByteArrays.java
public static short toShort(@NotNull final UnsignedByteArray bytes) { if (bytes.length() != Shorts.BYTES) throw new IllegalArgumentException("Wrong length"); return (short) (Shorts.fromByteArray(bytes.data) ^ Short.MIN_VALUE); }
From source file:tachyon.network.protocol.RPCErrorResponse.java
@Override public int getEncodedLength() { // 1 short (mStatus) return Shorts.BYTES; }
From source file:org.kududb.Type.java
/** * Gives the size in bytes for a given DataType, as per the pb specification * @param type pb type//w w w .j a v a2 s.com * @return size in bytes */ static int getTypeSize(DataType type) { switch (type) { case STRING: case BINARY: return 8 + 8; // offset then string length case BOOL: case INT8: return 1; case INT16: return Shorts.BYTES; case INT32: case FLOAT: return Ints.BYTES; case INT64: case DOUBLE: case TIMESTAMP: return Longs.BYTES; default: throw new IllegalArgumentException("The provided data type doesn't map" + " to know any known one."); } }
From source file:org.apache.kudu.Type.java
/** * Gives the size in bytes for a given DataType, as per the pb specification * @param type pb type// w ww. j a v a 2 s.com * @return size in bytes */ static int getTypeSize(DataType type) { switch (type) { case STRING: case BINARY: return 8 + 8; // offset then string length case BOOL: case INT8: return 1; case INT16: return Shorts.BYTES; case INT32: case FLOAT: return Ints.BYTES; case INT64: case DOUBLE: case UNIXTIME_MICROS: return Longs.BYTES; default: throw new IllegalArgumentException("The provided data type doesn't map" + " to know any known one."); } }
From source file:io.druid.segment.data.CompressedVSizeIntsIndexedSupplier.java
private static int bufferPadding(int numBytes) { // when numBytes == 3 we need to pad the buffer to allow reading an extra byte // beyond the end of the last value, since we use buffer.getInt() to read values. // for numBytes 1, 2 we remove the need for padding by reading bytes or shorts directly. switch (numBytes) { case Shorts.BYTES: case 1:/* ww w . j a v a 2 s . c o m*/ return 0; default: return Ints.BYTES - numBytes; } }
From source file:tachyon.network.protocol.RPCBlockResponse.java
@Override public int getEncodedLength() { // TODO: adjust the length when client also uses netty. // 3 longs (mBLockId, mOffset, mLength) + 1 short (DATA_SERVER_REQUEST_MESSAGE) return Longs.BYTES * 3 + Shorts.BYTES; }
From source file:alluxio.network.protocol.RPCFileWriteResponse.java
@Override public int getEncodedLength() { // 3 longs (mTempUfsFileId, mOffset, mLength) + 1 short (mStatus) return Longs.BYTES * 3 + Shorts.BYTES; }