org.deegree.commons.utils.io
Class StreamBufferStore

java.lang.Object
  extended by java.io.OutputStream
      extended by org.deegree.commons.utils.io.StreamBufferStore
All Implemented Interfaces:
Closeable, Flushable

public class StreamBufferStore
extends OutputStream

Scalable alternative to ByteArrayOutputStream that automatically switches to file-based storage if the amount of written bytes exceeds a given limit.

Version:
$Revision: 31265 $, $Date: 2011-07-12 16:15:25 +0200 (Tue, 12 Jul 2011) $
Author:
Markus Schneider, last edited by: $Author: mschneider $

Field Summary
static int DEFAULT_LIMIT
          Default limit (1 MB)
 
Constructor Summary
StreamBufferStore()
          Creates a new StreamBufferStore instance that switches to file storage when DEFAULT_LIMIT bytes have been written.
StreamBufferStore(int limit)
          Creates a new StreamBufferStore instance that switches to file storage when the specified number of bytes have been written.
StreamBufferStore(int limit, File targetFile)
          Creates a new StreamBufferStore instance that switches to file storage when the specified number of bytes have been written.
 
Method Summary
 void close()
           
 void flush()
           
 InputStream getInputStream()
          Returns an InputStream for accessing the previously written bytes.
 void reset()
          Clears any data that exists in the buffer.
 int size()
          Returns the current size of the buffer.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeTo(OutputStream outputStream)
          Writes the complete contents of this buffer to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LIMIT

public static final int DEFAULT_LIMIT
Default limit (1 MB)

See Also:
Constant Field Values
Constructor Detail

StreamBufferStore

public StreamBufferStore()
Creates a new StreamBufferStore instance that switches to file storage when DEFAULT_LIMIT bytes have been written.


StreamBufferStore

public StreamBufferStore(int limit)
Creates a new StreamBufferStore instance that switches to file storage when the specified number of bytes have been written.

Parameters:
limit - number of bytes when switching to file will occur

StreamBufferStore

public StreamBufferStore(int limit,
                         File targetFile)
Creates a new StreamBufferStore instance that switches to file storage when the specified number of bytes have been written.

Parameters:
limit - number of bytes when switching to file will occur
targetFile - file to use if written bytes exceed limit, must not be null
Method Detail

size

public int size()
Returns the current size of the buffer.

Returns:
the number of valid bytes in this buffer

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns an InputStream for accessing the previously written bytes.

Returns:
an InputStream, never null
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

writeTo

public void writeTo(OutputStream outputStream)
             throws IOException
Writes the complete contents of this buffer to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count).

Parameters:
outputStream - stream to write to, must not be null
Throws:
IOException - if an I/O error occurs

reset

public void reset()
Clears any data that exists in the buffer.



Copyright © 2011. All Rights Reserved.