SimplePullDataSource implements ISageTVDataSource { @Override public int read(long position, byte[] buffer, int offset, int len) throws IOException { if (!opened) { throw new IOException("read() called on DataSource that is not opened: " + uri); } return fetch(position, buffer, offset, len); } 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 testReadNoPosition() throws Exception { SimplePullDataSource pds = new SimplePullDataSource(); pds.remoteReader = new DataInputStream(new MockInputStream(100)); pds.remoteWriter = new ByteArrayOutputStream(); pds.opened = true; byte buffer[] = new byte[100]; int size = 3 * 9; int read = pds.read(0, buffer, 0, size); assertEquals(size, read); assertEquals(new String(data, 0, size), new String(buffer, 0, size)); }
@Test public void testReadWithPosition() throws Exception { SimplePullDataSource pds = new SimplePullDataSource(); pds.remoteReader = new DataInputStream(new MockInputStream(2000)); pds.remoteWriter = new ByteArrayOutputStream(); pds.opened = true; pds.size = 3000; byte buffer[] = new byte[100]; int size = 3 * 9; int read = pds.read(1000, buffer, 0, size); assertEquals(size, read); assertEquals(new String(data, 0, size), new String(buffer, 0, size)); }