Tabnine Logo
CompositeBuffer.toByteBufferArray
Code IndexAdd Tabnine to your IDE (free)

How to use
toByteBufferArray
method
in
org.glassfish.grizzly.memory.CompositeBuffer

Best Java code snippets using org.glassfish.grizzly.memory.CompositeBuffer.toByteBufferArray (Showing top 14 results out of 315)

origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: org.mule.glassfish.grizzly/grizzly-framework

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: org.glassfish.grizzly/grizzly-websockets-server

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: org.glassfish.grizzly/grizzly-core

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: org.glassfish.grizzly/grizzly-http-server-core

public static int readCompositeBuffer(final TCPNIOConnection connection,
    final CompositeBuffer buffer) throws IOException {
  
  final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
  final int oldPos = buffer.position();
  final ByteBufferArray array = buffer.toByteBufferArray();
  final ByteBuffer byteBuffers[] = array.getArray();
  final int size = array.size();
  
  final int read = (int) socketChannel.read(byteBuffers, 0, size);
  array.restore();
  array.recycle();
  
  if (read > 0) {
    buffer.position(oldPos + read);
  }
  
  if (LOGGER.isLoggable(Level.FINE)) {
    LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{
          connection, read
        });
  }
  
  return read;
}
origin: javaee/grizzly

@Test
public void testToByteBufferArray() {
  final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  final List<Buffer> bufferList = new ArrayList<Buffer>();
  for (byte b : bytes) {
    final Buffer buffer = mm.allocate(1);
    buffer.put(0, b);
    bufferList.add(buffer);
  }
  final Buffer[] buffers = bufferList.toArray(new Buffer[bufferList.size()]);
  final CompositeBuffer composite = CompositeBuffer.newBuffer(mm, buffers);
  for (int i = 0; i < bytes.length; i++) {
    for (int j = i; j < bytes.length; j++) {
      final ByteBufferArray bbArray = composite.toByteBufferArray(i, j);
      
      int bytesChecked = 0;
      final ByteBuffer[] bbs = bbArray.getArray();
      for (int k = 0; k < bbArray.size(); k++) {
        final ByteBuffer bb = bbs[k];
        while (bb.hasRemaining()) {
          final byte got = bb.get();
          assertEquals("Testcase [pos=" + i + " lim=" + j + " bytenumber=" + bytesChecked + "]", bytes[i + bytesChecked], got);
          bytesChecked++;
        }
      }
      assertEquals(j - i, bytesChecked);
      bbArray.restore();
    }
  }
}
origin: javaee/grizzly

  @Override
  public void run() {
    // Initialize memory manager
    mm.allocate(33);
    final int initialSize = mm.getReadyThreadBufferSize();
    CompositeBuffer compositeBuffer = CompositeBuffer.newBuffer(mm);
    for (int i = 0; i < 11; i++) {
      Buffer b = mm.allocate(1228);
      b.allowBufferDispose(true);
      compositeBuffer.append(b);
    }
    compositeBuffer.toByteBufferArray(0, 12280);
    compositeBuffer.limit(1228);
    compositeBuffer.shrink();
    assertEquals(initialSize - (1228 * 11 - 12280),
        mm.getReadyThreadBufferSize());
    compositeBuffer.position(compositeBuffer.limit());
    compositeBuffer.shrink();
    assertEquals(initialSize,
        mm.getReadyThreadBufferSize());
  }
};
org.glassfish.grizzly.memoryCompositeBuffertoByteBufferArray

Popular methods of CompositeBuffer

  • append
  • allowInternalBuffersDispose
  • newBuffer
  • remaining
  • allowBufferDispose
  • dispose
  • shrink
  • get
  • position
  • bulk
    Iterates over Buffer bytes from position to limit and lets BulkOperation examine/change the buffer c
  • disposeOrder
    Sets the order in which internal Buffers will be disposed.
  • limit
  • disposeOrder,
  • limit,
  • replace,
  • clear,
  • duplicate,
  • order,
  • prepend,
  • removeAll,
  • toBufferArray

Popular in Java

  • Start an intent from android
  • getContentResolver (Context)
  • scheduleAtFixedRate (Timer)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now