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

## lbg.common.io
Class EnhancedByteArrayOutputStream

    java.lang.Object
      java.io.OutputStream
          java.io.ByteArrayOutputStream
              lbg.common.io.EnhancedByteArrayOutputStream

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

    public class EnhancedByteArrayOutputStream

extends java.io.ByteArrayOutputStream

Additional methods for the standard ByteArrayOutputStream. This new class allows to copy its buffer in an already allocated byte array rather than creating a new one and can support a limit of characters.

If the stream is not large enough to fit the given information, it is silently dropped. This is useful in cases where you need to start a trustless child thread than should only output a limited amount of data.

Author:
  Xavier Dalem

Field Summary

Fields inherited from class java.io.ByteArrayOutputStream
`buf, count`

Constructor Summary
`EnhancedByteArrayOutputStream()`
`EnhancedByteArrayOutputStream(int limit)`
`EnhancedByteArrayOutputStream(int limit, int size)`

Method Summary
`int` | `setLimit(int new_limit)` Sets the limit size for this stream to a new value.
`byte[]` | `toByteArray(byte[] array)` Copies the buffer of this stream to the given byte array.
`void` | `write(byte[] b, int off, int len)`
`void` | `write(int b)`

Methods inherited from class java.io.ByteArrayOutputStream
`close, reset, size, toByteArray, toString, toString, toString, writeTo`

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

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

Constructor Detail

### EnhancedByteArrayOutputStream

    public EnhancedByteArrayOutputStream()

### EnhancedByteArrayOutputStream

    public EnhancedByteArrayOutputStream(int limit)

### EnhancedByteArrayOutputStream

    public EnhancedByteArrayOutputStream(int limit,
                                         int size)

Method Detail

### setLimit

    public int setLimit(int new_limit)

  Sets the limit size for this stream to a new value. Set to 0 for no limit.

  Parameters:
    `new_limit` - The new byte limit
  Returns:
    The old limit

### toByteArray

    public byte[] toByteArray(byte[] array)

  Copies the buffer of this stream to the given byte array. If the given array is too small, a new one is created as for `ByteArrayOutputStream.toByteArray()`.

  Parameters:
    `array` - The array where data should be put.
  Returns:
    A copy of the buffer

### write

    public void write(byte[] b,
                      int off,
                      int len)

  If the contents don't fit in the stream because of the limit, it is truncated.

  Overrides:
    `write` in class `java.io.ByteArrayOutputStream`

### write

    public void write(int b)

  If the content don't fit in the stream because of limit, it is dropped.

  Overrides:
    `write` in class `java.io.ByteArrayOutputStream`

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

> Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.