|
|
|
@ -889,24 +889,17 @@ public class ArrayStack implements BLOB {
|
|
|
|
|
final ReferenceFactory<ReferenceType> factory,
|
|
|
|
|
final int keylength, final ByteOrder order, final File f1, final File f2, final File newFile, final int writeBuffer) {
|
|
|
|
|
// iterate both files and write a new one
|
|
|
|
|
|
|
|
|
|
CloneableIterator<ReferenceContainer<ReferenceType>> i1 = null, i2 = null;
|
|
|
|
|
ReferenceIterator<ReferenceType> i1 = null;
|
|
|
|
|
try {
|
|
|
|
|
i1 = new ReferenceIterator<ReferenceType>(f1, factory);
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
Log.logSevere("ArrayStack", "cannot merge because input files cannot be read, f1 = " + f1.toString() + ": " + e.getMessage(), e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
ReferenceIterator<ReferenceType> i2 = null;
|
|
|
|
|
try {
|
|
|
|
|
i2 = new ReferenceIterator<ReferenceType>(f2, factory);
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
Log.logSevere("ArrayStack", "cannot merge because input files cannot be read, f2 = " + f2.toString() + ": " + e.getMessage(), e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!i1.hasNext()) {
|
|
|
|
|
if (i2.hasNext()) {
|
|
|
|
|
HeapWriter.delete(f1);
|
|
|
|
|
if (f2.renameTo(newFile)) return newFile;
|
|
|
|
|
if (f2.renameTo(newFile))
|
|
|
|
|
return newFile;
|
|
|
|
|
return f2;
|
|
|
|
|
}
|
|
|
|
|
HeapWriter.delete(f1);
|
|
|
|
@ -914,7 +907,8 @@ public class ArrayStack implements BLOB {
|
|
|
|
|
return null;
|
|
|
|
|
} else if (!i2.hasNext()) {
|
|
|
|
|
HeapWriter.delete(f2);
|
|
|
|
|
if (f1.renameTo(newFile)) return newFile;
|
|
|
|
|
if (f1.renameTo(newFile))
|
|
|
|
|
return newFile;
|
|
|
|
|
return f1;
|
|
|
|
|
}
|
|
|
|
|
assert i1.hasNext();
|
|
|
|
@ -939,6 +933,18 @@ public class ArrayStack implements BLOB {
|
|
|
|
|
HeapWriter.delete(f1);
|
|
|
|
|
HeapWriter.delete(f2);
|
|
|
|
|
return newFile;
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
Log.logSevere("ArrayStack", "cannot merge because input files cannot be read, f2 = " + f2.toString() + ": " + e.getMessage(), e);
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
if (i2 != null) i2.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (final IOException e) {
|
|
|
|
|
Log.logSevere("ArrayStack", "cannot merge because input files cannot be read, f1 = " + f1.toString() + ": " + e.getMessage(), e);
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
if (i1 != null) i1.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static <ReferenceType extends Reference> File rewriteWorker(
|
|
|
|
|