Search in sources :

Example 6 with ByteOrder

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);
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 7 with ByteOrder

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);
}
Also used : ByteOrder(java.nio.ByteOrder) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with 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;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 9 with ByteOrder

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;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 10 with ByteOrder

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();
    }
}
Also used : ByteOrder(java.nio.ByteOrder)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2