Example usage for java.nio ByteBuffer putInt

List of usage examples for java.nio ByteBuffer putInt

Introduction

In this page you can find the example usage for java.nio ByteBuffer putInt.

Prototype

public abstract ByteBuffer putInt(int value);

Source Link

Document

Writes the given int to the current position and increases the position by 4.

Usage

From source file:org.janusgraph.TestByteBuffer.java

private static long testByte() {
    LongObjectMap<ConcurrentSkipListSet<ByteEntry>> tx = new LongObjectHashMap<ConcurrentSkipListSet<ByteEntry>>(
            NUM);//w  ww.  ja va2 s  . co  m
    for (int i = 0; i < NUM; i++) {
        tx.put(i, new ConcurrentSkipListSet<ByteEntry>());
    }
    for (int i = 0; i < NUM; i++) {
        for (int j = 0; j < NUM; j++) {
            if (i == j)
                continue;
            if (Math.random() < FRACTION) {
                ByteBuffer key = ByteBuffer.allocate(16);
                key.putLong(5).putLong(j).flip();
                ByteBuffer value = ByteBuffer.allocate(4);
                value.putInt(random.nextInt(ROUNDSIZE)).flip();
                tx.get(i).add(new ByteEntry(key, value));
            }
        }
    }
    long time = System.currentTimeMillis();
    long sum = 0;
    for (int t = 0; t < TRIALS; t++) {
        for (int i = 0; i < NUM; i++) {
            for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) {
                sum += v.getId();
            }
        }
    }
    time = System.currentTimeMillis() - time;
    return time;
}

From source file:uk.ac.cam.cl.dtg.picky.parser.pcap2.PcapParser.java

private static void putUnsignedInt(ByteBuffer bb, long value) {
    bb.putInt((int) (value & 0xffffffffL));
}

From source file:com.buaa.cfs.common.oncrpc.XDR.java

static byte[] recordMark(int size, boolean last) {
    byte[] b = new byte[SIZEOF_INT];
    ByteBuffer buf = ByteBuffer.wrap(b);
    buf.putInt(!last ? size : size | 0x80000000);
    return b;//w ww  . j  ava2s .  c o  m
}

From source file:org.lic.ip.iplocator.IPv4RadixIntTree.java

private static long inet_aton(String ipStr) {
    try {//  w  w  w  .j a v  a2  s.  co m
        ByteBuffer bb = ByteBuffer.allocate(8);
        bb.putInt(0);
        bb.put(InetAddress.getByName(ipStr).getAddress());
        bb.rewind();
        return bb.getLong();
    } catch (UnknownHostException e) {
        logger.error(e.getMessage(), e);
    }
    return 0;
}

From source file:ConversionUtil.java

public static byte[] convertToByteArray(int value) {
    byte[] bytes = new byte[4];
    ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
    buffer.putInt(value);
    return buffer.array();
    // buffer.get(bytes);
    /*//from w ww .  java  2s . c  om
    for (int i =0;i<bytes.length; ++i) {
    int offset = (bytes.length -i-1) *8;
    bytes[i] = (byte)((value & (0xff << offset)) >>> offset);
    }
     */
    // return bytes;
}

From source file:com.oneguy.recognize.Util.java

public static ByteBuffer putData(ByteBuffer buffer, int data) {
    if (buffer == null) {
        return buffer;
    }//  w  ww . ja v a2s. c om
    // sizeof(int) == 4
    while (buffer.capacity() < buffer.position() + 4 - 1) {
        buffer = doubleSize(buffer);
    }
    buffer.putInt(data);
    return buffer;
}

From source file:com.nridge.core.base.std.BufUtl.java

/**
 * Resets the <code>ByteBuffer</code> position and adds the opcode and
 * version values to it./*from   w w w.  j a  v  a  2s  . c om*/
 *
 * @param aBuffer Packet byte buffer object.
 * @param anOpCode Application specific operation code value.
 * @param aVersion Application specific operation version code value.
 */
public static void setHeader(ByteBuffer aBuffer, int anOpCode, int aVersion) {
    if (aBuffer != null) {
        aBuffer.mark();
        aBuffer.position(0);
        aBuffer.putInt(anOpCode);
        aBuffer.putInt(aVersion);
        aBuffer.reset();
    }
}

From source file:org.apache.myriad.state.utils.ByteBufferSupport.java

public static byte[] toIntBytes(int src) {
    ByteBuffer bb = createBuffer(INT_SIZE);
    bb.putInt(src);
    return bb.array();
}

From source file:tor.HiddenService.java

public static byte[] getDescId(String onion, byte replica) {
    byte[] onionbin = new Base32().decode(onion.toUpperCase());
    assert onionbin.length == 10;

    long curtime = System.currentTimeMillis() / 1000L;
    int oid = onionbin[0] & 0xff;

    long t = (curtime + (oid * 86400L / 256)) / 86400L;

    ByteBuffer buf = ByteBuffer.allocate(10);
    buf.putInt((int) t);
    buf.put(replica);//from   w  w w  .  java 2  s. co m
    buf.flip();

    MessageDigest md = TorCrypto.getSHA1();
    md.update(buf);
    byte hashT[] = md.digest();

    md = TorCrypto.getSHA1();
    return md.digest(ArrayUtils.addAll(onionbin, hashT)); //md.digest();
}

From source file:org.opensha.commons.util.XMLUtils.java

public static void intArrayToXML(Element parent, int[] array, String elName) {
    byte[] bytes = new byte[array.length * 4];
    ByteBuffer buf = ByteBuffer.wrap(bytes);
    for (int val : array)
        buf.putInt(val);
    byteArrayToXML(parent, buf.array(), elName);
}