Detailed sequence input stream

(Watch my blog - "Detailed byte stream" )

SequenceInputStream categories:

The concept :

Represents other input stream is the logical concatenation of
it from the ordered set of input stream begins,
and start reading from the first input stream , until the end of the file ,
followed by a second read from the input stream ,
and so on, until reaching contains the last till the end of the file input stream

This stream can be tough in the information file merge multiple InputStream subclasses .

Well, now, I have to show this flow constructor :

Constructor :

  • SequenceInputStream (InputStream s1, InputStream s2)
    by remembering these two parameters to initialize a newly created SequenceInputStream
    (in sequence to read these two parameters, the first reading s1, then read s2),
  • SequenceInputStream (Enumeration <? Extends InputStream> e)
    Initializes a newly created SequenceInputStream by remembering parameters,
    this parameter must be generated runtime Enumeration type parameters of type InputStream object

Now, I have to show this kind of commonly used API :

Common API :

  • int available ()
    estimates returns read without blocking (or skipped) from the bottom of the current number of bytes in the input stream,
    the method is invoked by a single input stream to the bottom of the current methods
  • void close ()
    Closes this input stream and releases any system resources associated with the stream
  • int read ()
    from this input stream to read the next data byte
  • int read (byte [] b, int off, int len)
    up to len bytes of data from this input stream into a byte array

Well, now, I have to show using the lower part of the API:

package edu.youzg.about_io.about_file.core.Test;

import edu.youzg.about_io.about_file.core.FanInfo;

import java.io.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;

public class Test {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        FileInputStream in1 = new FileInputStream("JoJo.properties");
        DataInputStream in2 = new DataInputStream(new FileInputStream("plantsVSzombies.mp4"));
        SequenceInputStream in = new SequenceInputStream(in1, in2);
        FileOutputStream out = new FileOutputStream(new File("summary.txt"));

        int len = 0;
        byte[] bytes = new byte[1024 * 8];
        while ((len = in.read(bytes))!= -1){
            out.write(bytes,0,len);
            out.flush();
        }
        out.close();
        in.close();

    }

}

Now, I have to show the next two source file information:
Here Insert Picture Description

Here Insert Picture Description

I come to show the next generation of information files:
Here Insert Picture Description
you can see, the two files with different flow packed file, the code is merged into a specified file.

(I "Detailed byte stream" Bowen link: https:////www.cnblogs.com/codderYouzg/p/12418463.html )
(I I / O stream collection of articles Bowen link: HTTPS: //// the WWW .cnblogs.com / codderYouzg / the p-/ 12418404.html )

Guess you like

Origin www.cnblogs.com/codderYouzg/p/12418517.html