Package java.nio

Examples of java.nio.ByteBuffer.clear()


            {
                int x = ch.read(bb) ;
                if ( x < 0 )
                    break ;
                ByteBufferLib.print(bb) ;
                bb.clear() ;
            }
            fh.close() ;
           
        } catch (IOException ex)
        {
View Full Code Here


        public void run() {
            /** 64k receive buffer */
            ByteBuffer rcvdBuffer = ByteBuffer.allocate(64 * 1024);
            while (bound) {
                // I/O !
                rcvdBuffer.clear();
                try {
                    SocketAddress from = channel.receive(rcvdBuffer);
                    BioUdpSession session = sessions.get(from);
                    if (session == null) {
                        // create the session
View Full Code Here

 
  public void transferTo(WritableByteChannel channel) throws IOException {
    if (!flipped) notflipped();
    ByteBuffer buf = ByteBuffer.wrap(buffer);
    while(buf.hasRemaining()) channel.write(buf);
    buf.clear();
  }
}
View Full Code Here

    int patternSize = BODY_PATTERN.getBytes(Charset.defaultCharset()).length;

    for (int i = 0; i < respSize / DEFAULT_RESPONSE_CHUNK_SIZE; ++i)
    {
          bb.clear();
      for (int j = 0; j < DEFAULT_RESPONSE_CHUNK_SIZE / patternSize; ++j)
      {
        bb.put(BODY_PATTERN.getBytes(Charset.defaultCharset()));
      }
View Full Code Here

      request.getResponseContent().write(bb);
    }

    if (respSize % DEFAULT_RESPONSE_CHUNK_SIZE > 0)
    {
          bb.clear();
          for (int j = 0; j <= (respSize % DEFAULT_RESPONSE_CHUNK_SIZE) / patternSize; ++j)
          {
            bb.put(BODY_PATTERN.getBytes(Charset.defaultCharset()));
          }
View Full Code Here

     */
    private static ByteBuffer stringToByteBuffer (final String string) {
        final ByteBuffer buffer = ByteBuffer.allocate(string.length());
        for (int i = 0; i < string.length(); ++i)
            buffer.put((byte) string.charAt(i));
        buffer.clear();
        return buffer;
    }

    /**
     * Appends the content of a <code>ProtocolDataUnit</code> (text) data segment to a {@link StringBuilder};
View Full Code Here

        stringBuffer.put(hello.getBytes());

        StringBuilder builder = new StringBuilder("...");
        ReadWrite.appendTextDataSegmentToStringBuffer(stringBuffer, builder);

        stringBuffer.clear();
        stringBuffer.put(hello.getBytes());

        Assert.assertEquals(builder.toString(), new StringBuilder("...").append(new String(stringBuffer.array())).toString());
    }
View Full Code Here

                }
              }

              if (!readPos.hasNext())
              {
                readBuffer.clear();
              }
            } finally {
              _queueLock.unlock();
            }
          }
View Full Code Here

   */
  private void compactStgBuffer(ReadEventsReadPosition readPos, boolean logDebugEnabled)
  {
    final ByteBuffer readBuffer = readPos.getReadBuffer();

    readBuffer.clear();//despite its name, clear() does not remove the data
    if (readPos.hasNext())
    {
      if (logDebugEnabled)
      {
        _log.debug("Copying " + readPos.bytesRemaining() + " bytes to the start of the readBuffer");
View Full Code Here

      int count = 0;
      _eventHandler.onStart(query);

      while (rs.next())
      {
        buffer.clear();
        buffer.put(rs.getBytes("val"));
        event = event.reset(buffer, 0);
        GenericRecord record = _decoder.getGenericRecord(event);
        _eventHandler.onRecord(event, record);
        count++;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.