RandomAccessFile raf = null;
int flag;
try {
if (!f.exists()) { // this would not be run
if (reading) {
throw new ChaiDBException(ErrorCode.BTREE_TRACKFILE_IO_ERROR);
}
raf = new RandomAccessFile(trackName, "rw");
raf.setLength(4);
flag = OBSOLETE_FLAG;
raf.writeInt(flag);
return;
} else {
raf = new RandomAccessFile(trackName, "rw");
if (!isRightFile(raf) && reading) { // when reading track file, it's bad
throw new ChaiDBException(ErrorCode.BTREE_TRACKFILE_IO_ERROR);
} else {
if (f.length() < 8) {
if (reading) {
throw new ChaiDBException(ErrorCode.BTREE_TRACKFILE_IO_ERROR);
} else {
raf.setLength(8);
flag = OBSOLETE_FLAG;
raf.seek(FLAG_OFF);
raf.writeInt(flag);
if (!reading) {
raf.writeInt(treeid);
} else { // should read a empty track file when backup, it's bad, throw exception
throw new ChaiDBException(ErrorCode.BTREE_TRACKFILE_IO_ERROR);
}
}
return;
} else {