int duration;
Date end;
Date veryStart = new Date();
Date start = new Date();
Transaction txn = null;
Directory store = null;
System.out.println("Writing files byte by byte");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
for (int i = 0; i < count; i++) {
String name = i + ".dat";
int length = gen.nextInt() & LENGTH_MASK;
IndexOutput file = store.createOutput(name);
totalLength += length;
for (int j = 0; j < length; j++) {
byte b = (byte) (gen.nextInt() & 0x7F);
file.writeByte(b);
}
file.close();
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to read, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(seed);
start = new Date();
for (int i = 0; i < count; i++) {
if (i % 2 == 0) {
String name = i + ".dat";
store.deleteFile(name);
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
System.out.print(end.getTime() - start.getTime());
System.out.println(" total milliseconds to delete even files");
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to create, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(seed);
start = new Date();
for (int i = 0; i < count; i++) {
int length = gen.nextInt() & LENGTH_MASK;
if (i % 2 != 0) {
String name = i + ".dat";
IndexInput file = store.openInput(name);
if (file.length() != length)
throw new Exception("length incorrect");
for (int j = 0; j < length; j++) {
byte b = (byte) (gen.nextInt() & 0x7F);
if (file.readByte() != b)
throw new Exception("contents incorrect");
}
file.close();
} else {
for (int j = 0; j < length; j++) {
gen.nextInt();
}
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();
duration = (int) (end.getTime() - start.getTime());
System.out.print(duration);
System.out.print(" total milliseconds to read, ");
System.out.print(totalLength / duration);
System.out.println(" kb/s");
try {
txn = env.beginTransaction(null, null);
store = new JEDirectory(txn, index, blocks);
gen = new Random(seed);
start = new Date();
for (int i = 0; i < count; i++) {
if (i % 2 != 0) {
String name = i + ".dat";
store.deleteFile(name);
}
}
} catch (IOException e) {
txn.abort();
txn = null;
throw e;
} catch (DatabaseException e) {
if (txn != null) {
txn.abort();
txn = null;
}
throw e;
} finally {
if (txn != null)
txn.commit();
store.close();
}
end = new Date();