Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## things.common.tools
Class BoundedByteArrayOutputStream

    java.lang.Object
      java.io.OutputStream
          things.common.tools.BoundedByteArrayOutputStream

All Implemented Interfaces:
  java.io.Closeable, java.io.Flushable

    public class BoundedByteArrayOutputStream

extends java.io.OutputStream

A limited ByteArrayOutputStream. Instead of just expanding it forever, throw an IOException.

Version:
  1.0

  Version History

      EPG - Initial - 20 JUL 06

Author:
  Erich P. Gatejen

Constructor Summary
`BoundedByteArrayOutputStream(byte[] buffer)` Construct.

Method Summary
`void` | `close()` Close.
`void` | `copyMarkTo(java.io.OutputStream ous)` Copy from the last mark (or start if not mark made) to the end of the buffer into a stream.
`byte[]` | `get()` Get the total buffer.
`int` | `getFillSize()` Get how much of the buffer is filled.
`int` | `mark()` Mark the next spot that will get a byte and return the value.
`void` | `write(byte[] b)` Writes b.length bytes from the specified byte array to this output stream.
`void` | `write(byte[] b, int off, int len)` Writes len bytes from the specified byte array starting at offset off to this output stream.
`void` | `write(int b)` Writes the specified byte to this output stream.

Methods inherited from class java.io.OutputStream
`flush`

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

Constructor Detail

### BoundedByteArrayOutputStream

    public BoundedByteArrayOutputStream(byte[] buffer)
                                 throws java.lang.Throwable

  Construct. Use the buffer passed (and no more!)

  Parameters:
    `buffer` - The buffer.
  Throws:
    `java.lang.Throwable` - if the data is not allowed.

Method Detail

### get

    public byte[] get()

  Get the total buffer.

  Returns:
    the buffer.

### getFillSize

    public int getFillSize()

  Get how much of the buffer is filled. This might be silly, but I really don't want people to copy a huge buffer array just to get access to this data. Get the buffer and then getFillSize().

  Returns:
    the fill size in bytes.

### mark

    public int mark()

  Mark the next spot that will get a byte and return the value. If the array is bad you'll get a negative number.

### copyMarkTo

    public void copyMarkTo(java.io.OutputStream ous)
                    throws java.io.IOException

  Copy from the last mark (or start if not mark made) to the end of the buffer into a stream. Mark will be not be changed after the operation. If there is no difference between the mark and the next stop (meaning nothing was written since the last marking), nothing will out copied to the output stream.

  Parameters:
    `ous` - the output stream.
  Throws:
    `java.io.IOException`

### write

    public void write(byte[] b)
               throws java.io.IOException

  Writes b.length bytes from the specified byte array to this output stream.

  Overrides:
    `write` in class `java.io.OutputStream`
  Parameters:
    `b` - the data.
  Throws:
    `java.io.IOException`

### write

    public void write(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException

  Writes len bytes from the specified byte array starting at offset off to this output stream.

  Overrides:
    `write` in class `java.io.OutputStream`
  Parameters:
    `b` - the data.
    `off` - the start offset in the data.
    `len` - the number of bytes to write.
  Throws:
    `java.io.IOException`

### write

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

  Writes the specified byte to this output stream.

  Specified by:
    `write` in class `java.io.OutputStream`
  Parameters:
    `b` - the byte.
  Throws:
    `java.io.IOException`

### close

    public void close()
               throws java.io.IOException

  Close. It's a NOOP.

  Specified by:
    `close` in interface `java.io.Closeable`
  Overrides:
    `close` in class `java.io.OutputStream`
  Throws:
    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Things.