Class DataBufferedOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.BufferedOutputStream
uk.ac.starlink.util.DataBufferedOutputStream
- All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable
BufferedOutputStream 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
FieldsModifier and TypeFieldDescriptionstatic final intDefault buffer size 8192, same as java.io.BufferedOutputStream.Fields inherited from class BufferedOutputStream
buf, countFields inherited from class FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a stream with a default buffer size.DataBufferedOutputStream(OutputStream out, int size) Constructs a stream with a given buffer size. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckBuf(int need) Try to ensure there is a given number of bytes in the buffer.voidwriteBoolean(boolean b) voidwriteByte(int b) voidwriteBytes(String s) voidwriteChar(int v) voidwriteChars(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) voidMethods inherited from class BufferedOutputStream
flush, write, writeMethods inherited from class FilterOutputStream
close, writeMethods inherited from class OutputStream
nullOutputStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataOutput
write, write, write
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size 8192, same as java.io.BufferedOutputStream.- See Also:
-
-
Constructor Details
-
DataBufferedOutputStream
Constructs a stream with a default buffer size. The default buffer size is currently 8k.- Parameters:
out- base output stream
-
DataBufferedOutputStream
Constructs a stream with a given buffer size.- Parameters:
out- base output streamsize- buffer size in bytes, must be >=8
-
-
Method Details
-
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
writeCharUTF8
Writes a single character in UTF8 format.- Parameters:
c- character to write- Throws:
IOException
-
checkBuf
Try 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:
IOException
-