@Override public int read() throws IOException { byte[] b = new byte[1]; int bytesRead = read(b, 0, 1); if (bytesRead == -1) return bytesRead; return b[0]; }
@Override public int read() throws IOException { byte[] b = new byte[1]; int bytesRead = read(b, 0, 1); if (bytesRead == -1) return bytesRead; return b[0]; }
@Override public int read() throws IOException { byte[] b = new byte[1]; int bytesRead = read(b, 0, 1); if (bytesRead == -1) return bytesRead; return b[0]; }
@Override public int read() throws IOException { byte[] b = new byte[1]; int bytesRead = read(b, 0, 1); if (bytesRead == -1) return bytesRead; return b[0]; }
/** Tests the simple use case for InputSubstream */ @Test public void testSimple() throws Exception { InputSubstream in = new InputSubstream(new ByteArrayInputStream( sampleData.getBytes(StringUtils.UTF8)), 10, 10, true); assertEquals(10, in.available()); byte[] buffer = new byte[10]; assertEquals(10, in.read(buffer)); assertEquals("1234567890", new String(buffer, StringUtils.UTF8)); assertEquals(0, in.available()); CountingInputStream countingStream = new CountingInputStream(new InputSubstream( new ByteArrayInputStream(sampleData.getBytes(StringUtils.UTF8)), 10, 10, true)); int c; System.out.print("Data: "); while ((c = countingStream.read()) > -1) { System.out.print((char) c); } System.out.println(); assertEquals(10, countingStream.getByteCount()); countingStream = new CountingInputStream(new InputSubstream(new ByteArrayInputStream( sampleData.getBytes(StringUtils.UTF8)), 10, 10, true)); byte[] bytes = new byte[1]; System.out.print("Data: "); while ((c = countingStream.read(bytes)) > -1) { System.out.print((char) bytes[0]); } System.out.println(); assertEquals(10, countingStream.getByteCount()); }
assertEquals(5, in.read(buffer)); assertEquals("12345", new String(buffer, StringUtils.UTF8)); assertEquals(5, in.available()); assertEquals(5, in.read(buffer)); assertEquals("12345", new String(buffer, StringUtils.UTF8)); assertEquals(5, in.available()); assertEquals(5, in.read(buffer)); assertEquals("67890", new String(buffer, StringUtils.UTF8)); assertEquals(0, in.available());