SequenceInputStream SequenceInputStream(Enumeration) in Java

SequenceInputStream(Enumeration): This method is available in the java.io.SequenceInputStream class of Java.

Syntax:

java.io.SequenceInputStream.SequenceInputStream(Enumeration<? extends InputStream> e)

This method takes one argument. This method initializes a newly created SequenceInputStream by remembering the argument, which must be an Enumeration that produces objects whose run-time type is InputStream.

The input streams that are produced by the enumeration will be read, in order, to provide the bytes to be read from this SequenceInputStream.

Parameters: One parameter is required for this method.

e: an enumeration of input streams.

Exceptions: NA

Approach

Java

import java.io.FileInputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.Enumeration;
import java.util.Vector;

public class SequenceInputStreamSequenceInputStream2 {
    public static void main(String[] args) throws IOException {

        FileInputStream fin = new FileInputStream("D:\\hello.txt");
        FileInputStream fin2 = new FileInputStream("D:\\hell.txt");

        Vector<FileInputStream> v =
new Vector<FileInputStream>();
        v.add(fin);
        v.add(fin2);

        Enumeration<FileInputStream> e = v.elements();
        SequenceInputStream sequenceInputStream =
new SequenceInputStream(e);
        System.out.println(sequenceInputStream);
        sequenceInputStream.close();

    }
}

Output:

java.io.SequenceInputStream@2401f4c3


Some other methods of SequenceInputStream

available(): This method returns an estimate of the number of bytes that can be read (or skipped over) from the current underlying input stream without blocking the next invocation of a method for the current underlying input stream.

close(): This method closes this input stream and releases any system resources associated with the stream.

read(): This method reads the next byte of data from this input stream. 

read(byte[], int, int): This method reads up to len bytes of data from this input stream into an array of bytes.

SequenceInputStream(InputStream, InputStream): This method initializes a newly created SequenceInputStreamby remembering the two arguments, which will be read in order, first s1 and then s2, to provide the bytes to be read from this SequenceInputStream.

SequenceInputStream(Enumeration): This method initializes a newly created SequenceInputStream by remembering the argument, which must be an Enumeration that produces objects whose run-time type is InputStream.

No comments:

Post a Comment