com.devexperts.io
Class StreamOutput

java.lang.Object
  extended by java.io.OutputStream
      extended by com.devexperts.io.BufferedOutput
          extended by com.devexperts.io.StreamOutput
All Implemented Interfaces:
Closeable, DataOutput, Flushable, ObjectOutput

public class StreamOutput
extends BufferedOutput

An implementation of BufferedOutput that writes all data to destination OutputStream.


Field Summary
protected  OutputStream out
           
 
Fields inherited from class com.devexperts.io.BufferedOutput
buffer, EMPTY_BYTE_ARRAY, limit, position
 
Constructor Summary
StreamOutput()
          Creates a new stream output with default buffer capacity.
StreamOutput(int size)
          Creates a new stream output with specified buffer capacity.
StreamOutput(OutputStream out)
          Creates a new stream output with specified destination output stream and default buffer capacity.
StreamOutput(OutputStream out, int size)
          Creates a new stream output with specified destination output stream and buffer capacity.
 
Method Summary
 void close()
           
 void flush()
           
protected  void needSpace()
          This method is invoked when output methods need more space to write data.
 void resetOutput()
          Resets this stream output by releasing destination output stream and resetting position.
 void setOutput(OutputStream out)
          Sets new destination output stream.
 void write(byte[] b, int off, int len)
           
 
Methods inherited from class com.devexperts.io.BufferedOutput
write, write, writeBoolean, writeByte, writeByteArray, writeBytes, writeChar, writeChars, writeCompactInt, writeCompactLong, writeDouble, writeFloat, writeInt, writeLong, writeObject, writeShort, writeUTF, writeUTFChar, writeUTFString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected OutputStream out
Constructor Detail

StreamOutput

public StreamOutput()
Creates a new stream output with default buffer capacity.


StreamOutput

public StreamOutput(int size)
Creates a new stream output with specified buffer capacity.

Parameters:
size - the initial buffer size
Throws:
IllegalArgumentException - if size is not positive

StreamOutput

public StreamOutput(OutputStream out)
Creates a new stream output with specified destination output stream and default buffer capacity.

Parameters:
out - the destination to write to

StreamOutput

public StreamOutput(OutputStream out,
                    int size)
Creates a new stream output with specified destination output stream and buffer capacity.

Parameters:
out - the destination to write to
size - the initial buffer size
Throws:
IllegalArgumentException - if size is not positive
Method Detail

setOutput

public void setOutput(OutputStream out)
Sets new destination output stream. Accepts null to release destination.

Parameters:
out - the destination to write to

resetOutput

public void resetOutput()
Resets this stream output by releasing destination output stream and resetting position.


flush

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

close

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

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface DataOutput
Specified by:
write in interface ObjectOutput
Overrides:
write in class BufferedOutput
Throws:
IOException

needSpace

protected void needSpace()
                  throws IOException
Description copied from class: BufferedOutput
This method is invoked when output methods need more space to write data. This method must ensure that expression (position < limit) is true or throw an exception. This method may block if needed. This method is allowed to update buffer, position and limit fields as needed.

Specified by:
needSpace in class BufferedOutput
Throws:
IOException - if an I/O error occurs


Copyright © 2013 Devexperts. All Rights Reserved.