Java stream operations can be divided into byte streams and byte streams.

Source: Internet
Author: User

Java stream operations can be divided into byte streams and byte streams.

1. byte stream

All read Operations inherit from a common superclass java. io. InputStream class.

All write operations inherit from a common superclass java. io. OutputStream class.

Both InputStream and OutputStream are abstract classes.

InputStream has six low-level input streams:

Low-level stream
Stream usage

ByteArrayInputStream
Read data bytes from memory array

FileInputStream
Read data bytes from the local file system

PipedInputStream
Read data bytes from the thread Pipeline

StringBufferInputStream
Reads data bytes from a string.

SequenceInputStream
Reads data bytes from two or more low-level streams, and transfers data from one stream to another when it reaches the end of the stream.

System. in
Read data bytes from the user Console

InputStream also has a subclass: the filter stream java. io. FilterInputStream. The filter stream encapsulates the basic stream for more convenient usage.

The construction method of the FilterInputStream class is FilterInputStream (InputStream). An input stream filter is created on the specified input stream.

Common subclasses of FilterInputStream are as follows:

Filter input stream
Stream usage

BufferedInputStream
Access data by the buffer to improve efficiency

DataInputStream
Reads basic data types from the input stream, such as int, float, double, or even a line of text.

LineNumberInputStream
Maintain a counter Based on the line terminator of the translation. The counter indicates the row being read.

PushbackInputStream
Data bytes can be pushed back to the first part of the stream.

OutputStream (omitted)

The structure of OutputStream is basically the same as that of InputStream.

2. Ghost stream

Note: It was introduced in jdk1.1, And the byte stream above was introduced in jdk1.0. When it is used to process text data, it is better to select the limit stream than the word throttling. However, developers who only use the basic data type can continue to use byte streams.

All read Operations inherit from a common superclass java. io. Reader class.

All write operations inherit from a common superclass java. io. Writer class.

Reader and Writer are also abstract classes.

The common subclass of Reader is as follows:

Low-level Reader
Stream usage

CharArrayReader
Read data from character array

InputStreamReader

FileReader (subclass of InputStreamReader)
Read character sequences from local file systems

StringReader
Read character sequences from strings

PipedReader
Read character sequences from thread Pipelines

InputStreamReader:

InputStreamReader reads data from the input stream and connects the input stream to the reader. For example:

New InputStreamReader (System. in)

Constructor:

InputStreamReader (InputStream)

Use the default character encoding method to create an InputStreamReader.

InputStreamReader (InputStream, String)

Create an InputStreamReader using the named character encoding method.

Common filter readers:

Filter Reader
Stream usage

BufferedReader
Buffer Data Access to improve efficiency

LineNumberReader (subclass of BufferedReader)
Maintain a counter that indicates the row being read.

FilterReader (abstract class)
Provides a class that can be extended when a filter is created.

PushbackReader (subclass of FilterReader)
Allow text data to be pushed back to the reader stream

All these filter readers can pass in a Reader as a constructor parameter.

Writer (omitted)

The structure of Writer is basically the same as that of Reader.

Byte streams are the most basic, and forward streams are proposed to process characters.

New BufferedReader (new InputStreamReader (client. getInputStream (); explanation:

Client. getInputStream () is a byte stream;

InputStreamReader converts byte streams into bytes streams;

BufferedReader caches the primary stream so that you can directly read a row using methods such as readline ().

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.