Example usage for java.nio ByteBuffer get

List of usage examples for java.nio ByteBuffer get

Introduction

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

Prototype

public abstract byte get(int index);

Source Link

Document

Returns the byte at the specified index and does not change the position.

Usage

From source file:com.healthmarketscience.jackcess.UsageMap.java

/**
 * @param database database that contains this usage map
 * @param pageNum Page number that this usage map is contained in
 * @param rowNum Number of the row on the page that contains this usage map
 * @return Either an InlineUsageMap or a ReferenceUsageMap, depending on
 *         which type of map is found/*from  www .  j av  a  2 s .  c  o  m*/
 */
public static UsageMap read(Database database, int pageNum, int rowNum, boolean assumeOutOfRangeBitsOn)
        throws IOException {
    JetFormat format = database.getFormat();
    PageChannel pageChannel = database.getPageChannel();
    ByteBuffer tableBuffer = pageChannel.createPageBuffer();
    pageChannel.readPage(tableBuffer, pageNum);
    short rowStart = Table.findRowStart(tableBuffer, rowNum, format);
    int rowEnd = Table.findRowEnd(tableBuffer, rowNum, format);
    tableBuffer.limit(rowEnd);
    byte mapType = tableBuffer.get(rowStart);
    UsageMap rtn = new UsageMap(database, tableBuffer, pageNum, rowStart);
    rtn.initHandler(mapType, assumeOutOfRangeBitsOn);
    return rtn;
}

From source file:com.offbynull.portmapper.natpmp.ExternalAddressNatPmpResponse.java

/**
 * Constructs a {@link ExternalAddressNatPmpResponse} object by parsing a buffer.
 * @param buffer buffer containing PCP response data
 * @throws NullPointerException if any argument is {@code null}
 * @throws BufferUnderflowException if not enough data is available in {@code buffer}
 * @throws IllegalArgumentException if the version doesn't match the expected version (must always be {@code 0}), or if the op
 * {@code != 128}, or if there's an unsuccessful/unrecognized result code
 *///from   w ww.ja  va 2  s  .c  om
public ExternalAddressNatPmpResponse(ByteBuffer buffer) {
    super(buffer);

    Validate.isTrue(getOp() == 128);

    byte[] addr = new byte[4];
    buffer.get(addr);

    try {
        address = InetAddress.getByAddress(addr);
    } catch (UnknownHostException uhe) {
        throw new IllegalStateException(uhe); // should never happen, will always be 4 bytes
    }
}

From source file:com.esri.geoevent.transport.twitter.TwitterOutboundTransport.java

@Override
public void receive(ByteBuffer bb, String channelId) {
    byte[] data = new byte[bb.remaining()];
    bb.get(data);

    postBodyOrg = "status=" + new String(data);
    postBody = OAuth.encodePostBody(postBodyOrg);
    LOGGER.debug(postBody);//from  w ww  . j  a va2  s.co  m

    // super.receive(bb, channelId);
    doHttp();
}

From source file:com.glaf.core.util.ByteBufferUtils.java

/**
 * Compare two ByteBuffer at specified offsets for length. Compares the non
 * equal bytes as unsigned./*from  w  ww  . ja v  a2  s .  c o m*/
 * 
 * @param bytes1
 *            First byte buffer to compare.
 * @param offset1
 *            Position to start the comparison at in the first array.
 * @param bytes2
 *            Second byte buffer to compare.
 * @param offset2
 *            Position to start the comparison at in the second array.
 * @param length
 *            How many bytes to compare?
 * @return -1 if byte1 is less than byte2, 1 if byte2 is less than byte1 or
 *         0 if equal.
 */
