抽象类InputStream

首先来说一下InputStaram类是一个抽象类,不可以实例化(抽象类为什么不能实例化自行百度),java.io.InputStream类实现了Closeable接口 重写了close()方法;但实际上close方法体是空的,具体的实现方法是有其子类实现的;

再说其read方法是一个抽象方法但其重载方法以及skip方法都是通过调用该抽象方法实现自己的的功能的,子类不再重写;

java.io.InputStream类源码

package java.io;

public abstract class InputStream implements Closeable {
	private static final int MAX_SKIP_BUFFER_SIZE = 2048;

	public abstract int read() throws IOException;

	public int read(byte[] paramArrayOfByte) throws IOException {
		return read(paramArrayOfByte, 0, paramArrayOfByte.length);
	}

	public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2) throws IOException {
		if (paramArrayOfByte == null) {
			throw new NullPointerException();
		}
		if ((paramInt1 < 0) || (paramInt2 < 0) || (paramInt2 > paramArrayOfByte.length - paramInt1)) {
			throw new IndexOutOfBoundsException();
		}
		if (paramInt2 == 0) {
			return 0;
		}
		int i = read();
		if (i == -1) {
			return -1;
		}
		paramArrayOfByte[paramInt1] = ((byte) i);
		int j = 1;
		try {
			while (j < paramInt2) {
				i = read();
				if (i == -1) {
					break;
				}
				paramArrayOfByte[(paramInt1 + j)] = ((byte) i);
				j++;
			}
		} catch (IOException localIOException) {
		}
		return j;
	}

	public long skip(long paramLong) throws IOException {
		long l = paramLong;
		if (paramLong <= 0L) {
			return 0L;
		}
		int j = (int) Math.min(2048L, l);
		byte[] arrayOfByte = new byte[j];
		while (l > 0L) {
			int i = read(arrayOfByte, 0, (int) Math.min(j, l));
			if (i < 0) {
				break;
			}
			l -= i;
		}
		return paramLong - l;
	}

	public int available() throws IOException {
		return 0;
	}

	public void close() throws IOException {
	}

	public synchronized void mark(int paramInt) {
	}

	public synchronized void reset() throws IOException {
		throw new IOException("mark/reset not supported");
	}

	public boolean markSupported() {
		return false;
	}
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dan淡淡的心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值