Java Code Examples for com.google.common.primitives.Longs.fromBytes()

The following are Jave code examples for showing how to use fromBytes() of the com.google.common.primitives.Longs class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: guava-mock   File: LittleEndianByteArray.java   Source Code and License Vote up 5 votes
@Override
public long getLongLittleEndian(byte[] source, int offset) {
  return Longs.fromBytes(
      source[offset + 7],
      source[offset + 6],
      source[offset + 5],
      source[offset + 4],
      source[offset + 3],
      source[offset + 2],
      source[offset + 1],
      source[offset]);
}
 
Example 2
Project: guava-mock   File: LittleEndianDataInputStream.java   Source Code and License Vote up 5 votes
/**
 * Reads a {@code long} as specified by {@link DataInputStream#readLong()}, except using
 * little-endian byte order.
 *
 * @return the next eight bytes of the input stream, interpreted as a {@code long} in
 *     little-endian byte order
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // to skip some bytes
@Override
public long readLong() throws IOException {
  byte b1 = readAndCheckByte();
  byte b2 = readAndCheckByte();
  byte b3 = readAndCheckByte();
  byte b4 = readAndCheckByte();
  byte b5 = readAndCheckByte();
  byte b6 = readAndCheckByte();
  byte b7 = readAndCheckByte();
  byte b8 = readAndCheckByte();

  return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
}
 
Example 3
Project: googles-monorepo-demo   File: LittleEndianByteArray.java   Source Code and License Vote up 5 votes
@Override
public long getLongLittleEndian(byte[] source, int offset) {
  return Longs.fromBytes(
      source[offset + 7],
      source[offset + 6],
      source[offset + 5],
      source[offset + 4],
      source[offset + 3],
      source[offset + 2],
      source[offset + 1],
      source[offset]);
}
 
Example 4
Project: googles-monorepo-demo   File: LittleEndianDataInputStream.java   Source Code and License Vote up 5 votes
/**
 * Reads a {@code long} as specified by {@link DataInputStream#readLong()}, except using
 * little-endian byte order.
 *
 * @return the next eight bytes of the input stream, interpreted as a {@code long} in
 *     little-endian byte order
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // to skip some bytes
@Override
public long readLong() throws IOException {
  byte b1 = readAndCheckByte();
  byte b2 = readAndCheckByte();
  byte b3 = readAndCheckByte();
  byte b4 = readAndCheckByte();
  byte b5 = readAndCheckByte();
  byte b6 = readAndCheckByte();
  byte b7 = readAndCheckByte();
  byte b8 = readAndCheckByte();

  return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
}
 
Example 5
Project: Cobweb   File: DirectDiskUrlFilter.java   Source Code and License Vote up 4 votes
private long lowerEight(byte[] bytes) {
    return Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]);
}
 
Example 6
Project: Cobweb   File: DirectDiskUrlFilter.java   Source Code and License Vote up 4 votes
private long upperEight(byte[] bytes) {
    return Longs.fromBytes(bytes[15], bytes[14], bytes[13], bytes[12], bytes[11], bytes[10], bytes[9], bytes[8]);
}