Example usage for com.google.common.primitives Ints fromByteArray

List of usage examples for com.google.common.primitives Ints fromByteArray

Introduction

In this page you can find the example usage for com.google.common.primitives Ints fromByteArray.

Prototype

@GwtIncompatible("doesn't work")
public static int fromByteArray(byte[] bytes) 

Source Link

Document

Returns the int value whose big-endian representation is stored in the first 4 bytes of bytes ; equivalent to ByteBuffer.wrap(bytes).getInt() .

Usage

From source file:com.axiomine.largecollections.utils.SerDeUtils.java

public static int integerFromByteArray(byte[] bytes) {
    return Ints.fromByteArray(bytes);
}

From source file:io.druid.segment.SegmentUtils.java

public static int getVersionFromDir(File inDir) throws IOException {
    File versionFile = new File(inDir, "version.bin");
    if (versionFile.exists()) {
        return Ints.fromByteArray(Files.toByteArray(versionFile));
    }//from   w  w w. j a  va  2  s. c o  m

    final File indexFile = new File(inDir, "index.drd");
    int version;
    try (InputStream in = new FileInputStream(indexFile)) {
        version = in.read();
    }
    return version;
}

From source file:org.apache.druid.segment.SegmentUtils.java

public static int getVersionFromDir(File inDir) throws IOException {
    File versionFile = new File(inDir, "version.bin");
    if (versionFile.exists()) {
        return Ints.fromByteArray(Files.toByteArray(versionFile));
    }/*from   ww  w  . ja  v a 2s .  c om*/

    final File indexFile = new File(inDir, "index.drd");
    int version;
    if (indexFile.exists()) {
        try (InputStream in = new FileInputStream(indexFile)) {
            version = in.read();
        }
        return version;
    }

    throw new IOE("Invalid segment dir [%s]. Can't find either of version.bin or index.drd.", inDir);
}

From source file:com.sprogcoder.memory.MemoryUtils.java

public static int bytesToSignedInt(byte[] bytes) {
    byte[] byteCopy = Arrays.copyOf(bytes, bytes.length);
    Collections.reverse(Bytes.asList(byteCopy));

    return Ints.fromByteArray(byteCopy);
}

From source file:org.apache.hadoop.mapred.nativetask.testutil.BytesFactory.java

public static void updateObject(Writable obj, byte[] seed) {
    if (obj instanceof IntWritable) {
        ((IntWritable) obj).set(Ints.fromByteArray(seed));
    } else if (obj instanceof FloatWritable) {
        ((FloatWritable) obj).set(r.nextFloat());
    } else if (obj instanceof DoubleWritable) {
        ((DoubleWritable) obj).set(r.nextDouble());
    } else if (obj instanceof LongWritable) {
        ((LongWritable) obj).set(Longs.fromByteArray(seed));
    } else if (obj instanceof VIntWritable) {
        ((VIntWritable) obj).set(Ints.fromByteArray(seed));
    } else if (obj instanceof VLongWritable) {
        ((VLongWritable) obj).set(Longs.fromByteArray(seed));
    } else if (obj instanceof BooleanWritable) {
        ((BooleanWritable) obj).set(seed[0] % 2 == 1 ? true : false);
    } else if (obj instanceof Text) {
        ((Text) obj).set(BytesUtil.toStringBinary(seed));
    } else if (obj instanceof ByteWritable) {
        ((ByteWritable) obj).set(seed.length > 0 ? seed[0] : 0);
    } else if (obj instanceof BytesWritable) {
        ((BytesWritable) obj).set(seed, 0, seed.length);
    } else if (obj instanceof UTF8) {
        ((UTF8) obj).set(BytesUtil.toStringBinary(seed));
    } else if (obj instanceof MockValueClass) {
        ((MockValueClass) obj).set(seed);
    } else {/*ww  w . j  a v  a  2s. c o m*/
        throw new IllegalArgumentException("unknown writable: " + obj.getClass().getName());
    }
}

From source file:net.rauros.jzwave.core.messages.response.ZWMemoryGetID.java

public ZWMemoryGetID(Message rawMessage) {
    super(rawMessage);

    byte[] payload = getPayload();
    homeID = Ints.fromByteArray(payload);
    nodeID = payload[4];
}

From source file:org.onosproject.ipfix.packet.InformationElement.java

public static InformationElement parse(byte[] data) throws HeaderException {
    try {//from www  .  j  a  v a 2  s .c  o  m
        if (data.length < LENGTH) {
            throw new HeaderException("Data array too short.");
        }
        InformationElement ie = new InformationElement();
        // information element ID
        byte[] informationElementID = new byte[2];
        System.arraycopy(data, 0, informationElementID, 0, 2);
        ie.setInformationElementID(Ints.fromByteArray(informationElementID));
        // field length
        byte[] fieldLength = new byte[2];
        System.arraycopy(data, 2, fieldLength, 0, 2);
        ie.setFieldLength(Ints.fromByteArray(fieldLength));
        return ie;
    } catch (Exception e) {
        throw new HeaderException("Parse error: " + e.getMessage());
    }
}

From source file:com.yandex.yoctodb.util.UnsignedByteArrays.java

public static int toInt(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != Ints.BYTES)
        throw new IllegalArgumentException("Wrong length");

    return Ints.fromByteArray(bytes.data) ^ Integer.MIN_VALUE;
}

From source file:se.sics.kompics.simulator.network.identifier.impl.SocketId.java

@Override
public int partition(int nrPartitions) {
    int ip = Ints.fromByteArray(isa.getAddress().getAddress());
    return ip % nrPartitions;
}

From source file:org.voltdb.jni.Sha1Wrapper.java

@Override
public int hashCode() {
    return Ints.fromByteArray(hashBytes);
}