FastBufferedInputStream.java

net.minecraft.util.FastBufferedInputStream

信息

  • 全限定名:net.minecraft.util.FastBufferedInputStream
  • 类型:public class
  • 包:net.minecraft.util
  • 源码路径:src/main/java/net/minecraft/util/FastBufferedInputStream.java
  • 起始行号:L6
  • 继承:InputStream
  • 职责:

    TODO

字段/常量

  • DEFAULT_BUFFER_SIZE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L7
    • 说明:

      TODO

  • in

    • 类型: InputStream
    • 修饰符: private final
    • 源码定位: L8
    • 说明:

      TODO

  • buffer

    • 类型: byte[]
    • 修饰符: private final
    • 源码定位: L9
    • 说明:

      TODO

  • limit

    • 类型: int
    • 修饰符: private
    • 源码定位: L10
    • 说明:

      TODO

  • position

    • 类型: int
    • 修饰符: private
    • 源码定位: L11
    • 说明:

      TODO

内部类/嵌套类型

构造器

public FastBufferedInputStream(InputStream in) @ L13

  • 构造器名:FastBufferedInputStream
  • 源码定位:L13
  • 修饰符:public

参数:

  • in: InputStream

说明:

TODO

public FastBufferedInputStream(InputStream in, int bufferSize) @ L17

  • 构造器名:FastBufferedInputStream
  • 源码定位:L17
  • 修饰符:public

参数:

  • in: InputStream
  • bufferSize: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public int read() @ L22

  • 方法名:read
  • 源码定位:L22
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public int read(byte[] output, int offset, int length) @ L34

  • 方法名:read
  • 源码定位:L34
  • 返回类型:int
  • 修饰符:public

参数:

  • output: byte[]
  • offset: int
  • length: int

说明:

TODO

public long skip(long count) @ L58

  • 方法名:skip
  • 源码定位:L58
  • 返回类型:long
  • 修饰符:public

参数:

  • count: long

说明:

TODO

public int available() @ L77

  • 方法名:available
  • 源码定位:L77
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public void close() @ L82

  • 方法名:close
  • 源码定位:L82
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private int bytesInBuffer() @ L87

  • 方法名:bytesInBuffer
  • 源码定位:L87
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private void fill() @ L91

  • 方法名:fill
  • 源码定位:L91
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

代码

public class FastBufferedInputStream extends InputStream {
    private static final int DEFAULT_BUFFER_SIZE = 8192;
    private final InputStream in;
    private final byte[] buffer;
    private int limit;
    private int position;
 
    public FastBufferedInputStream(InputStream in) {
        this(in, 8192);
    }
 
    public FastBufferedInputStream(InputStream in, int bufferSize) {
        this.in = in;
        this.buffer = new byte[bufferSize];
    }
 
    @Override
    public int read() throws IOException {
        if (this.position >= this.limit) {
            this.fill();
            if (this.position >= this.limit) {
                return -1;
            }
        }
 
        return Byte.toUnsignedInt(this.buffer[this.position++]);
    }
 
    @Override
    public int read(byte[] output, int offset, int length) throws IOException {
        int availableInBuffer = this.bytesInBuffer();
        if (availableInBuffer <= 0) {
            if (length >= this.buffer.length) {
                return this.in.read(output, offset, length);
            }
 
            this.fill();
            availableInBuffer = this.bytesInBuffer();
            if (availableInBuffer <= 0) {
                return -1;
            }
        }
 
        if (length > availableInBuffer) {
            length = availableInBuffer;
        }
 
        System.arraycopy(this.buffer, this.position, output, offset, length);
        this.position += length;
        return length;
    }
 
    @Override
    public long skip(long count) throws IOException {
        if (count <= 0L) {
            return 0L;
        } else {
            long availableInBuffer = this.bytesInBuffer();
            if (availableInBuffer <= 0L) {
                return this.in.skip(count);
            } else {
                if (count > availableInBuffer) {
                    count = availableInBuffer;
                }
 
                this.position = (int)(this.position + count);
                return count;
            }
        }
    }
 
    @Override
    public int available() throws IOException {
        return this.bytesInBuffer() + this.in.available();
    }
 
    @Override
    public void close() throws IOException {
        this.in.close();
    }
 
    private int bytesInBuffer() {
        return this.limit - this.position;
    }
 
    private void fill() throws IOException {
        this.limit = 0;
        this.position = 0;
        int actuallyRead = this.in.read(this.buffer, 0, this.buffer.length);
        if (actuallyRead > 0) {
            this.limit = actuallyRead;
        }
    }
}

引用的其他类