Package uk.ac.starlink.util
Class DataBufferedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.BufferedOutputStream
-
- uk.ac.starlink.util.DataBufferedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.DataOutput,java.io.Flushable,java.lang.AutoCloseable
public class DataBufferedOutputStream extends java.io.BufferedOutputStream implements java.io.DataOutputBufferedOutputStream subclass implementing the DataOutput interface. This is considerably faster than simply layering a DataOutputStream on top of a BufferedOutputStream.The implementation was largely copied from
nom.tam.util.BufferedDataOutputStream.- Author:
- Mark Taylor, Tom McGlynn
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault buffer size 8192, same as java.io.BufferedOutputStream.
-
Constructor Summary
Constructors Constructor Description DataBufferedOutputStream(java.io.OutputStream out)Constructs a stream with a default buffer size.DataBufferedOutputStream(java.io.OutputStream out, int size)Constructs a stream with a given buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckBuf(int need)Try to ensure there is a given number of bytes in the buffer.voidwriteBoolean(boolean b)voidwriteByte(int b)voidwriteBytes(java.lang.String s)voidwriteChar(int v)voidwriteChars(java.lang.String s)voidwriteCharUTF8(char c)Writes a single character in UTF8 format.voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(java.lang.String s)
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default buffer size 8192, same as java.io.BufferedOutputStream.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataBufferedOutputStream
public DataBufferedOutputStream(java.io.OutputStream out)
Constructs a stream with a default buffer size. The default buffer size is currently 8k.- Parameters:
out- base output stream
-
DataBufferedOutputStream
public DataBufferedOutputStream(java.io.OutputStream out, int size)Constructs a stream with a given buffer size.- Parameters:
out- base output streamsize- buffer size in bytes, must be >=8
-
-
Method Detail
-
writeBoolean
public void writeBoolean(boolean b) throws java.io.IOException- Specified by:
writeBooleanin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeByte
public void writeByte(int b) throws java.io.IOException- Specified by:
writeBytein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeShort
public void writeShort(int v) throws java.io.IOException- Specified by:
writeShortin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeInt
public void writeInt(int v) throws java.io.IOException- Specified by:
writeIntin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeLong
public void writeLong(long v) throws java.io.IOException- Specified by:
writeLongin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChar
public void writeChar(int v) throws java.io.IOException- Specified by:
writeCharin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float v) throws java.io.IOException- Specified by:
writeFloatin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double v) throws java.io.IOException- Specified by:
writeDoublein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String s) throws java.io.IOException- Specified by:
writeBytesin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String s) throws java.io.IOException- Specified by:
writeCharsin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String s) throws java.io.IOException- Specified by:
writeUTFin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeCharUTF8
public void writeCharUTF8(char c) throws java.io.IOExceptionWrites a single character in UTF8 format.- Parameters:
c- character to write- Throws:
java.io.IOException
-
checkBuf
protected void checkBuf(int need) throws java.io.IOExceptionTry to ensure there is a given number of bytes in the buffer. If it's nearly full, it will be flushed ready for more data. This call does not guarantee that the requested number of bytes are free in the buffer; if the request is more than the buffer length, the buffer is simply flushed.- Parameters:
need- number of bytes required- Throws:
java.io.IOException
-
-