List of usage examples for java.nio ByteBuffer limit
public final int limit()
From source file:com.homeadvisor.kafdrop.service.MessageInspector.java
private byte[] readBytes(ByteBuffer buffer) { return readBytes(buffer, 0, buffer.limit()); }
From source file:org.jasig.cas.ticket.registry.support.kryo.serial.AttributeMapSerializerTests.java
private void printBuffer(final ByteBuffer buffer) { final byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes);/*from www. java 2 s . c o m*/ try { logger.debug(new String(bytes, "UTF-8")); } catch (Exception e) { logger.error("Error printing buffer as string."); } buffer.rewind(); }
From source file:org.sglover.alfrescoextensions.common.HasherImpl.java
private String getHash(ByteBuffer bytes, int start, int end, MessageDigest digest) throws NoSuchAlgorithmException { int saveLimit = bytes.limit(); bytes.limit(end + 1);//from w ww. j av a2s . c om bytes.mark(); bytes.position(start); digest.reset(); digest.update(bytes); byte[] array = digest.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } bytes.limit(saveLimit); bytes.reset(); return sb.toString(); }
From source file:backtype.storm.messaging.TaskMessage.java
public void deserialize(ByteBuffer packet) { if (packet == null) return;/*ww w . j a v a 2s . c om*/ _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);/*from w w w . j av a 2 s. c o m*/ LOG.debug(new String(bytes, "UTF-8")); } }
From source file:net.phoenix.thrift.hello.SpringHelloService.java
@Override public ByteBuffer testBinary(ByteBuffer name) throws TException { try {/*from w w w.j av a 2s. c o m*/ String result = new String(name.array(), name.position(), name.limit() - name.position(), "UTF-8"); result = "Hello " + result; return ByteBuffer.wrap(result.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new TException(e); } }
From source file:com.ah.be.ls.processor2.TxProcessor.java
public byte[] buildPacket() { if (requestObj == null) { return new byte[0]; }//from w w w.j av a 2 s .c om ByteBuffer buffer = requestObj.pack(); byte[] outBytes = new byte[buffer.limit()]; buffer.get(outBytes); return outBytes; }
From source file:org.apache.accumulo.server.security.delegation.AuthenticationKey.java
@Override public void write(DataOutput out) throws IOException { if (null == authKey) { WritableUtils.writeVInt(out, 0); return;//from w w w . ja v a2 s . c om } ThriftMessageUtil util = new ThriftMessageUtil(); ByteBuffer serialized = util.serialize(authKey); WritableUtils.writeVInt(out, serialized.limit() - serialized.arrayOffset()); ByteBufferUtil.write(out, serialized); }
From source file:org.cloudata.core.commitlog.pipe.Message.java
private ByteBuffer duplicate(ByteBuffer buf) { // LOG.debug("before pos : " + buf.position()); // LOG.debug("before limit : " + buf.limit()); ByteBuffer ret = buf.duplicate(); if (ret.position() == ret.limit()) { ret.flip();// ww w . j av a 2 s.c o m } // LOG.debug("after pos : " + ret.position()); // LOG.debug("after limit : " + ret.limit()); return ret; }
From source file:com.spotify.heroic.metric.datastax.schema.legacy.MapSerializer.java
@Override public ByteBuffer serialize(final Map<A, B> value) throws IOException { final List<Pair<ByteBuffer, ByteBuffer>> buffers = new ArrayList<>(); short size = 0; for (final Map.Entry<A, B> e : value.entrySet()) { final ByteBuffer key = a.serialize(e.getKey()); final ByteBuffer val = b.serialize(e.getValue()); size += key.limit() + val.limit(); buffers.add(Pair.of(key, val)); }//from w w w . ja va 2 s . c o m final ByteBuffer buffer = ByteBuffer.allocate(4 + 8 * value.size() + size); buffer.putShort((short) buffers.size()); for (final Pair<ByteBuffer, ByteBuffer> p : buffers) { buffer.putShort((short) p.getLeft().remaining()); buffer.put(p.getLeft()); buffer.putShort((short) p.getRight().remaining()); buffer.put(p.getRight()); } buffer.flip(); return buffer; }