ByteArrayOutputStream write(final Random dataRandom) throws Exception {
// Create the in-memory file and start to write to it.
ByteArrayOutputStream inMemoryFile = new ByteArrayOutputStream();
SimpleSeekableFormatOutputStream out = new SimpleSeekableFormatOutputStream(inMemoryFile);
// Set compression Codec
Configuration conf = new Configuration();
if (codecClass != null) {
conf.setClass(SimpleSeekableFormat.FILEFORMAT_SSF_CODEC_CONF, codecClass,
CompressionCodec.class);
}
out.setConf(conf);
// Write some data
for (int r = 0; r < numRecord; r++) {
byte[] b = new byte[dataRandom.nextInt(maxRecordSize)];
// Generate some compressible random data
UtilsForTests.nextBytes(dataRandom, b, 16);
out.write(b);
if (r % 100 == 99) {
out.flush();
}
}
out.close();
return inMemoryFile;
}