com.devexperts.io
Class BufferedOutput

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

public abstract class BufferedOutput
extends OutputStream
implements ObjectOutput

An efficient buffered implementation of data output API. It is attributed with underlying byte buffer, position and limit:


Field Summary
protected  byte[] buffer
           
protected static byte[] EMPTY_BYTE_ARRAY
           
protected  int limit
           
protected  int position
           
 
Constructor Summary
protected BufferedOutput()
          Creates new instance with empty buffer.
 
Method Summary
protected abstract  void needSpace()
          This method is invoked when output methods need more space to write data.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeByteArray(byte[] bytes)
          Writes an array of bytes in a compact encapsulation format.
 void writeBytes(String str)
           
 void writeChar(int v)
           
 void writeChars(String str)
           
 void writeCompactInt(int v)
          Writes an int value in a compact format (see IOUtil).
 void writeCompactLong(long v)
          Writes a long value in a compact format (see IOUtil).
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeObject(Object obj)
           
 void writeShort(int v)
           
 void writeUTF(String str)
           
 void writeUTFChar(int codePoint)
          Writes a Unicode code point in a UTF-8 format.
 void writeUTFString(String str)
          Writes a string in a UTF-8 format with compact encapsulation (see IOUtil).
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.ObjectOutput
close, flush
 

Field Detail

EMPTY_BYTE_ARRAY

protected static final byte[] EMPTY_BYTE_ARRAY

buffer

protected byte[] buffer

position

protected int position

limit

protected int limit
Constructor Detail

BufferedOutput

protected BufferedOutput()
Creates new instance with empty buffer.

Method Detail

needSpace

protected abstract void needSpace()
                           throws IOException
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.

Throws:
IOException - if an I/O error occurs

write

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

write

public final void write(byte[] b)
                 throws IOException
Specified by:
write in interface DataOutput
Specified by:
write in interface ObjectOutput
Overrides:
write 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 OutputStream
Throws:
IOException

writeBoolean

public final void writeBoolean(boolean v)
                        throws IOException
Specified by:
writeBoolean in interface DataOutput
Throws:
IOException

writeByte

public final void writeByte(int v)
                     throws IOException
Specified by:
writeByte in interface DataOutput
Throws:
IOException

writeShort

public final void writeShort(int v)
                      throws IOException
Specified by:
writeShort in interface DataOutput
Throws:
IOException

writeChar

public final void writeChar(int v)
                     throws IOException
Specified by:
writeChar in interface DataOutput
Throws:
IOException

writeInt

public final void writeInt(int v)
                    throws IOException
Specified by:
writeInt in interface DataOutput
Throws:
IOException

writeLong

public final void writeLong(long v)
                     throws IOException
Specified by:
writeLong in interface DataOutput
Throws:
IOException

writeFloat

public final void writeFloat(float v)
                      throws IOException
Specified by:
writeFloat in interface DataOutput
Throws:
IOException

writeDouble

public final void writeDouble(double v)
                       throws IOException
Specified by:
writeDouble in interface DataOutput
Throws:
IOException

writeBytes

public final void writeBytes(String str)
                      throws IOException
Specified by:
writeBytes in interface DataOutput
Throws:
IOException

writeChars

public final void writeChars(String str)
                      throws IOException
Specified by:
writeChars in interface DataOutput
Throws:
IOException

writeUTF

public final void writeUTF(String str)
                    throws IOException
Specified by:
writeUTF in interface DataOutput
Throws:
IOException

writeObject

public final void writeObject(Object obj)
                       throws IOException
Specified by:
writeObject in interface ObjectOutput
Throws:
IOException

writeCompactInt

public final void writeCompactInt(int v)
                           throws IOException
Writes an int value in a compact format (see IOUtil). Equivalent to IOUtil.writeCompactInt(java.io.DataOutput, int) method.

Parameters:
v - the int value to be written
Throws:
IOException - if an I/O error occurs

writeCompactLong

public final void writeCompactLong(long v)
                            throws IOException
Writes a long value in a compact format (see IOUtil). Equivalent to IOUtil.writeCompactLong(java.io.DataOutput, long) method.

Parameters:
v - the long value to be written
Throws:
IOException - if an I/O error occurs

writeByteArray

public final void writeByteArray(byte[] bytes)
                          throws IOException
Writes an array of bytes in a compact encapsulation format. This method defines length as a number of bytes. Equivalent to IOUtil.writeByteArray(java.io.DataOutput, byte[]) method.

Parameters:
bytes - the byte array to be written
Throws:
IOException - if an I/O error occurs

writeUTFChar

public final void writeUTFChar(int codePoint)
                        throws IOException
Writes a Unicode code point in a UTF-8 format. The surrogate code points are accepted and written in a CESU-8 format. Equivalent to IOUtil.writeUTFChar(java.io.DataOutput, int) method.

Parameters:
codePoint - the code point to be written
Throws:
UTFDataFormatException - if codePoint is not a valid Unicode character
IOException - if an I/O error occurs

writeUTFString

public final void writeUTFString(String str)
                          throws IOException
Writes a string in a UTF-8 format with compact encapsulation (see IOUtil). Unpaired surrogate code points are accepted and written in a CESU-8 format. This method defines length as a number of bytes. Equivalent to IOUtil.writeUTFString(java.io.DataOutput, java.lang.String) method.

Parameters:
str - the string to be written
Throws:
UTFDataFormatException - if str is too long
IOException - if an I/O error occurs


Copyright © 2013 Devexperts. All Rights Reserved.