Java Code Examples for com.google.common.primitives.Shorts#BYTES

The following examples show how to use com.google.common.primitives.Shorts#BYTES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmplitudeData.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public AmplitudeData(byte[] rawData) {
    if (rawData == null) {
        amplitude = 0;
        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);
}
 
Example 2
Source File: MemcachedChunkingCache.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
protected static int getValueSplit(MemcachedCacheConfig config, String keyS, int valueBLen) {
    // the number 6 means the chunk number size never exceeds 6 bytes
    final int valueSize = config.getMaxObjectSize() - Shorts.BYTES - Ints.BYTES
            - keyS.getBytes(Charsets.UTF_8).length - 6;
    final int maxValueSize = config.getMaxChunkSize() * valueSize;
    Preconditions.checkArgument(valueBLen <= maxValueSize,
            "the value bytes length [%d] exceeds maximum value size [%d]", valueBLen, maxValueSize);
    return (valueBLen - 1) / valueSize + 1;
}
 
Example 3
Source File: ResultSetUtil.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private static Object convertByteArrayValue(final Object value, final Class<?> convertType) {
    byte[] bytesValue = (byte[]) value;
    switch (bytesValue.length) {
        case 1:
            return convertNumberValue(bytesValue[0], convertType);
        case Shorts.BYTES:
            return convertNumberValue(Shorts.fromByteArray(bytesValue), convertType);
        case Ints.BYTES:
            return convertNumberValue(Ints.fromByteArray(bytesValue), convertType);
        case Longs.BYTES:
            return convertNumberValue(Longs.fromByteArray(bytesValue), convertType);
        default:
            return value;
    }
}
 
Example 4
Source File: BytesUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static byte[] writeShort(short num) {
    byte[] output = new byte[Shorts.BYTES];
    writeShort(num, output, 0, output.length);
    return output;
}