com.dyuproject.protostuff
Class LinkedBuffer

java.lang.Object
  extended by com.dyuproject.protostuff.LinkedBuffer

public final class LinkedBuffer
extends java.lang.Object

A buffer that wraps a byte array and has a reference to the next buffer for dynamic increase.

Author:
David Yu
Date created:
May 18, 2010

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default buffer size for a LinkedBuffer.
static int MIN_BUFFER_SIZE
          The minimum buffer size for a LinkedBuffer.
 
Method Summary
static LinkedBuffer allocate(int size)
          Allocates a new buffer with the specified size.
static LinkedBuffer allocate(int size, LinkedBuffer previous)
          Allocates a new buffer with the specified size and appends it to the previous buffer.
 LinkedBuffer clear()
          The offset will be reset to its starting position.
static LinkedBuffer use(byte[] buffer)
          Uses the existing byte array as the internal buffer.
static LinkedBuffer use(byte[] buffer, int start)
          Uses the existing byte array as the internal buffer.
static LinkedBuffer wrap(byte[] array, int offset, int length)
          Wraps the byte array buffer as a read-only buffer.
static int writeTo(java.io.DataOutput out, LinkedBuffer node)
          Writes the contents of the LinkedBuffer into the DataOutput.
static int writeTo(java.io.OutputStream out, LinkedBuffer node)
          Writes the contents of the LinkedBuffer into the OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_BUFFER_SIZE

public static final int MIN_BUFFER_SIZE
The minimum buffer size for a LinkedBuffer.

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size for a LinkedBuffer.

See Also:
Constant Field Values
Method Detail

allocate

public static LinkedBuffer allocate(int size)
Allocates a new buffer with the specified size.


allocate

public static LinkedBuffer allocate(int size,
                                    LinkedBuffer previous)
Allocates a new buffer with the specified size and appends it to the previous buffer.


wrap

public static LinkedBuffer wrap(byte[] array,
                                int offset,
                                int length)
Wraps the byte array buffer as a read-only buffer.


use

public static LinkedBuffer use(byte[] buffer)
Uses the existing byte array as the internal buffer.


use

public static LinkedBuffer use(byte[] buffer,
                               int start)
Uses the existing byte array as the internal buffer.


writeTo

public static int writeTo(java.io.OutputStream out,
                          LinkedBuffer node)
                   throws java.io.IOException
Writes the contents of the LinkedBuffer into the OutputStream.

Returns:
the total content size of the buffer.
Throws:
java.io.IOException

writeTo

public static int writeTo(java.io.DataOutput out,
                          LinkedBuffer node)
                   throws java.io.IOException
Writes the contents of the LinkedBuffer into the DataOutput.

Returns:
the total content size of the buffer.
Throws:
java.io.IOException

clear

public LinkedBuffer clear()
The offset will be reset to its starting position. The buffer next to this will be dereferenced.



Copyright © 2009-2014. All Rights Reserved.