use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.
the class BlockedByteArrayTest method testReadSingle.
public void testReadSingle() throws IOException {
int size = 65 * 1024;
BlockedByteArray src = createBlockedByteArray(size);
int read = 0;
while (src.read(read) != -1) {
read++;
}
}
use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.
the class BlockedByteArrayTest method testLength.
public void testLength() throws IOException {
BlockedByteArray src = createBlockedByteArray(0);
assertEquals(0L, src.length());
src.writeByte(0L, (byte) 1);
assertEquals(1L, src.length());
src.writeByte(0L, (byte) 1);
assertEquals(1L, src.length());
src.writeByte(9L, (byte) 2);
assertEquals(10L, src.length());
byte[] bytes = new byte[4096];
Arrays.fill(bytes, (byte) 7);
src.writeBytes(0L, bytes, 0, bytes.length);
assertEquals(bytes.length, src.length());
src.writeBytes(bytes.length, bytes, 0, bytes.length);
assertEquals(2 * bytes.length, src.length());
// Test setLength
src.setLength(55555);
assertEquals(55555, src.length());
src.setLength(44444);
assertEquals(44444, src.length());
}
use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.
the class BlockedByteArrayTest method testLengthNoInitialBlocksWriteMultipleBytes4K.
public void testLengthNoInitialBlocksWriteMultipleBytes4K() {
BlockedByteArray src = new BlockedByteArray();
byte[] buf = new byte[4 * 1024];
Arrays.fill(buf, (byte) 1);
src.writeBytes(0, buf, 0, buf.length);
assertEquals(buf.length, src.length());
Arrays.fill(buf, (byte) 2);
src.writeBytes(buf.length, buf, 0, buf.length);
assertEquals(2 * buf.length, src.length());
src.writeByte(69, (byte) 8);
assertEquals(2 * buf.length, src.length());
}
use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.
the class BlockedByteArrayTest method testLengthNoInitialBlocksWriteMultipleBytes4KPlussAFew.
public void testLengthNoInitialBlocksWriteMultipleBytes4KPlussAFew() {
BlockedByteArray src = new BlockedByteArray();
byte[] buf = new byte[4 * 1024 + 37];
Arrays.fill(buf, (byte) 1);
src.writeBytes(0, buf, 0, buf.length);
assertEquals(buf.length, src.length());
Arrays.fill(buf, (byte) 2);
src.writeBytes(buf.length, buf, 0, buf.length);
assertEquals(2 * buf.length, src.length());
src.writeByte(54, (byte) 7);
assertEquals(2 * buf.length, src.length());
}
use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.
the class BlockedByteArrayTest method createBlockedByteArray.
/**
* Creates a blocked byte array and fills it with data.
*
* @param length requested length
* @return A filled blocked byte array.
* @throws IOException if reading from the source fails
*/
private BlockedByteArray createBlockedByteArray(long length) throws IOException {
BlockedByteArray data = new BlockedByteArray();
InputStream src = new LoopingAlphabetStream(length);
byte[] buf = new byte[4 * 1024];
long pos = 0;
while (pos < length) {
int readFromSrc = src.read(buf);
pos += data.writeBytes(pos, buf, 0, readFromSrc);
}
return data;
}
Aggregations