org.apache.derby.iapi.services.io
Class AccessibleByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class AccessibleByteArrayOutputStream
extends java.io.ByteArrayOutputStream

This allows us to get to the byte array to go back and edit contents or get the array without having a copy made.

Since a copy is not made, users must be careful that no more writes are made to the stream if the array reference is handed off.

Users of this must make the modifications *before* the next write is done, and then release their hold on the array.


Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
AccessibleByteArrayOutputStream()
           
AccessibleByteArrayOutputStream(int size)
           
 
Method Summary
static java.io.InputStream copyStream(java.io.InputStream in, int bufferSize)
          Copy an InputStream into an array of bytes and return an InputStream against those bytes.
 java.io.InputStream getInputStream()
          Return an InputStream that wraps the valid byte array.
 byte[] getInternalByteArray()
          The caller promises to set their variable to null before any other calls to write to this stream are made.
 void readFrom(java.io.InputStream in)
          Read the complete contents of the passed input stream into this byte array.
 
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, write, write, 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

AccessibleByteArrayOutputStream

public AccessibleByteArrayOutputStream()

AccessibleByteArrayOutputStream

public AccessibleByteArrayOutputStream(int size)
Method Detail

getInternalByteArray

public byte[] getInternalByteArray()
The caller promises to set their variable to null before any other calls to write to this stream are made. Or promises to throw away references to the stream before passing the array reference out of its control.


readFrom

public void readFrom(java.io.InputStream in)
              throws java.io.IOException
Read the complete contents of the passed input stream into this byte array.

Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
Return an InputStream that wraps the valid byte array. Note that no copy is made of the byte array from the input stream, it is up to the caller to ensure the correct co-ordination.


copyStream

public static java.io.InputStream copyStream(java.io.InputStream in,
                                             int bufferSize)
                                      throws java.io.IOException
Copy an InputStream into an array of bytes and return an InputStream against those bytes. The input stream is copied until EOF is returned. This is useful to provide streams to applications in order to isolate them from Derby's internals.

Parameters:
in - InputStream to be copied
bufferSize - Initial size of the byte array
Returns:
InputStream against the raw data.
Throws:
java.io.IOException - Error reading the stream

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.