@Test public void testReadZero2() throws Exception { InputStream r = new TextInputStream("test", Charsets.US_ASCII, 1024); byte[] bytes = new byte[30]; assertEquals(2, r.read(bytes, 0, 2)); assertEquals(0, r.read(bytes, 2, 0)); assertEquals(0, r.read(bytes, 2, 0)); assertEquals(2, r.read(bytes, 2, 2)); assertEquals(-1, r.read(bytes, 4, 0)); assertEquals(-1, r.read(bytes, 4, 2)); }
@Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } if (off < 0 || len < 0 || off + len > b.length) { throw new IndexOutOfBoundsException(); } if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } int bytesRead = 0; while (len > 0) { if (this.bbuf.hasRemaining()) { int chunk = Math.min(this.bbuf.remaining(), len); this.bbuf.get(b, off, chunk); off += chunk; len -= chunk; bytesRead += chunk; } else { fillBuffer(); if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { break; } } } if (bytesRead > 0) { return bytesRead; } else { if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } else { return bytesRead; } } }
TextInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } if (off < 0 || len < 0 || off + len > b.length) { throw new IndexOutOfBoundsException(); } if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } int bytesRead = 0; while (len > 0) { if (this.bbuf.hasRemaining()) { int chunk = Math.min(this.bbuf.remaining(), len); this.bbuf.get(b, off, chunk); off += chunk; len -= chunk; bytesRead += chunk; } else { fillBuffer(); if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { break; } } } if (bytesRead > 0) { return bytesRead; } else { if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } else { return bytesRead; } } } }
TextInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } if (off < 0 || len < 0 || off + len > b.length) { throw new IndexOutOfBoundsException(); } if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } int bytesRead = 0; while (len > 0) { if (this.bbuf.hasRemaining()) { int chunk = Math.min(this.bbuf.remaining(), len); this.bbuf.get(b, off, chunk); off += chunk; len -= chunk; bytesRead += chunk; } else { fillBuffer(); if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { break; } } } if (bytesRead > 0) { return bytesRead; } else { if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } else { return bytesRead; } } } TextInputStream(final CharSequence s, final Charset charset, int bufferSize); }
TextInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } if (off < 0 || len < 0 || off + len > b.length) { throw new IndexOutOfBoundsException(); } if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } int bytesRead = 0; while (len > 0) { if (this.bbuf.hasRemaining()) { int chunk = Math.min(this.bbuf.remaining(), len); this.bbuf.get(b, off, chunk); off += chunk; len -= chunk; bytesRead += chunk; } else { fillBuffer(); if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { break; } } } if (bytesRead > 0) { return bytesRead; } else { if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } else { return bytesRead; } } } TextInputStream(final CharSequence s, final Charset charset, int bufferSize); @Override int read(byte[] b, int off, int len); @Override int read(); @Override int read(byte[] b); @Override long skip(long n); @Override int available(); @Override void mark(int readlimit); @Override void reset(); @Override boolean markSupported(); @Override void close(); }
TextInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } if (off < 0 || len < 0 || off + len > b.length) { throw new IndexOutOfBoundsException(); } if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } int bytesRead = 0; while (len > 0) { if (this.bbuf.hasRemaining()) { int chunk = Math.min(this.bbuf.remaining(), len); this.bbuf.get(b, off, chunk); off += chunk; len -= chunk; bytesRead += chunk; } else { fillBuffer(); if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { break; } } } if (bytesRead > 0) { return bytesRead; } else { if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) { return -1; } else { return bytesRead; } } } TextInputStream(final CharSequence s, final Charset charset, int bufferSize); @Override int read(byte[] b, int off, int len); @Override int read(); @Override int read(byte[] b); @Override long skip(long n); @Override int available(); @Override void mark(int readlimit); @Override void reset(); @Override boolean markSupported(); @Override void close();  }