Table of Contents

About

Byte I/O Operations (Stream) in java

Programs use byte streams to perform input and output of 8-bit bytes.

Super Classes

All byte stream classes are descended from this two class:

  • input stream to read byte or byte array (buffer). All implementations extends the InputStream abstract class.
  • output stream to write byte or byte array (buffer). All implementations extends the OutputStream abstract class.

Implementation Level

High Level (Stream)

All streams are from the Java IO package.

Byte Stream

All other stream types are built on byte streams.

Stream Operations Logical Unit Description
FileInputStream Read Byte A FileInputStream read one byte at a time.
FileOutputStream Write Byte A file output stream write to a File or to a FileDescriptor one byte at a time.

FileInputStream and FileOutputStream use an int variable to read to and write from.

in = new FileInputStream(Parameters.FILE_PATH_READ);
int c = in.read();

It holds a byte value in its last 8 bits. (In character stream, the int holds a character in its last 16 bits).

Buffered Byte Stream

Stream Operations Logical Unit Description
ByteArrayInputStream Read Buffer (ByteArray) A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream.
ByteArrayOutputStream Write Buffer (ByteArray) This class implements an output stream in which the data is written into a byte array.
BufferedInputStream Read Buffer (ByteArray) A BufferedInputStream adds functionality on buffer streams-namely, the support the mark and reset methods.
BufferedOutputStream Write Buffer (ByteArray) The class implements a buffered output stream.

Piped Byte Stream

Stream Operations Logical Unit Description
PipedInputStream Pipe Read Na A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream.
PipedOutputStream Pipe Write Na A piped output stream can be connected to a piped input stream to create a communications pipe.

Random Access Byte Stream

Stream Operations Logical Unit Description
RandomAccessFile Pointer Read/Write Byte of Array Instances of this class support both reading and writing to a random access file.

Low Level (FileChannel)

FileInputStream, FileOutputStream and RandomAccessFile can return a FileChannel for low-level I/O.

The channels class are from the Java NIO Package.

Documentation / Reference