use of java.nio.ByteOrder in project disunity by ata4.
the class UnityGUID method write.
@Override
public void write(DataWriter out) throws IOException {
// write GUID as big-endian
ByteOrder order = out.order();
out.order(ByteOrder.BIG_ENDIAN);
out.writeLong(uuid.getMostSignificantBits());
out.writeLong(uuid.getLeastSignificantBits());
out.order(order);
}
use of java.nio.ByteOrder in project hazelcast by hazelcast.
the class EmptyObjectDataOutputTest method testEmptyMethodsDoNothing.
@Test
public void testEmptyMethodsDoNothing() throws IOException {
ByteOrder byteOrder = out.getByteOrder();
out.close();
assertEquals(ByteOrder.BIG_ENDIAN, byteOrder);
}
use of java.nio.ByteOrder in project jedis by xetorthio.
the class MurmurHash method hash64A.
public static long hash64A(ByteBuffer buf, int seed) {
ByteOrder byteOrder = buf.order();
buf.order(ByteOrder.LITTLE_ENDIAN);
long m = 0xc6a4a7935bd1e995L;
int r = 47;
long h = seed ^ (buf.remaining() * m);
long k;
while (buf.remaining() >= 8) {
k = buf.getLong();
k *= m;
k ^= k >>> r;
k *= m;
h ^= k;
h *= m;
}
if (buf.remaining() > 0) {
ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
// for big-endian version, do this first:
// finish.position(8-buf.remaining());
finish.put(buf).rewind();
h ^= finish.getLong();
h *= m;
}
h ^= h >>> r;
h *= m;
h ^= h >>> r;
buf.order(byteOrder);
return h;
}
use of java.nio.ByteOrder in project jedis by xetorthio.
the class MurmurHash method hash.
/**
* Hashes the bytes in a buffer from the current position to the limit.
* @param buf The bytes to hash.
* @param seed The seed for the hash.
* @return The 32 bit murmur hash of the bytes in the buffer.
*/
public static int hash(ByteBuffer buf, int seed) {
// save byte order for later restoration
ByteOrder byteOrder = buf.order();
buf.order(ByteOrder.LITTLE_ENDIAN);
int m = 0x5bd1e995;
int r = 24;
int h = seed ^ buf.remaining();
int k;
while (buf.remaining() >= 4) {
k = buf.getInt();
k *= m;
k ^= k >>> r;
k *= m;
h *= m;
h ^= k;
}
if (buf.remaining() > 0) {
ByteBuffer finish = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
// for big-endian version, use this first:
// finish.position(4-buf.remaining());
finish.put(buf).rewind();
h ^= finish.getInt();
h *= m;
}
h ^= h >>> 13;
h *= m;
h ^= h >>> 15;
buf.order(byteOrder);
return h;
}
use of java.nio.ByteOrder in project cassandra by apache.
the class SafeMemoryWriter method reallocate.
@Override
protected void reallocate(long count) {
long newCapacity = calculateNewSize(count);
if (newCapacity != capacity()) {
long position = length();
ByteOrder order = buffer.order();
SafeMemory oldBuffer = memory;
memory = this.memory.copy(newCapacity);
buffer = tailBuffer(memory);
int newPosition = (int) (position - tailOffset(memory));
buffer.position(newPosition);
buffer.order(order);
oldBuffer.free();
}
}
Aggregations