use of com.google.common.io.InputSupplier in project cdap by caskdata.
the class TextStreamBodyConsumerTest method generateFile.
@Override
protected ContentInfo generateFile(final int recordCount) throws IOException {
return new FileContentInfo(generateFile(TMP_FOLDER.newFile(), recordCount)) {
@Override
public boolean verify(Map<String, String> headers, InputSupplier<? extends InputStream> contentSupplier) throws IOException {
byte[] buf = null;
InputStream input = contentSupplier.getInput();
try {
for (int i = 0; i < recordCount; i++) {
byte[] expected = ("Message number " + i).getBytes(Charsets.UTF_8);
buf = ensureCapacity(buf, expected.length);
ByteStreams.readFully(input, buf, 0, expected.length);
if (Bytes.compareTo(expected, 0, expected.length, buf, 0, expected.length) != 0) {
return false;
}
}
return true;
} finally {
input.close();
}
}
};
}
Aggregations