net.sf.cotta.memory
Class ByteArrayBuffer

java.lang.Object
  extended by net.sf.cotta.memory.ByteArrayBuffer

public class ByteArrayBuffer
extends java.lang.Object

Faster performing ByteArrayBuffer using the ByteArrayOutputStream as a backing up stream. Writes 400MB in 44 seconds. Requires approx 2x memory of the file size, eg for 400MB set -Xmx1024m.

Contributed by: Sergey Abramov http://coldcore.com


Field Summary
static int INCREMENT
           
 
Constructor Summary
ByteArrayBuffer()
           
ByteArrayBuffer(byte[] content)
           
ByteArrayBuffer(byte[] content, int increament)
           
ByteArrayBuffer(int initialCapacity)
           
ByteArrayBuffer(int initialCapacity, int increment)
           
 
Method Summary
 ByteArrayBuffer append(byte b)
           
 ByteArrayBuffer append(byte[] b)
          Faster performing method, output stream should delegate to it (comment above).
 ByteArrayBuffer append(byte[] b, int off, int len)
          Faster performing method, output stream should delegate to it (comment above).
 void append(java.lang.String value)
          This works for the default charset only:

String str = ""+(char)1077+(char)1078; //UTF-8 System.out.println((int)str.charAt(0)); //1077 str = new String(str.getBytes(), "UTF-8"); System.out.println((int)str.charAt(0)); //63, no UTF-8 any longer

 void append(java.lang.String value, java.lang.String charsetName)
          This one converts to the proper charset.
 byte byteAt(int position)
           
 byte byteAt(long position)
           
 int copyFrom(java.nio.ByteBuffer src)
           
 long copyTo(java.nio.ByteBuffer dst, int start, int count)
           
 long copyTo(java.nio.channels.WritableByteChannel target, long position, long count)
           
 int size()
           
 byte[] toByteArray()
           
 java.lang.String toString()
          This method returns a string using the default charset.
 java.lang.String toString(java.lang.String charsetName)
          This method returns a string converted to the proper charset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INCREMENT

public static final int INCREMENT
See Also:
Constant Field Values
Constructor Detail

ByteArrayBuffer

public ByteArrayBuffer(byte[] content)

ByteArrayBuffer

public ByteArrayBuffer(byte[] content,
                       int increament)

ByteArrayBuffer

public ByteArrayBuffer()

ByteArrayBuffer

public ByteArrayBuffer(int initialCapacity)

ByteArrayBuffer

public ByteArrayBuffer(int initialCapacity,
                       int increment)
Method Detail

toByteArray

public byte[] toByteArray()

append

public ByteArrayBuffer append(byte b)

append

public ByteArrayBuffer append(byte[] b,
                              int off,
                              int len)
Faster performing method, output stream should delegate to it (comment above).


append

public ByteArrayBuffer append(byte[] b)
Faster performing method, output stream should delegate to it (comment above).


append

public void append(java.lang.String value)
            throws java.io.IOException
This works for the default charset only:

String str = ""+(char)1077+(char)1078; //UTF-8 System.out.println((int)str.charAt(0)); //1077 str = new String(str.getBytes(), "UTF-8"); System.out.println((int)str.charAt(0)); //63, no UTF-8 any longer

Throws:
java.io.IOException

append

public void append(java.lang.String value,
                   java.lang.String charsetName)
            throws java.io.IOException
This one converts to the proper charset.

Throws:
java.io.IOException

byteAt

public byte byteAt(long position)

byteAt

public byte byteAt(int position)

size

public int size()

copyFrom

public int copyFrom(java.nio.ByteBuffer src)

copyTo

public long copyTo(java.nio.ByteBuffer dst,
                   int start,
                   int count)

copyTo

public long copyTo(java.nio.channels.WritableByteChannel target,
                   long position,
                   long count)
            throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
This method returns a string using the default charset.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String charsetName)
                          throws java.io.UnsupportedEncodingException
This method returns a string converted to the proper charset.

Throws:
java.io.UnsupportedEncodingException