Array flow, data flow, stream objects

A. Array stream

1. The source and destination stream files may be in addition to, or may be a computer memory.

2. The array of flow can be divided into two categories:

(1) byte array stream

1) the input stream:
Constructors:
A ByteArrayInputStream (byte [] buf);
source byte array stream this constructor is a parameter buf byte units all the specified array.

ByteArrayInputStream (byte [] buf, int
offset, int length); source byte array configuration method of this stream is specified array buf order to take unit length bytes from offset.

Common methods:
public int Read ();
This method may be sequentially read a byte from the source, the return value of the read-out byte.

public int read (byte [] b
, int off, int len); the method may be sequentially read out from the source parameter len specifies the number of bytes, and reads out the parameter b stored in the specified byte array, b parameter read off the specified array of bytes starting position, returns the number of bytes actually read, if not read the byte read method returns -1.

2) an output stream:
Constructors:
ByteArrayOutputStream ();
while the process configuration space point byte array output a default buffer size is 32 bytes, if the number of bytes written to the output buffer is greater than the buffer flow, buffer capacity will automatically increase.

ByteArrayOutputStream (int size);
initial size of this method constructs byte array output stream buffer pointed to by the parameter specified size, if the number of bytes written to the output buffer is greater than the buffer flow, the buffer capacity will be automatically increase.

Common methods:
public void Write (int B);
ByteArrayOutputStream may invoke this method to sequentially write a byte buffer.

public void write (byte [] b
, int off, int len); the method may be specified in the parameter b len bytes are sequentially written to the buffer, off parameter specifies the byte written starting from b position.

public byte [] toByteArray ();
the method may return an output stream of bytes written to all buffers.

(2) character array stream: the stream byte array to Byte Char, otherwise identical.

II. Data Flow

1. What is a stream?
DataOutputStream DataInputStream class objects created and called a data input streams and data output streams.

2. What is its role?
They allow the program by pressing the machine-independent style java read the raw data, that is, when reading a value, this value should not have to care about is the number of bytes.

3. The method of construction:
1) data input stream:
DataInputStream (in the InputStream);
a data input stream for this constructor creates a point in the bottom of the input stream specified by the parameters.

2) data output stream
DataOutputStream (OutputStream out);
a data output stream this constructor creates a point specified by the parameter output stream out the bottom.

4. A common method
Close ();
Close stream.

the readBoolean ();
reading a Boolean value.

the readByte ();
read a byte.

the readChar ();
reading a character.

the readDouble ();
reading a double-precision floating-point value.

the readFloat ();
read a single-precision floating-point value.

the readInt ();
reads an integer value.

the readLong ();
reading a long integer.

the readShort ();
reading a short value.

readUnsignedByte ();
read an unsigned byte.

readUnsignedShort ();
read an unsigned short integer value.

the readUTF ();
reading a UTF string.

skipBytes (int n);
skip a given number of bytes.

writeBoolean (boolean v);
writes a Boolean value.

writeBytes (String s);
Write a string

writeChars (String s);
Write a string

writeDouble (double v);
writes a double-precision floating-point value

writeFloat (float v);
write single-precision floating-point value a

writeInt (int v);
writes an integer value

writeLong (long v);
writing a long integer

writeShort (int v);
writing a short value

writeUTF (String s);
Writes a UTF string

III. Object flow

1. What is the object stream?
Objects created with an object class called ObjectOutputStream and ObjectInputStream input (output) stream.

2. The effect of
the object input (output) may be a stream object is written to a file (or to read an object file).

3. Methods

ObjectInputStream (InputStream in);
This method is the constructor object input stream.
the readObject ();
This method reads an object in the program.

ObjectOutputStream (OutputStream out);
This method is an object constructor output stream.
writeObject (object obj);
This method may be written to a file obj.

Published 35 original articles · won praise 0 · Views 1287

Guess you like

Origin blog.csdn.net/c1776167012/article/details/104178687