⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferedthreadedinputstream.java

📁 java多线程编程实例_Source
💻 JAVA
字号:
import java.io.*;

// uses ThreadedInputStream

public class BufferedThreadedInputStream 
		extends FilterInputStream {

	// fixed class that does *not* have a synchronized close()
	private static class BISFix extends BufferedInputStream {
		public BISFix(InputStream rawIn, int buffSize) {
			super(rawIn, buffSize);
		}

		public void close() throws IOException {
			if ( in != null ) {
				try {
					in.close();
				} finally {
					in = null;
				}
			}
		}
	}

	public BufferedThreadedInputStream(
				InputStream rawIn, 
				int bufferSize
			) {

		super(rawIn); // super-class' "in" is set below

		// rawIn -> BufferedIS -> ThreadedIS -> 
		//       BufferedIS -> read()

		BISFix bis = new BISFix(rawIn, bufferSize);
		ThreadedInputStream tis = 
				new ThreadedInputStream(bis, bufferSize);

		// Change the protected variable 'in' from the 
		// superclass from rawIn to the correct stream.
		in = new BISFix(tis, bufferSize);
	}

	public BufferedThreadedInputStream(InputStream rawIn) {
		this(rawIn, 2048);
	}

	// Overridden to show that InterruptedIOException might 
	// be thrown.
	public int read() 
			throws InterruptedIOException, IOException {

		return in.read();
	}

	// Overridden to show that InterruptedIOException might 
	// be thrown.
	public int read(byte[] b) 
			throws InterruptedIOException, IOException {

		return in.read(b);
	}

	// Overridden to show that InterruptedIOException might 
	// be thrown.
	public int read(byte[] b, int off, int len) 
			throws InterruptedIOException, IOException {

		return in.read(b, off, len);
	}

	// Overridden to show that InterruptedIOException might 
	// be thrown.
	public long skip(long n) 
			throws InterruptedIOException, IOException {

		return in.skip(n);
	}

	// The remainder of the methods are directly inherited from 
	// FilterInputStream and access "in" in the much the same 
	// way as the methods above do.
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -