Java Code Examples for com.google.common.primitives.Longs#fromBytes()
The following examples show how to use
com.google.common.primitives.Longs#fromBytes() .
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: Slice.java From hive-dwrf with Apache License 2.0 | 6 votes |
/** * Fill the slice with the specified value; */ public void fill(byte value) { int offset = 0; int length = size; long longValue = Longs.fromBytes(value, value, value, value, value, value, value, value); while (length >= SizeOf.SIZE_OF_LONG) { unsafe.putLong(base, address + offset, longValue); offset += SizeOf.SIZE_OF_LONG; length -= SizeOf.SIZE_OF_LONG; } while (length > 0) { unsafe.putByte(base, address + offset, value); offset++; length--; } }
Example 2
Source File: LittleEndianByteArray.java From zetasketch with Apache License 2.0 | 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 3
Source File: UUIDUtils.java From SonarPet with GNU General Public License v3.0 | 5 votes |
public static UUID fromBytes(byte[] bytes) { Preconditions.checkNotNull(bytes, "Null bytes"); Preconditions.checkArgument(bytes.length == 16, "Invalid length: %s", bytes.length); long msb = Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]); long lsb = Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); return new UUID(msb, lsb); }
Example 4
Source File: LittleEndianDataInputStream.java From LevelDb2Avnil with GNU General Public License v2.0 | 5 votes |
@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
Source File: LittleEndianByteArray.java From codebuff with BSD 2-Clause "Simplified" License | 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 6
Source File: ObjectFileScrubbers.java From buck with Apache License 2.0 | 5 votes |
public static long getLittleEndianLong(ByteBuffer buffer) { byte b1 = buffer.get(); byte b2 = buffer.get(); byte b3 = buffer.get(); byte b4 = buffer.get(); byte b5 = buffer.get(); byte b6 = buffer.get(); byte b7 = buffer.get(); byte b8 = buffer.get(); return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1); }
Example 7
Source File: LittleEndianDataInputStream.java From codebuff with BSD 2-Clause "Simplified" License | 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 8
Source File: LittleEndianByteArray.java From codebuff with BSD 2-Clause "Simplified" License | 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 9
Source File: ShortTermDuplicateMemory.java From divolte-collector with Apache License 2.0 | 5 votes |
private boolean isProbablyDuplicate(final HashCode eventDigest) { // Our hashing algorithm produces 8 bytes: // 0: slot[0] // 1: slot[1] // 2: slot[2] // 3: slot[3] // 4: // 5: // 6: // 7: // 8: signature[0] // 9: .. // 10: .. // 11: .. // 12: .. // 13: .. // 14: .. // 15: signature[7] final byte[] hashBytes = eventDigest.asBytes(); // We use the low int for the slot. final int slotSelector = Ints.fromBytes(hashBytes[0], hashBytes[1], hashBytes[2], hashBytes[3]); // We use the high long for the signature. final long signature = Longs.fromBytes(hashBytes[8], hashBytes[9], hashBytes[10], hashBytes[11], hashBytes[12], hashBytes[13], hashBytes[14], hashBytes[15]); final int slot = (slotSelector & Integer.MAX_VALUE) % memory.length; final boolean result = memory[slot] == signature; memory[slot] = signature; return result; }
Example 10
Source File: LocalNoteList.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public LocalNoteCoordinate(final byte[] bytes, final LocalNoteList parentList) { parent_ = parentList; if (bytes.length >= BUFFER_SIZE) { this.x = Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]); this.y = Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); } else { throw new IllegalArgumentException("Can't construct new LocalNoteCoordinate from byte length of " + bytes.length); } }
Example 11
Source File: NoteCoordinate.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public static String getUnidFromBytes(final byte[] bytes) { if (bytes.length >= 16) { long first = Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]); long last = Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); return getUnidFromLongs(first, last); } else { //TODO NTF Something here... throw new IllegalArgumentException("Cannot convert a byte array of length " + bytes.length + " to a unid"); } }
Example 12
Source File: LittleEndianDataInputStream.java From codebuff with BSD 2-Clause "Simplified" License | 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 13
Source File: JaegerExporterHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
private long traceIdLow() { return Longs.fromBytes( traceIdBuffer[8], traceIdBuffer[9], traceIdBuffer[10], traceIdBuffer[11], traceIdBuffer[12], traceIdBuffer[13], traceIdBuffer[14], traceIdBuffer[15]); }
Example 14
Source File: JaegerExporterHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
private long traceIdHigh() { return Longs.fromBytes( traceIdBuffer[0], traceIdBuffer[1], traceIdBuffer[2], traceIdBuffer[3], traceIdBuffer[4], traceIdBuffer[5], traceIdBuffer[6], traceIdBuffer[7]); }
Example 15
Source File: NoteCoordinate.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@Override public void readExternal(final ObjectInput arg0) throws IOException, ClassNotFoundException { byte[] bytes = extreadbuffer_.get(); arg0.read(bytes); this.db = Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]); this.x = Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); this.y = Longs.fromBytes(bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23]); }
Example 16
Source File: LittleEndianByteArray.java From codebuff with BSD 2-Clause "Simplified" License | 4 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 17
Source File: IndexTagCalc.java From CuckooFilter4J with Apache License 2.0 | 4 votes |
private long longFromLowBytes(byte[] bytes) { return Longs.fromBytes(bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); }
Example 18
Source File: IndexTagCalc.java From CuckooFilter4J with Apache License 2.0 | 4 votes |
private long longFromHighBytes(byte[] bytes) { return Longs.fromBytes(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]); }
Example 19
Source File: HDFSStorage.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
/** * @param b * @param startIndex * @return */ long byteArrayToLong(byte[] b, int startIndex) { final byte b1 = 0; return Longs.fromBytes(b1, b1, b1, b1, b[3 + startIndex], b[2 + startIndex], b[1 + startIndex], b[startIndex]); }
Example 20
Source File: Bytes.java From hivemq-community-edition with Apache License 2.0 | 3 votes |
/** * Read a serialized long value for a given byte array * * @param buffer A byte array that contains the serialized long value to read. * @param startPosition The position of the first bit of the long value in the buffer * @return The next 8 bits from startPosition as long * @throws IllegalArgumentException if the buffer is to small to read a long value from the start position */ public static long readLong(final byte[] buffer, final int startPosition) { if (startPosition + Long.BYTES > buffer.length) { throw new IllegalArgumentException("The provided array[" + buffer.length + "] is to small to read 8 bytes from start position " + startPosition); } return Longs.fromBytes(buffer[startPosition], buffer[startPosition + 1], buffer[startPosition + 2], buffer[startPosition + 3], buffer[startPosition + 4], buffer[startPosition + 5], buffer[startPosition + 6], buffer[startPosition + 7]); }