sequenceinputstream.java
来自「kaffe是一个java虚拟机的源代码。里面包含了一些java例程和标准的jav」· Java 代码 · 共 89 行
JAVA
89 行
package java.io;import java.util.Enumeration;import java.util.Vector;/* * Java core library component. * * Copyright (c) 1997, 1998 * Transvirtual Technologies, Inc. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */public class SequenceInputStream extends InputStream{ private Vector streams = new Vector(); private int currentStreamIdx; private InputStream currentStream;public SequenceInputStream(Enumeration e) { while (e.hasMoreElements()) { streams.addElement(e.nextElement()); } currentStream = (InputStream)streams.elementAt(0);}public SequenceInputStream(InputStream s1, InputStream s2) { streams.addElement(s1); streams.addElement(s2); currentStream = s1;}public int available() throws IOException { if (currentStreamIdx >= streams.size()) { return (0); } else { return (currentStream.available()); }}public void close() throws IOException { for (int stream = currentStreamIdx; stream < streams.size(); stream++) { ((InputStream)streams.elementAt(stream)).close(); } currentStreamIdx = 0; currentStream = null; streams = new Vector();}public int read() throws IOException { if (currentStreamIdx >= streams.size()) { return -1; } for (;;) { final int data = currentStream.read(); if (data != -1) { return (data); } currentStream.close(); currentStreamIdx++; if (currentStreamIdx >= streams.size()) { return -1; } currentStream = (InputStream)streams.elementAt(currentStreamIdx); }}public int read(byte buf[], int pos, int len) throws IOException { if (currentStreamIdx >= streams.size()) { return -1; } for (;;) { final int nr = currentStream.read(buf, pos, len); if (nr != -1) { return (nr); } currentStream.close(); currentStreamIdx++; if (currentStreamIdx >= streams.size()) { return -1; } currentStream = (InputStream)streams.elementAt(currentStreamIdx); }}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?