LUCENE-3892: close IndexOutput on exception

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/pforcodec_3892@1359299 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-07-09 17:30:25 +00:00
parent 7afaab4589
commit cda371db21
2 changed files with 22 additions and 2 deletions

View File

@ -45,7 +45,17 @@ public final class ForFactory extends IntStreamFactory {
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);
boolean success = false;
IndexOutput out = dir.createOutput(fileName, context);
try {
IntIndexOutput ret = new ForIndexOutput(out, blockSize);
success = true;
return ret;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(out);
}
}
}
@Override

View File

@ -45,7 +45,17 @@ public final class PForFactory extends IntStreamFactory {
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);
boolean success = false;
IndexOutput out = dir.createOutput(fileName, context);
try {
IntIndexOutput ret = new PForIndexOutput(out, blockSize);
success = true;
return ret;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(out);
}
}
}
@Override