File size: 2,577 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package net.minecraft.util;

import java.io.IOException;
import java.io.InputStream;

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 p_196566_) {
        this(p_196566_, 8192);
    }

    public FastBufferedInputStream(InputStream p_196568_, int p_196569_) {
        this.in = p_196568_;
        this.buffer = new byte[p_196569_];
    }

    @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[] p_196576_, int p_196577_, int p_196578_) throws IOException {
        int i = this.bytesInBuffer();
        if (i <= 0) {
            if (p_196578_ >= this.buffer.length) {
                return this.in.read(p_196576_, p_196577_, p_196578_);
            }

            this.fill();
            i = this.bytesInBuffer();
            if (i <= 0) {
                return -1;
            }
        }

        if (p_196578_ > i) {
            p_196578_ = i;
        }

        System.arraycopy(this.buffer, this.position, p_196576_, p_196577_, p_196578_);
        this.position += p_196578_;
        return p_196578_;
    }

    @Override
    public long skip(long p_196580_) throws IOException {
        if (p_196580_ <= 0L) {
            return 0L;
        } else {
            long i = (long)this.bytesInBuffer();
            if (i <= 0L) {
                return this.in.skip(p_196580_);
            } else {
                if (p_196580_ > i) {
                    p_196580_ = i;
                }

                this.position = (int)((long)this.position + p_196580_);
                return p_196580_;
            }
        }
    }

    @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 i = this.in.read(this.buffer, 0, this.buffer.length);
        if (i > 0) {
            this.limit = i;
        }
    }
}