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:
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 int
Default buffer size 8192, same as java.io.BufferedOutputStream.Fields inherited from class java.io.BufferedOutputStream
buf, count
Fields inherited from class java.io.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 void
checkBuf
(int need) Try to ensure there is a given number of bytes in the buffer.void
writeBoolean
(boolean b) void
writeByte
(int b) void
writeBytes
(String s) void
writeChar
(int v) void
writeChars
(String s) void
writeCharUTF8
(char c) Writes a single character in UTF8 format.void
writeDouble
(double v) void
writeFloat
(float v) void
writeInt
(int v) void
writeLong
(long v) void
writeShort
(int v) void
Methods inherited from class java.io.BufferedOutputStream
flush, write, write
Methods inherited from class java.io.FilterOutputStream
close, write
Methods inherited from class java.io.OutputStream
nullOutputStream
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.io.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:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeShort
- Specified by:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
- Specified by:
writeLong
in interfaceDataOutput
- Throws:
IOException
-
writeChar
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
- Specified by:
writeUTF
in 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
-