*
* @return the paded bucket
*/
public static Bucket pad(Bucket oldBucket, int blockLength, BucketFactory bf, int length) throws IOException {
byte[] hash = BucketTools.hash(oldBucket);
Bucket b = bf.makeBucket(blockLength);
MersenneTwister mt = new MersenneTwister(hash);
OutputStream os = b.getOutputStreamUnbuffered();
try {
BucketTools.copyTo(oldBucket, os, length);
byte[] buf = new byte[BUFFER_SIZE];
for(int x=length;x<blockLength;) {
int remaining = blockLength - x;
int thisCycle = Math.min(remaining, buf.length);
mt.nextBytes(buf); // FIXME??
os.write(buf, 0, thisCycle);
x += thisCycle;
}
os.close();
os = null;
if(b.size() != blockLength)
throw new IllegalStateException("The bucket's size is "+b.size()+" whereas it should be "+blockLength+'!');
return b;
} finally { Closer.close(os); }
}