Sequenceinputstream (sequential input stream) Example

Source: Internet
Author: User
/* The sequenceinputstream class allows multiple inputstream streams to be connected. The construction of sequenceinputstream is different from any other inputstream. The sequenceinputstream constructor either uses a pair of inputstream or an enumeration of inputstream. The output is as follows: sequenceinputstream (inputstream first, inputstream second) sequenceinputstream (enumeration streamenum, this class meets the read requirements for reading the first inputstream and then forwarding the second stream. When enumeration is used, it continues to read all inputstream streams until the last one is read. Text.txtand file2.txt must be in the current directory. * /// Demonstrate squenced input.
Import java. Io .*;
Import java. util .*;
Class inputstreamenumerator implements enumeration {
Private enumeration files;
Public inputstreamenumerator (vector files ){
This. Files = files. Elements ();
}
Public Boolean hasmoreelements (){
Return files. hasmoreelements ();
}
Public object nextelement (){
Try {
Return new fileinputstream (files. nextelement (). tostring ());
} Catch (exception e ){
Return NULL;
}
}
}
Class sequenceinputstreamdemo {
Public static void main (string [] ARGs) throws exception {
Int C;
Vector files = new vector ();
Files. addelement ("text.txt ");
Files. addelement ("file2.txt ");

Inputstreamenumerator E = new inputstreamenumerator (files );
Inputstream input = new sequenceinputstream (E );
While (C = input. Read ())! =-1 ){
System. Out. Print (char) C );
}
Input. Close ();
}
}

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.