home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class BufferedInputStream extends FilterInputStream {
- private static int defaultBufferSize = 2048;
- protected byte[] buf;
- protected int count;
- protected int pos;
- protected int markpos;
- protected int marklimit;
-
- private void ensureOpen() throws IOException {
- if (super.in == null) {
- throw new IOException("Stream closed");
- }
- }
-
- public BufferedInputStream(InputStream var1) {
- this(var1, defaultBufferSize);
- }
-
- public BufferedInputStream(InputStream var1, int var2) {
- super(var1);
- this.markpos = -1;
- if (var2 <= 0) {
- throw new IllegalArgumentException("Buffer size <= 0");
- } else {
- this.buf = new byte[var2];
- }
- }
-
- private void fill() throws IOException {
- if (this.markpos < 0) {
- this.pos = 0;
- } else if (this.pos >= this.buf.length) {
- if (this.markpos > 0) {
- int var1 = this.pos - this.markpos;
- System.arraycopy(this.buf, this.markpos, this.buf, 0, var1);
- this.pos = var1;
- this.markpos = 0;
- } else if (this.buf.length >= this.marklimit) {
- this.markpos = -1;
- this.pos = 0;
- } else {
- int var3 = this.pos * 2;
- if (var3 > this.marklimit) {
- var3 = this.marklimit;
- }
-
- byte[] var2 = new byte[var3];
- System.arraycopy(this.buf, 0, var2, 0, this.pos);
- this.buf = var2;
- }
- }
-
- this.count = this.pos;
- int var4 = super.in.read(this.buf, this.pos, this.buf.length - this.pos);
- if (var4 > 0) {
- this.count = var4 + this.pos;
- }
-
- }
-
- public synchronized int read() throws IOException {
- this.ensureOpen();
- if (this.pos >= this.count) {
- this.fill();
- if (this.pos >= this.count) {
- return -1;
- }
- }
-
- return this.buf[this.pos++] & 255;
- }
-
- private int read1(byte[] var1, int var2, int var3) throws IOException {
- int var4 = this.count - this.pos;
- if (var4 <= 0) {
- if (var3 >= this.buf.length && this.markpos < 0) {
- return super.in.read(var1, var2, var3);
- }
-
- this.fill();
- var4 = this.count - this.pos;
- if (var4 <= 0) {
- return -1;
- }
- }
-
- int var5 = var4 < var3 ? var4 : var3;
- System.arraycopy(this.buf, this.pos, var1, var2, var5);
- this.pos += var5;
- return var5;
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
- this.ensureOpen();
- if ((var2 | var3 | var2 + var3 | var1.length - (var2 + var3)) < 0) {
- throw new IndexOutOfBoundsException();
- } else if (var3 == 0) {
- return 0;
- } else {
- int var4 = this.read1(var1, var2, var3);
- if (var4 <= 0) {
- return var4;
- } else {
- while(var4 < var3 && super.in.available() > 0) {
- int var5 = this.read1(var1, var2 + var4, var3 - var4);
- if (var5 <= 0) {
- break;
- }
-
- var4 += var5;
- }
-
- return var4;
- }
- }
- }
-
- public synchronized long skip(long var1) throws IOException {
- this.ensureOpen();
- if (var1 <= 0L) {
- return 0L;
- } else {
- long var3 = (long)(this.count - this.pos);
- if (var3 <= 0L) {
- if (this.markpos < 0) {
- return super.in.skip(var1);
- }
-
- this.fill();
- var3 = (long)(this.count - this.pos);
- if (var3 <= 0L) {
- return 0L;
- }
- }
-
- long var5 = var3 < var1 ? var3 : var1;
- this.pos = (int)((long)this.pos + var5);
- return var5;
- }
- }
-
- public synchronized int available() throws IOException {
- this.ensureOpen();
- return this.count - this.pos + super.in.available();
- }
-
- public synchronized void mark(int var1) {
- this.marklimit = var1;
- this.markpos = this.pos;
- }
-
- public synchronized void reset() throws IOException {
- this.ensureOpen();
- if (this.markpos < 0) {
- throw new IOException("Resetting to invalid mark");
- } else {
- this.pos = this.markpos;
- }
- }
-
- public boolean markSupported() {
- return true;
- }
-
- public void close() throws IOException {
- if (super.in != null) {
- super.in.close();
- super.in = null;
- this.buf = null;
- }
- }
- }
-