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

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

Introduction

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

Prototype

public static long fromByteArray(byte[] bytes) 

Source Link

Document

Returns the long value whose big-endian representation is stored in the first 8 bytes of bytes ; equivalent to ByteBuffer.wrap(bytes).getLong() .

Usage

From source file:ws.moor.swissvault.util.Obfuscator.java

public long unobfuscateLong(String obfuscated) {
    try {/*w ww  . j ava 2  s.  c  om*/
        Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, secret);
        return Longs.fromByteArray(cipher.doFinal(encoding.decode(obfuscated)));
    } catch (Exception e) {
        throw new RuntimeException(obfuscated, e);
    }
}

From source file:com.heliosapm.streams.serialization.TimeValuePairSerde.java

/**
 * {@inheritDoc}/*from ww  w  .j a  v  a  2s. c  om*/
 * @see org.apache.kafka.common.serialization.Deserializer#deserialize(java.lang.String, byte[])
 */
@Override
public long[] deserialize(final String topic, final byte[] data) {
    final long[] pair = new long[2];
    byte[] b = new byte[8];
    System.arraycopy(data, 0, b, 0, 8);
    pair[0] = Longs.fromByteArray(b);
    System.arraycopy(data, 8, b, 0, 8);
    pair[1] = Longs.fromByteArray(b);
    return pair;
}

From source file:org.apache.drill.exec.store.parquet.decimal.Int64DecimalParquetValueWriter.java

@Override
public void writeValue(RecordConsumer consumer, DrillBuf buffer, int start, int end, int precision) {
    byte[] output;
    int startPos;
    int length = end - start;
    startPos = Longs.BYTES - length;// w w  w  . j a  va  2 s.  c o  m
    output = new byte[Longs.BYTES];
    if (startPos > 0) {
        buffer.getBytes(start, output, startPos, length);
        if (output[startPos] < 0) {
            Arrays.fill(output, 0, output.length - length, (byte) -1);
        }
    } else {
        // in this case value from FIXED_LEN_BYTE_ARRAY or BINARY field was taken, ignore leading bytes
        buffer.getBytes(start - startPos, output, 0, length + startPos);
    }
    consumer.addLong(Longs.fromByteArray(output));
}

From source file:com.spotify.folsom.client.binary.IncrRequest.java

@Override
public void handle(final BinaryResponse replies) throws IOException {
    final ResponsePacket reply = handleSingleReply(replies);

    if (reply.status == MemcacheStatus.OK) {
        succeed(Longs.fromByteArray(reply.value));
    } else if (reply.status == MemcacheStatus.KEY_NOT_FOUND) {
        succeed(null);/*from   w ww . jav a2  s. co  m*/
    } else {
        throw new IOException("Unexpected response: " + reply.status);
    }
}

From source file:com.heliosapm.streams.serialization.TimeWindowLongValueSerde.java

/**
 * {@inheritDoc}/*  www.jav a 2  s.c o m*/
 * @see org.apache.kafka.common.serialization.Deserializer#deserialize(java.lang.String, byte[])
 */
@Override
public long[] deserialize(final String topic, final byte[] data) {
    if (data == null)
        throw new IllegalArgumentException("The passed data was null");
    if (data.length != 24)
        throw new IllegalArgumentException(
                "The passed data length was expected to be 24 but was [" + data.length + "]");
    final long[] triplet = new long[3];
    byte[] b = new byte[8];
    System.arraycopy(data, 0, b, 0, 8);
    triplet[0] = Longs.fromByteArray(b);
    System.arraycopy(data, 8, b, 0, 8);
    triplet[1] = Longs.fromByteArray(b);
    System.arraycopy(data, 16, b, 0, 8);
    triplet[2] = Longs.fromByteArray(b);
    return triplet;
}

From source file:Model.PeerDiscovery.java

private void listen() {
    byte[] buffer;
    boolean exists = false;
    while (run) {
        connect();/* www . j av a2  s  .c o m*/
        try {
            buffer = new byte[256];
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

            while (!serverSocket.isClosed()) {
                serverSocket.receive(packet);
                p = new PeerNode(packet.getAddress().getHostAddress());
                exists = localPeerNode.addPeerNode(p, buffer);
                if (exists && (Longs.fromByteArray(packet.getData()) == 999999)) {
                    System.out.println("Received P2P removal request");
                    localPeerNode.removePeerNode(p);
                }
                //                    buffer = null;
            }
        } catch (IOException ex) {
            Logger.getLogger(PeerNode.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:io.warp10.script.functions.RUNNERNONCE.java

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
    Object o = stack.pop();//w w w . j  av a 2s  . c  o m

    if (!(o instanceof String)) {
        throw new WarpScriptException(getName() + " expects a String.");
    }

    synchronized (RUNNERNONCE.class) {
        if (null == runnerPSK) {
            try {
                runnerPSK = WarpDist.getKeyStore().getKey(KeyStore.AES_RUNNER_PSK);
            } catch (Throwable t) {
                // Catch NoClassDefFoundError
            }
        }
    }

    if (null != runnerPSK) {
        // Unwrap the blob
        byte[] wrapped = OrderPreservingBase64.decode(o.toString().getBytes(Charsets.US_ASCII));
        byte[] raw = CryptoHelper.unwrapBlob(runnerPSK, wrapped);

        if (null == raw) {
            throw new WarpScriptException(getName() + " invalid runner nonce.");
        }
        stack.push(Longs.fromByteArray(raw));
    } else {
        stack.push(null);
    }

    return stack;
}

From source file:com.nec.strudel.tkvs.store.hbase.HBaseTransaction.java

public HBaseTransaction(String gName, Key gKey, byte[] rowid, HTableInterface table, TransactionProfiler prof)
        throws IOException {
    super(gName, gKey, new HBaseReader(table, rowid), prof);
    this.rowid = rowid;
    //Get version number
    Get get = new Get(rowid);
    get.addColumn(HBaseStore.VERSIONCF, HBaseStore.VERQUALIFIER);
    Result res = table.get(get);/*from  w w w.j  a  va2 s . co m*/
    this.vnum = res.isEmpty() ? 0L : Longs.fromByteArray(res.value());
    this.htable = table;

    this.gName = gName;
    this.prof = prof;
}

From source file:com.subitarius.domain.License.java

public boolean validate() throws IOException {
    Iterator<NetworkInterface> i1 = Iterators.forEnumeration(NetworkInterface.getNetworkInterfaces());
    while (i1.hasNext()) {
        NetworkInterface iface = i1.next();
        byte[] macBytes = new byte[8];
        System.arraycopy(iface.getHardwareAddress(), 0, macBytes, 2, 6);
        long mac = Longs.fromByteArray(macBytes);
        if (macAddresses.contains(mac)) {
            return true;
        }/*from   w ww  .  ja v a2s .co  m*/
    }
    return false;
}

From source file:com.github.games647.flexiblelogin.Account.java

public Account(ResultSet resultSet) throws SQLException {
    //uuid in binary format
    byte[] uuidBytes = resultSet.getBytes(2);

    byte[] mostBits = ArrayUtils.subarray(uuidBytes, 0, 8);
    byte[] leastBits = ArrayUtils.subarray(uuidBytes, 8, 16);

    long mostByte = Longs.fromByteArray(mostBits);
    long leastByte = Longs.fromByteArray(leastBits);

    this.uuid = new UUID(mostByte, leastByte);
    this.username = resultSet.getString(3);
    this.passwordHash = resultSet.getString(4);

    this.ip = resultSet.getBytes(5);
    this.timestamp = resultSet.getTimestamp(6);

    this.email = resultSet.getString(7);
}