## org.jboss.netty.buffer
Class HeapChannelBufferFactory

    java.lang.Object
      org.jboss.netty.buffer.AbstractChannelBufferFactory
          org.jboss.netty.buffer.HeapChannelBufferFactory

All Implemented Interfaces:
  ChannelBufferFactory

    public class HeapChannelBufferFactory

extends AbstractChannelBufferFactory

A `ChannelBufferFactory` which merely allocates a heap buffer with the specified capacity. `HeapChannelBufferFactory` should perform very well in most situations because it relies on the JVM garbage collector, which is highly optimized for heap allocation.

Version:
  $Rev: 2197 $, $Date: 2010-02-23 09:43:15 +0900 (Tue, 23 Feb 2010) $
Author:
  The Netty Project, Trustin Lee

Constructor Summary
`HeapChannelBufferFactory()` Creates a new factory whose default `ByteOrder` is `ByteOrder.BIG_ENDIAN`.
`HeapChannelBufferFactory(ByteOrder defaultOrder)` Creates a new factory with the specified default `ByteOrder`.

Method Summary
`ChannelBuffer` `getBuffer(ByteBuffer nioBuffer)` Returns a `ChannelBuffer` whose content is equal to the sub-region of the specified `nioBuffer`.
`ChannelBuffer` `getBuffer(ByteOrder order, byte[] array, int offset, int length)` Returns a `ChannelBuffer` whose content is equal to the sub-region of the specified `array`.
`ChannelBuffer` `getBuffer(ByteOrder order, int capacity)` Returns a `ChannelBuffer` with the specified `endianness` and `capacity`.
`static ChannelBufferFactory` `getInstance()`
`static ChannelBufferFactory` `getInstance(ByteOrder endianness)`

Methods inherited from class org.jboss.netty.buffer.AbstractChannelBufferFactory
`getBuffer, getBuffer, getDefaultOrder`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HeapChannelBufferFactory

    public HeapChannelBufferFactory()

  Creates a new factory whose default `ByteOrder` is `ByteOrder.BIG_ENDIAN`.

### HeapChannelBufferFactory

    public HeapChannelBufferFactory(ByteOrder defaultOrder)

  Creates a new factory with the specified default `ByteOrder`.

  Parameters:
    `defaultOrder` - the default `ByteOrder` of this factory

Method Detail

### getInstance

    public static ChannelBufferFactory getInstance()

### getInstance

    public static ChannelBufferFactory getInstance(ByteOrder endianness)

### getBuffer

    public ChannelBuffer getBuffer(ByteOrder order,
                                   int capacity)

  Description copied from interface: `ChannelBufferFactory`
  Returns a `ChannelBuffer` with the specified `endianness` and `capacity`.

  Parameters:
    `order` - the endianness of the returned `ChannelBuffer`
    `capacity` - the capacity of the returned `ChannelBuffer`
  Returns:
    a `ChannelBuffer` with the specified `endianness` and `capacity`, whose `readerIndex` and `writerIndex` are `0`

### getBuffer

    public ChannelBuffer getBuffer(ByteOrder order,
                                   byte[] array,
                                   int offset,
                                   int length)

  Description copied from interface: `ChannelBufferFactory`
  Returns a `ChannelBuffer` whose content is equal to the sub-region of the specified `array`. Depending on the factory implementation, the returned buffer could wrap the `array` or create a new copy of the `array`.

  Parameters:
    `order` - the endianness of the returned `ChannelBuffer`
    `array` - the byte array
    `offset` - the offset of the byte array
    `length` - the length of the byte array
  Returns:
    a `ChannelBuffer` with the specified content, whose `readerIndex` and `writerIndex` are `0` and `(length - offset)` respectively

### getBuffer

    public ChannelBuffer getBuffer(ByteBuffer nioBuffer)

  Description copied from interface: `ChannelBufferFactory`
  Returns a `ChannelBuffer` whose content is equal to the sub-region of the specified `nioBuffer`. Depending on the factory implementation, the returned buffer could wrap the `nioBuffer` or create a new copy of the `nioBuffer`.

  Parameters:
    `nioBuffer` - the NIO `ByteBuffer`
  Returns:
    a `ChannelBuffer` with the specified content, whose `readerIndex` and `writerIndex` are `0` and `nioBuffer.remaining()` respectively

Copyright © 2008-2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.