@Test public void readArrayMultipleExtentsTest() throws IOException { final int n = 10; final byte[] src = new byte[2*n]; for (int i = 0; i < src.length; ++i) { src[i] = (byte) (i % 256); } final List<Map<String,Object>> extents = new ArrayList<Map<String,Object>>(); for (int i = 0, off = 0; i <= n; off += i, ++i) { final Map<String,Object> extent = new HashMap<String,Object>(); extent.put("addr", Long.valueOf(i)); extent.put("len", Long.valueOf(i)); extents.add(extent); } final FSDataInputStream in = new ArrayFSDataInputStream(src); final InputStream eis = new ExtentsInputStream(in, extents); for (int i = 0; i < extents.size(); ++i) { final int rlen = ((Number) extents.get(i).get("len")).intValue(); final byte[] actual = new byte[rlen]; assertEquals(rlen, eis.read(actual, 0, rlen)); final byte[] expected = new byte[rlen]; final int addr = ((Number) extents.get(i).get("addr")).intValue(); System.arraycopy(src, addr, expected, 0, rlen); assertArrayEquals(expected, actual); } }
@Override public int read() throws IOException { final byte[] b = new byte[1]; int rlen; do { rlen = read(b, 0, 1); } while (rlen == 0); return rlen == -1 ? -1 : b[0]; }
ExtentsInputStream extends InputStream { @Override public int read() throws IOException { final byte[] b = new byte[1]; int rlen; do { rlen = read(b, 0, 1); } while (rlen == 0); return rlen == -1 ? -1 : b[0]; } }
ExtentsInputStream extends InputStream { @Override public int read() throws IOException { final byte[] b = new byte[1]; int rlen; do { rlen = read(b, 0, 1); } while (rlen == 0); return rlen == -1 ? -1 : b[0]; } ExtentsInputStream(FSDataInputStream in,
                            List<Map<String,Object>> extents); }
ExtentsInputStream extends InputStream { @Override public int read() throws IOException { final byte[] b = new byte[1]; int rlen; do { rlen = read(b, 0, 1); } while (rlen == 0); return rlen == -1 ? -1 : b[0]; } ExtentsInputStream(FSDataInputStream in,
                            List<Map<String,Object>> extents); @Override int read(); @Override int read(byte[] buf, int off, int len); }
ExtentsInputStream extends InputStream { @Override public int read() throws IOException { final byte[] b = new byte[1]; int rlen; do { rlen = read(b, 0, 1); } while (rlen == 0); return rlen == -1 ? -1 : b[0]; } ExtentsInputStream(FSDataInputStream in,
                            List<Map<String,Object>> extents); @Override int read(); @Override int read(byte[] buf, int off, int len);  }