jamod at SF

net.wimpi.modbus.io
Class FastByteArrayOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bynet.wimpi.modbus.io.FastByteArrayOutputStream
Direct Known Subclasses:
BytesOutputStream

public class FastByteArrayOutputStream
extends java.io.OutputStream

This class is a replacement implementation for ByteArrayOutputStream that does not synchronize every byte written.

Version:
1.2rc1 (09/11/2004)
Author:
Mark Hayes, Dieter Wimberger

Field Summary
protected  byte[] buf
          Output buffer byte[].
protected  int bumpLen
          Increment of the output buffer size on overflow.
protected  int count
          Number of bytes in the output buffer.
static int DEFAULT_BUMP_SIZE
          Defines the default increment of the output buffer size (100 bytes).
static int DEFAULT_INIT_SIZE
          Defines the default oputput buffer size (100 bytes).
 
Constructor Summary
FastByteArrayOutputStream()
          Creates an output stream with default sizes.
FastByteArrayOutputStream(byte[] buffer)
          Creates an output stream with a given initial buffer and a default bump size.
FastByteArrayOutputStream(byte[] buffer, int bumpSize)
          Creates an output stream with a given initial buffer and a given bump size.
FastByteArrayOutputStream(int initialSize)
          Creates an output stream with a default bump size and a given initial size.
FastByteArrayOutputStream(int initialSize, int bumpSize)
          Creates an output stream with a given bump size and initial size.
 
Method Summary
 void addSize(int sizeAdded)
          Skip the given number of bytes in the buffer.
 byte[] getBufferBytes()
          Returns the buffer owned by this object.
 int getBufferLength()
          Returns the length used in the internal buffer, that is, the offset at which data will be written next.
 int getBufferOffset()
          Returns the offset of the internal buffer.
 void makeSpace(int sizeNeeded)
          Ensure that at least the given number of bytes are available in the internal buffer.
 void reset()
          Resets this FastByteArrayOutputStream.
 int size()
          Returns the number of bytes written to this FastByteArrayOutputStream.
 byte[] toByteArray()
          Returns the written bytes in a newly allocated byte[] of length getSize().
 void toByteArray(byte[] toBuf, int offset)
          Copy the buffered data to the given array.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String encoding)
          Returns the content of this FastByteArrayOutputStream as String.
 void write(byte[] fromBuf)
           
 void write(byte[] fromBuf, int offset, int length)
           
 void write(int b)
           
 void writeTo(java.io.OutputStream out)
          Writes the content of this FastByteArrayOutputStream to the given output stream.
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INIT_SIZE

public static final int DEFAULT_INIT_SIZE
Defines the default oputput buffer size (100 bytes).

See Also:
Constant Field Values

DEFAULT_BUMP_SIZE

public static final int DEFAULT_BUMP_SIZE
Defines the default increment of the output buffer size (100 bytes).

See Also:
Constant Field Values

count

protected int count
Number of bytes in the output buffer.


bumpLen

protected int bumpLen
Increment of the output buffer size on overflow.


buf

protected byte[] buf
Output buffer byte[].

Constructor Detail

FastByteArrayOutputStream

public FastByteArrayOutputStream()
Creates an output stream with default sizes.


FastByteArrayOutputStream

public FastByteArrayOutputStream(int initialSize)
Creates an output stream with a default bump size and a given initial size.

Parameters:
initialSize - the initial size of the buffer.

FastByteArrayOutputStream

public FastByteArrayOutputStream(int initialSize,
                                 int bumpSize)
Creates an output stream with a given bump size and initial size.

Parameters:
initialSize - the initial size of the buffer.
bumpSize - the amount to increment the buffer.

FastByteArrayOutputStream

public FastByteArrayOutputStream(byte[] buffer)
Creates an output stream with a given initial buffer and a default bump size.

Parameters:
buffer - the initial buffer; will be owned by this object.

FastByteArrayOutputStream

public FastByteArrayOutputStream(byte[] buffer,
                                 int bumpSize)
Creates an output stream with a given initial buffer and a given bump size.

Parameters:
buffer - the initial buffer; will be owned by this object.
bumpSize - the amount to increment the buffer.
Method Detail

size

public int size()
Returns the number of bytes written to this FastByteArrayOutputStream.

Returns:
the number of bytes written as int.

reset

public void reset()
Resets this FastByteArrayOutputStream.


write

public void write(int b)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] fromBuf)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] fromBuf,
                  int offset,
                  int length)
           throws java.io.IOException
Throws:
java.io.IOException

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Writes the content of this FastByteArrayOutputStream to the given output stream.

Parameters:
out - the output stream to be written to.
Throws:
java.io.IOException - if an I/O error occurs.

toString

public java.lang.String toString()

toString

public java.lang.String toString(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
Returns the content of this FastByteArrayOutputStream as String.

Parameters:
encoding - the encoding to be used for conversion.
Returns:
a newly allocated String.
Throws:
java.io.UnsupportedEncodingException - if the given encoding is not supported.

toByteArray

public byte[] toByteArray()
Returns the written bytes in a newly allocated byte[] of length getSize().

Returns:
a newly allocated byte[] with the content of the output buffer.

toByteArray

public void toByteArray(byte[] toBuf,
                        int offset)
Copy the buffered data to the given array.

Parameters:
toBuf - the buffer to hold a copy of the data.
offset - the offset at which to start copying.

getBufferBytes

public byte[] getBufferBytes()
Returns the buffer owned by this object.

Returns:
the buffer.

getBufferOffset

public int getBufferOffset()
Returns the offset of the internal buffer.

Returns:
always zero currently.

getBufferLength

public int getBufferLength()
Returns the length used in the internal buffer, that is, the offset at which data will be written next.

Returns:
the buffer length.

makeSpace

public void makeSpace(int sizeNeeded)
Ensure that at least the given number of bytes are available in the internal buffer.

Parameters:
sizeNeeded - the number of bytes desired.

addSize

public void addSize(int sizeAdded)
Skip the given number of bytes in the buffer.

Parameters:
sizeAdded - number of bytes to skip.

jamod at SF

Copyright © 2002-2004 jamod development team.