Java - IO - Byte Stream

> Procedural Languages > Java > Java - IO (Input/Output) - (File System|File|Console)

1 - About

Byte I/O Operations (Stream) in java

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

Advertising

3 - 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.

4 - Implementation Level

4.1 - High Level (Stream)

All streams are from the Java IO package.

4.1.1 - 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).

Advertising

4.1.2 - 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.

4.1.3 - 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.

4.1.4 - 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.

4.2 - 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.

Advertising

5 - Documentation / Reference

lang/java/io/byte_stream.txt · Last modified: 2019/07/01 09:25 by gerardnico