# 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`

public class DataBufferedOutputStream extends BufferedOutputStream implements DataOutput
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

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_BUFFER_SIZE`
Default buffer size 8192, same as java.io.BufferedOutputStream.

### Fields inherited from class BufferedOutputStream

`buf, count`

### Fields inherited from class FilterOutputStream

`out`

## Constructor Summary

Constructors
Constructor
Description
`DataBufferedOutputStream(OutputStream out)`
Constructs a stream with a default buffer size.
`DataBufferedOutputStream(OutputStream out, int size)`
Constructs a stream with a given buffer size.

## Method Summary

Modifier and Type
Method
Description
`protected 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`
`writeUTF(String s)`

### Methods inherited from class BufferedOutputStream

`flush, write, write`

### Methods inherited from class FilterOutputStream

`close, write`

### Methods inherited from class OutputStream

`nullOutputStream`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface DataOutput

`write, write, write`

## Field Details

### 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 Details

### DataBufferedOutputStream

public DataBufferedOutputStream(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(OutputStream out, int size)
Constructs a stream with a given buffer size.

Parameters:
  `out` - base output stream
  `size` - buffer size in bytes, must be >=8

## Method Details

### writeBoolean

public void writeBoolean(boolean b) throws IOException

Specified by:
  `writeBoolean` in interface `DataOutput`
Throws:
  `IOException`

### writeByte

public void writeByte(int b) throws IOException

Specified by:
  `writeByte` in interface `DataOutput`
Throws:
  `IOException`

### writeShort

public void writeShort(int v) throws IOException

Specified by:
  `writeShort` in interface `DataOutput`
Throws:
  `IOException`

### writeInt

public void writeInt(int v) throws IOException

Specified by:
  `writeInt` in interface `DataOutput`
Throws:
  `IOException`

### writeLong

public void writeLong(long v) throws IOException

Specified by:
  `writeLong` in interface `DataOutput`
Throws:
  `IOException`

### writeChar

public void writeChar(int v) throws IOException

Specified by:
  `writeChar` in interface `DataOutput`
Throws:
  `IOException`

### writeFloat

public void writeFloat(float v) throws IOException

Specified by:
  `writeFloat` in interface `DataOutput`
Throws:
  `IOException`

### writeDouble

public void writeDouble(double v) throws IOException

Specified by:
  `writeDouble` in interface `DataOutput`
Throws:
  `IOException`

### writeBytes

public void writeBytes(String s) throws IOException

Specified by:
  `writeBytes` in interface `DataOutput`
Throws:
  `IOException`

### writeChars

public void writeChars(String s) throws IOException

Specified by:
  `writeChars` in interface `DataOutput`
Throws:
  `IOException`

### writeUTF

public void writeUTF(String s) throws IOException

Specified by:
  `writeUTF` in interface `DataOutput`
Throws:
  `IOException`

### writeCharUTF8

public void writeCharUTF8(char c) throws IOException
Writes a single character in UTF8 format.

Parameters:
  `c` - character to write
Throws:
  `IOException`

### checkBuf

protected void checkBuf(int need) throws IOException
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`