public static int compareSubArrays(ByteBuffer bytes1, int offset1, ByteBuffer bytes2, int offset2, int length) {
    if (null == bytes1) {
        if (null == bytes2)
            return 0;
        else
            return -1;
    }
    if (null == bytes2)
        return 1;

    assert bytes1.limit() >= offset1
            + length : "The first byte array isn't long enough for the specified offset and length.";
    assert bytes2.limit() >= offset2
            + length : "The second byte array isn't long enough for the specified offset and length.";
    for (int i = 0; i < length; i++) {
        byte byte1 = bytes1.get(offset1 + i);
        byte byte2 = bytes2.get(offset2 + i);
        if (byte1 == byte2)
            continue;
        // compare non-equal bytes as unsigned
        return (byte1 & 0xFF) < (byte2 & 0xFF) ? -1 : 1;
    }
    return 0;
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.http2Encoder.java

@Override
public int write(ByteBuffer src) throws IOException {
    while (src.hasRemaining()) {
        byte[] b;
        b = new byte[src.remaining()];
        src.get(b);

        if (src.hasRemaining())
            encoder.writeData(chContext, streamId, Unpooled.wrappedBuffer(b), 0, false, promise);
        else {/*from w w  w  . ja  va2s  .  c  o  m*/
            encoder.writeData(chContext, streamId, Unpooled.wrappedBuffer(b), 0, true, promise);
            isComplete = true;
        }

    }

    return src.position();
}

From source file:backtype.storm.messaging.TaskMessage.java

public void deserialize(ByteBuffer packet) {
    if (packet == null)
        return;// ww  w  . j av a  2s . c o m
    _task = packet.getShort();
    remoteTuple = packet.getShort();
    _message = new byte[packet.limit() - 4];
    packet.get(_message);
}

From source file:fr.jetoile.hadoopunit.test.kafka.KafkaConsumerUtils.java

private void printMessages(ByteBufferMessageSet messageSet) throws UnsupportedEncodingException {
    for (MessageAndOffset messageAndOffset : messageSet) {
        ByteBuffer payload = messageAndOffset.message().payload();
        byte[] bytes = new byte[payload.limit()];
        payload.get(bytes);
        LOG.debug(new String(bytes, "UTF-8"));
    }/*from   w w  w  .j a v  a 2  s .com*/
}

From source file:com.healthmarketscience.jackcess.impl.UsageMap.java

/**
 * @param database database that contains this usage map
 * @param pageNum Page number that this usage map is contained in
 * @param rowNum Number of the row on the page that contains this usage map
 * @return Either an InlineUsageMap or a ReferenceUsageMap, depending on
 *         which type of map is found//from  www.  j  a  v  a2 s .  co  m
 */
public static UsageMap read(DatabaseImpl database, int pageNum, int rowNum, boolean assumeOutOfRangeBitsOn)
        throws IOException {
    if (pageNum <= 0) {
        // usage maps will never appear on page 0 (or less)
        throw new IllegalStateException("Invalid usage map page number " + pageNum);
    }

    JetFormat format = database.getFormat();
    PageChannel pageChannel = database.getPageChannel();
    ByteBuffer tableBuffer = pageChannel.createPageBuffer();
    pageChannel.readPage(tableBuffer, pageNum);
    short rowStart = TableImpl.findRowStart(tableBuffer, rowNum, format);
    int rowEnd = TableImpl.findRowEnd(tableBuffer, rowNum, format);
    tableBuffer.limit(rowEnd);
    byte mapType = tableBuffer.get(rowStart);
    UsageMap rtn = new UsageMap(database, tableBuffer, pageNum, rowStart);
    rtn.initHandler(mapType, assumeOutOfRangeBitsOn);
    return rtn;
}

From source file:com.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java

private byte[] getCleanedBytes(char[] password) {
    final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password);
    final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars));
    final byte[] byteArray = new byte[byteBuffer.remaining()];
    byteBuffer.get(byteArray);
    Arrays.fill(byteBuffer.array(), (byte) 0);
    return byteArray;
}

From source file:com.ah.be.ls.processor2.TxProcessor.java

public byte[] buildPacket() {
    if (requestObj == null) {
        return new byte[0];
    }/*from  ww w  .j  a v a2  s  .c  o  m*/
    ByteBuffer buffer = requestObj.pack();
    byte[] outBytes = new byte[buffer.limit()];
    buffer.get(outBytes);
    return outBytes;
}