SimplePullDataSource implements ISageTVDataSource { int readBuffer(byte[] buffer, int offset, int len) throws IOException { int total = 0; int read = 0; while (total < len) { if (VerboseLogging.DATASOURCE_LOGGING && log.isDebugEnabled()) log.debug("read packet: total: {}, len: {}, delta: {}", total, len, (len - total)); read = remoteReader.read(buffer, offset + total, len - total); if (read == -1) { if (total == 0) { log.warn("End of File reached for {}", uri); return -1; } else { return total; } } total += read; } if (VerboseLogging.DATASOURCE_LOGGING) log.debug("Filled buffer with {} bytes", total); return total; } SimplePullDataSource();  SimplePullDataSource(String host); String getUri(); @Override long open(String uri); @Override void close(); @Override long size(); boolean isOpen(); @Override int read(long position, byte[] buffer, int offset, int len); int fetch(long position, byte[] buffer, int offset, int len);  }
@Test public void testReadBufferNoOffset() throws Exception { SimplePullDataSource pds = new SimplePullDataSource(); pds.remoteReader = new DataInputStream(new MockInputStream(100)); byte buffer[] = new byte[100]; int size = 3 * 9; int read = pds.readBuffer(buffer, 0, size); assertEquals(size, read); assertEquals(new String(data, 0, size), new String(buffer, 0, size)); }
@Test public void testReadBufferWithOffset() throws Exception { SimplePullDataSource pds = new SimplePullDataSource(); pds.remoteReader = new DataInputStream(new MockInputStream(100)); byte buffer[] = new byte[100]; int size = 3 * 9; int offset = 5; int read = pds.readBuffer(buffer, offset, size); assertEquals(size, read); assertEquals(new String(data, 0, size), new String(buffer, offset, size)); System.out.println("data[" + new String(buffer, offset, size) + "]"); }