com.informix.csm

## Class IfxCsmBuffer

- java.lang.Object
- - java.io.OutputStream
  - - java.io.ByteArrayOutputStream
    - - com.informix.csm.IfxCsmBuffer

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

    public class IfxCsmBuffer
    extends java.io.ByteArrayOutputStream

### Field Summary

### Fields inherited from class java.io.ByteArrayOutputStream

`buf, count`

### Constructor Summary

Constructors
Constructor and Description
`IfxCsmBuffer()`
`IfxCsmBuffer(int initSize)`

### Method Summary

Methods
`int` `getCount()`
`void` `initialize(IfxCsmBuffer anotherBuffer)` this shall initialize this csmBuffer with contents ( i.e.
`void` `initialize(IfxCsmReadBuffer bis)` populates buf reference with internal buffer reference from bis Be aware that this method does not care about the current position (pos) of bis

`int`

`read(byte[] b, int off, int len)`
copies len number fo bytes from byte array buf into byte array b ***************IMPORTANT **************************** Note that this read does not behave like read on an input stream if you read say n bytes and then again call read to ream next m bytes you are going to get n as well as m from begining of buf thus you shall end up getting first m bytes from array and NOT m bytes from position buf[n]

`byte[]` `read(int len)` Allocates a byte array , copies len bytes from byte array buf to it and returns the array
`int` `readWithReset(byte[] b, int off, int len)` This functions reads bytes from byte array buf creates a new byte array copies unread bytes from buf to new byte array replaces byte array referred to by buf with this new array Also resets count .
`byte[]` `readWithReset(int len)`
`void` `reset()` we are overriding default implementation of reset() in ByteArrayOutputStream The default implementation does not release the internal buffer 'buf' but just resets count to zero.
`void` `resetAndwrite(byte[] b)`
`byte[]` `toByteArray()`
`byte[]` `toByteArrayWithReset()`
`void` `write(byte[] b)`
`void` `write(byte[] b, int off, int len)`
`void` `write(int b)`
`void` `writeTo(java.io.OutputStream out)`

### Methods inherited from class java.io.ByteArrayOutputStream

`close, size, toString, toString, toString`

### Methods inherited from class java.io.OutputStream

`flush`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### IfxCsmBuffer

    public IfxCsmBuffer()

#### IfxCsmBuffer

    public IfxCsmBuffer(int initSize)

### Method Detail

#### initialize

    public void initialize(IfxCsmBuffer anotherBuffer)

this shall initialize this csmBuffer with contents ( i.e. buf and count) from another CSM buffer. IMPORTANT : SHALL RESET anotherBuffer so that it does not holds reference to the buf anymore . If we do not do this , any writes called on anotherBuffer after it is used to initialize this csmBuffer shall result in contents of this csmBuffer also getting changed. This is diffrent from reset() implementation as in JDK as BufferedOutputStream:reset() does not allocate a new internal buffer. it just sets count to zero

Parameters:
  `anotherBuffer` - used to initialize this buffer Note that anotherBuffer IS RESET

#### initialize

    public void initialize(IfxCsmReadBuffer bis)

populates buf reference with internal buffer reference from bis Be aware that this method does not care about the current position (pos) of bis

Parameters:
  `bis` -

#### write

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

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

#### write

    public void write(byte[] b)

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

#### resetAndwrite

    public void resetAndwrite(byte[] b)

#### write

    public void write(int b)

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

#### toByteArray

    public byte[] toByteArray()

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

#### toByteArrayWithReset

    public byte[] toByteArrayWithReset()

#### read

    public int read(byte[] b,
           int off,
           int len)

copies len number fo bytes from byte array buf into byte array b ***************IMPORTANT **************************** Note that this read does not behave like read on an input stream if you read say n bytes and then again call read to ream next m bytes you are going to get n as well as m from begining of buf thus you shall end up getting first m bytes from array and NOT m bytes from position buf[n]

Parameters:
  `b` -
  `off` -
  `len` -
Returns:

#### read

    public byte[] read(int len)

Allocates a byte array , copies len bytes from byte array buf to it and returns the array

Parameters:
  `len` -
Returns:

#### readWithReset

    public byte[] readWithReset(int len)

#### readWithReset

    public int readWithReset(byte[] b,
                    int off,
                    int len)

This functions reads bytes from byte array buf creates a new byte array copies unread bytes from buf to new byte array replaces byte array referred to by buf with this new array Also resets count .

Parameters:
  `b` -
  `off` -
  `len` -
Returns:

#### getCount

    public int getCount()

#### reset

    public void reset()

we are overriding default implementation of reset() in ByteArrayOutputStream The default implementation does not release the internal buffer 'buf' but just resets count to zero. Thus internal buffer buf is reused however in this overridden reset method , we shall be allocating new internal byte array buffer buf so that we lose reference to old buffer completely.

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

#### writeTo

    public void writeTo(java.io.OutputStream out)
                 throws java.io.IOException

Overrides:
  `writeTo` in class `java.io.ByteArrayOutputStream`
Throws:
  `java.io.IOException`