use of org.apache.hadoop.ozone.client.io.KeyInputStream in project ozone by apache.
the class TestChunkStreams method testReadGroupInputStream.
@Test
public void testReadGroupInputStream() throws Exception {
try (KeyInputStream groupInputStream = new KeyInputStream()) {
String dataString = RandomStringUtils.randomAscii(500);
byte[] buf = dataString.getBytes(UTF_8);
int offset = 0;
for (int i = 0; i < 5; i++) {
int tempOffset = offset;
BlockInputStream in = new BlockInputStream(null, 100, null, null, true, null) {
private long pos = 0;
private ByteArrayInputStream in = new ByteArrayInputStream(buf, tempOffset, 100);
@Override
public synchronized void seek(long pos) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public synchronized long getPos() {
return pos;
}
@Override
public boolean seekToNewSource(long targetPos) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public synchronized int read() throws IOException {
return in.read();
}
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
int readLen = in.read(b, off, len);
pos += readLen;
return readLen;
}
};
offset += 100;
groupInputStream.addStream(in);
}
byte[] resBuf = new byte[500];
int len = groupInputStream.read(resBuf, 0, 500);
assertEquals(500, len);
assertEquals(dataString, new String(resBuf, UTF_8));
}
}
Aggregations