UnsyncCharArrayReader extends Reader { @Override public int read() throws IOException { if (_buffer == null) { throw new IOException("Stream closed"); } if (_index >= _capacity) { return -1; } return _buffer[_index++]; } UnsyncCharArrayReader(char[] chars);  UnsyncCharArrayReader(char[] chars, int offset, int length); @Override void close(); @Override void mark(int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(char[] chars); @Override int read(char[] chars, int offset, int length); @Override int read(CharBuffer charBuffer); @Override boolean ready(); @Override void reset(); @Override long skip(long skip);  }
@Override @Test public void testBlockRead() throws IOException { UnsyncCharArrayReader unsyncCharArrayReader = new UnsyncCharArrayReader( _BUFFER); int size = _SIZE * 2 / 3; char[] buffer = new char[size]; int read = unsyncCharArrayReader.read(buffer); Assert.assertEquals(size, read); for (int i = 0; i < read; i++) { Assert.assertEquals('a' + i, buffer[i]); } read = unsyncCharArrayReader.read(buffer); Assert.assertEquals(_SIZE - size, read); for (int i = 0; i < read; i++) { Assert.assertEquals('a' + i + size, buffer[i]); } Assert.assertEquals(-1, unsyncCharArrayReader.read(new char[1])); }
@Test public void testBufferRead() throws IOException { UnsyncCharArrayReader unsyncCharArrayReader = new UnsyncCharArrayReader( _BUFFER); int size = _SIZE * 2 / 3; CharBuffer charBuffer = CharBuffer.allocate(size); int read = unsyncCharArrayReader.read(charBuffer); Assert.assertEquals(size, read); for (int i = 0; i < read; i++) { Assert.assertEquals('a' + i, charBuffer.get(i)); } charBuffer.position(0); read = unsyncCharArrayReader.read(charBuffer); Assert.assertEquals(_SIZE - size, read); for (int i = 0; i < read; i++) { Assert.assertEquals('a' + i + size, charBuffer.get(i)); } charBuffer.position(charBuffer.limit()); Assert.assertEquals(0, unsyncCharArrayReader.read(charBuffer)); charBuffer.position(0); Assert.assertEquals(-1, unsyncCharArrayReader.read(charBuffer)); }