mirror of https://github.com/apache/lucene.git
LUCENE-3405: rename IOUtils.close methods
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1162394 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ce5a9a107f
commit
3ed03b8488
|
@ -89,7 +89,11 @@ public class PKIndexSplitter {
|
||||||
createIndex(config2, dir2, reader, docsInFirstIndex, true);
|
createIndex(config2, dir2, reader, docsInFirstIndex, true);
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, reader);
|
if (success) {
|
||||||
|
IOUtils.close(reader);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(reader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +104,11 @@ public class PKIndexSplitter {
|
||||||
w.addIndexes(new DocumentFilteredIndexReader(reader, preserveFilter, negateFilter));
|
w.addIndexes(new DocumentFilteredIndexReader(reader, preserveFilter, negateFilter));
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, w);
|
if (success) {
|
||||||
|
IOUtils.close(w);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class NRTCachingDirectory extends Directory {
|
||||||
in = cache.openInput(fileName, context);
|
in = cache.openInput(fileName, context);
|
||||||
in.copyBytes(out, in.length());
|
in.copyBytes(out, in.length());
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, in, out);
|
IOUtils.close(in, out);
|
||||||
}
|
}
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
cache.deleteFile(fileName);
|
cache.deleteFile(fileName);
|
||||||
|
|
|
@ -87,7 +87,7 @@ final class DocFieldProcessor extends DocConsumer {
|
||||||
consumers.finish(state.numDocs);
|
consumers.finish(state.numDocs);
|
||||||
};
|
};
|
||||||
// close perDocConsumer during flush to ensure all files are flushed due to PerCodec CFS
|
// close perDocConsumer during flush to ensure all files are flushed due to PerCodec CFS
|
||||||
IOUtils.closeSafely(false, perDocConsumers.values());
|
IOUtils.close(perDocConsumers.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,7 +108,7 @@ final class DocFieldProcessor extends DocConsumer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(true, perDocConsumers.values());
|
IOUtils.closeWhileHandlingException(perDocConsumers.values());
|
||||||
// TODO add abort to PerDocConsumer!
|
// TODO add abort to PerDocConsumer!
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignore on abort!
|
// ignore on abort!
|
||||||
|
|
|
@ -174,9 +174,9 @@ public final class FieldsReader implements Cloneable, Closeable {
|
||||||
public final void close() throws IOException {
|
public final void close() throws IOException {
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
if (isOriginal) {
|
if (isOriginal) {
|
||||||
IOUtils.closeSafely(false, fieldsStream, indexStream, fieldsStreamTL, cloneableFieldsStream, cloneableIndexStream);
|
IOUtils.close(fieldsStream, indexStream, fieldsStreamTL, cloneableFieldsStream, cloneableIndexStream);
|
||||||
} else {
|
} else {
|
||||||
IOUtils.closeSafely(false, fieldsStream, indexStream, fieldsStreamTL);
|
IOUtils.close(fieldsStream, indexStream, fieldsStreamTL);
|
||||||
}
|
}
|
||||||
closed = true;
|
closed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ final class FieldsWriter {
|
||||||
void close() throws IOException {
|
void close() throws IOException {
|
||||||
if (directory != null) {
|
if (directory != null) {
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(false, fieldsStream, indexStream);
|
IOUtils.close(fieldsStream, indexStream);
|
||||||
} finally {
|
} finally {
|
||||||
fieldsStream = indexStream = null;
|
fieldsStream = indexStream = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,11 @@ final class FreqProxTermsWriter extends TermsHashConsumer {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, consumer);
|
if (success) {
|
||||||
|
IOUtils.close(consumer);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2270,7 +2270,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
} catch(IOException ex) {
|
} catch(IOException ex) {
|
||||||
prior = ex;
|
prior = ex;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(prior, cfsDir);
|
IOUtils.closeWhileHandlingException(prior, cfsDir);
|
||||||
}
|
}
|
||||||
// Perform the merge
|
// Perform the merge
|
||||||
|
|
||||||
|
@ -2606,7 +2606,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, cfsdir);
|
IOUtils.close(cfsdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
info.dir = directory;
|
info.dir = directory;
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class MultiPerDocValues extends PerDocValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, this.subs);
|
IOUtils.close(this.subs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -88,7 +88,11 @@ final class NormsWriter extends InvertedDocEndConsumer {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, normsOut);
|
if (success) {
|
||||||
|
IOUtils.close(normsOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(normsOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, consumers);
|
IOUtils.closeWhileHandlingException(consumers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, consumers);
|
IOUtils.close(consumers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
// If we hit exception (eg, IOE because writer was
|
// If we hit exception (eg, IOE because writer was
|
||||||
// committing, or, for any other reason) we must
|
// committing, or, for any other reason) we must
|
||||||
// go back and close all FieldsProducers we opened:
|
// go back and close all FieldsProducers we opened:
|
||||||
IOUtils.closeSafely(true, producers.values());
|
IOUtils.closeWhileHandlingException(producers.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, codecs.values());
|
IOUtils.close(codecs.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, producers.values());
|
IOUtils.closeWhileHandlingException(producers.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, codecs.values());
|
IOUtils.close(codecs.values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ final class PerFieldCodecWrapper extends Codec {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, consumers);
|
IOUtils.close(consumers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -122,7 +122,7 @@ final class SegmentCoreReaders {
|
||||||
|
|
||||||
synchronized void decRef() throws IOException {
|
synchronized void decRef() throws IOException {
|
||||||
if (ref.decrementAndGet() == 0) {
|
if (ref.decrementAndGet() == 0) {
|
||||||
IOUtils.closeSafely(false, fields, perDocProducer, termVectorsReaderOrig,
|
IOUtils.close(fields, perDocProducer, termVectorsReaderOrig,
|
||||||
fieldsReaderOrig, cfsReader, storeCFSReader);
|
fieldsReaderOrig, cfsReader, storeCFSReader);
|
||||||
// Now, notify any ReaderFinished listeners:
|
// Now, notify any ReaderFinished listeners:
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
|
|
|
@ -331,7 +331,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentInfo> {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// We hit an exception above; try to close the file
|
// We hit an exception above; try to close the file
|
||||||
// but suppress any exception:
|
// but suppress any exception:
|
||||||
IOUtils.closeSafely(true, segnOutput);
|
IOUtils.closeWhileHandlingException(segnOutput);
|
||||||
try {
|
try {
|
||||||
// Try not to leave a truncated segments_N file in
|
// Try not to leave a truncated segments_N file in
|
||||||
// the index:
|
// the index:
|
||||||
|
|
|
@ -573,7 +573,11 @@ final class SegmentMerger {
|
||||||
slices.toArray(ReaderUtil.Slice.EMPTY_ARRAY)));
|
slices.toArray(ReaderUtil.Slice.EMPTY_ARRAY)));
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, consumer);
|
if (success) {
|
||||||
|
IOUtils.close(consumer);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +606,11 @@ final class SegmentMerger {
|
||||||
docsConsumer.merge(mergeState, multiPerDocValues);
|
docsConsumer.merge(mergeState, multiPerDocValues);
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, docsConsumer);
|
if (success) {
|
||||||
|
IOUtils.close(docsConsumer);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(docsConsumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* don't close the perDocProducers here since they are private segment producers
|
/* don't close the perDocProducers here since they are private segment producers
|
||||||
|
@ -654,7 +662,11 @@ final class SegmentMerger {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, output);
|
if (success) {
|
||||||
|
IOUtils.close(output);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ class TermVectorsReader implements Cloneable, Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, tvx, tvd, tvf);
|
IOUtils.close(tvx, tvd, tvf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,7 +57,7 @@ final class TermVectorsTermsWriter extends TermsHashConsumer {
|
||||||
fill(state.numDocs);
|
fill(state.numDocs);
|
||||||
assert state.segmentName != null;
|
assert state.segmentName != null;
|
||||||
String idxName = IndexFileNames.segmentFileName(state.segmentName, "", IndexFileNames.VECTORS_INDEX_EXTENSION);
|
String idxName = IndexFileNames.segmentFileName(state.segmentName, "", IndexFileNames.VECTORS_INDEX_EXTENSION);
|
||||||
IOUtils.closeSafely(false, tvx, tvf, tvd);
|
IOUtils.close(tvx, tvf, tvd);
|
||||||
tvx = tvd = tvf = null;
|
tvx = tvd = tvf = null;
|
||||||
if (4+((long) state.numDocs)*16 != state.directory.fileLength(idxName)) {
|
if (4+((long) state.numDocs)*16 != state.directory.fileLength(idxName)) {
|
||||||
throw new RuntimeException("after flush: tvx size mismatch: " + state.numDocs + " docs vs " + state.directory.fileLength(idxName) + " length in bytes of " + idxName + " file exists?=" + state.directory.fileExists(idxName));
|
throw new RuntimeException("after flush: tvx size mismatch: " + state.numDocs + " docs vs " + state.directory.fileLength(idxName) + " length in bytes of " + idxName + " file exists?=" + state.directory.fileExists(idxName));
|
||||||
|
@ -107,7 +107,7 @@ final class TermVectorsTermsWriter extends TermsHashConsumer {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, tvx, tvd, tvf);
|
IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ final class TermVectorsTermsWriter extends TermsHashConsumer {
|
||||||
public void abort() {
|
public void abort() {
|
||||||
hasVectors = false;
|
hasVectors = false;
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(true, tvx, tvd, tvf);
|
IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// cannot happen since we suppress exceptions
|
// cannot happen since we suppress exceptions
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -45,7 +45,7 @@ final class TermVectorsWriter {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, tvx, tvd, tvf);
|
IOUtils.closeWhileHandlingException(tvx, tvd, tvf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,6 @@ final class TermVectorsWriter {
|
||||||
final void close() throws IOException {
|
final void close() throws IOException {
|
||||||
// make an effort to close all streams we can but remember and re-throw
|
// make an effort to close all streams we can but remember and re-throw
|
||||||
// the first exception encountered in this process
|
// the first exception encountered in this process
|
||||||
IOUtils.closeSafely(false, tvx, tvd, tvf);
|
IOUtils.close(tvx, tvd, tvf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class BlockTermsWriter extends FieldsConsumer {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class BlockTermsWriter extends FieldsConsumer {
|
||||||
}
|
}
|
||||||
writeTrailer(dirStart);
|
writeTrailer(dirStart);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, out, postingsWriter, termsIndexWriter);
|
IOUtils.close(out, postingsWriter, termsIndexWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class BlockTreeTermsReader extends FieldsProducer {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, indexIn, this);
|
IOUtils.closeWhileHandlingException(indexIn, this);
|
||||||
} else if (indexDivisor != -1) {
|
} else if (indexDivisor != -1) {
|
||||||
indexIn.close();
|
indexIn.close();
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class BlockTreeTermsReader extends FieldsProducer {
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(false, in, postingsReader);
|
IOUtils.close(in, postingsReader);
|
||||||
} finally {
|
} finally {
|
||||||
for(FieldReader field : fields.values()) {
|
for(FieldReader field : fields.values()) {
|
||||||
field.close();
|
field.close();
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class BlockTreeTermsWriter extends FieldsConsumer {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out, indexOut);
|
IOUtils.closeWhileHandlingException(out, indexOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.indexOut = indexOut;
|
this.indexOut = indexOut;
|
||||||
|
@ -937,7 +937,7 @@ public class BlockTreeTermsWriter extends FieldsConsumer {
|
||||||
} catch (IOException ioe2) {
|
} catch (IOException ioe2) {
|
||||||
ioe = ioe2;
|
ioe = ioe2;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(ioe, out, indexOut, postingsWriter);
|
IOUtils.closeWhileHandlingException(ioe, out, indexOut, postingsWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ public class DefaultDocValuesProducer extends PerDocValues {
|
||||||
} else {
|
} else {
|
||||||
toClose = closeables;
|
toClose = closeables;
|
||||||
}
|
}
|
||||||
IOUtils.closeSafely(false, toClose);
|
IOUtils.close(toClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class DefaultSegmentInfosWriter extends SegmentInfosWriter {
|
||||||
return out;
|
return out;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,9 @@ public class FixedGapTermsIndexReader extends TermsIndexReaderBase {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) IOUtils.closeSafely(true, in);
|
if (!success) {
|
||||||
|
IOUtils.closeWhileHandlingException(in);
|
||||||
|
}
|
||||||
if (indexDivisor > 0) {
|
if (indexDivisor > 0) {
|
||||||
in.close();
|
in.close();
|
||||||
in = null;
|
in = null;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,11 @@ public class FixedGapTermsIndexWriter extends TermsIndexWriterBase {
|
||||||
writeTrailer(dirStart);
|
writeTrailer(dirStart);
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, out);
|
if (success) {
|
||||||
|
IOUtils.close(out);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class VariableGapTermsIndexWriter extends TermsIndexWriterBase {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ public final class SepPostingsWriter extends PostingsWriterBase {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, docOut, skipOut, freqOut, posOut, payloadOut);
|
IOUtils.closeWhileHandlingException(docOut, skipOut, freqOut, posOut, payloadOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ public final class SepPostingsWriter extends PostingsWriterBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, docOut, skipOut, freqOut, posOut, payloadOut);
|
IOUtils.close(docOut, skipOut, freqOut, posOut, payloadOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getExtensions(Set<String> extensions) {
|
public static void getExtensions(Set<String> extensions) {
|
||||||
|
|
|
@ -368,7 +368,7 @@ public final class Bytes {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, datOut);
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ public final class Bytes {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, idxOut);
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return idxOut;
|
return idxOut;
|
||||||
|
|
|
@ -112,7 +112,11 @@ class FixedDerefBytesImpl {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
hash.close();
|
hash.close();
|
||||||
}
|
}
|
||||||
success = false;
|
success = false;
|
||||||
|
@ -134,7 +138,11 @@ class FixedDerefBytesImpl {
|
||||||
w.finish();
|
w.finish();
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, idxOut);
|
if (success) {
|
||||||
|
IOUtils.close(idxOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
|
}
|
||||||
bytesUsed
|
bytesUsed
|
||||||
.addAndGet((-docToID.length) * RamUsageEstimator.NUM_BYTES_INT);
|
.addAndGet((-docToID.length) * RamUsageEstimator.NUM_BYTES_INT);
|
||||||
docToID = null;
|
docToID = null;
|
||||||
|
|
|
@ -126,7 +126,11 @@ class FixedSortedBytesImpl {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
hash.close();
|
hash.close();
|
||||||
}
|
}
|
||||||
final IndexOutput idxOut = getIndexOut();
|
final IndexOutput idxOut = getIndexOut();
|
||||||
|
@ -159,7 +163,11 @@ class FixedSortedBytesImpl {
|
||||||
}
|
}
|
||||||
w.finish();
|
w.finish();
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, idxOut);
|
if (success) {
|
||||||
|
IOUtils.close(idxOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
|
}
|
||||||
bytesUsed.addAndGet((-docToEntry.length)
|
bytesUsed.addAndGet((-docToEntry.length)
|
||||||
* RamUsageEstimator.NUM_BYTES_INT);
|
* RamUsageEstimator.NUM_BYTES_INT);
|
||||||
docToEntry = null;
|
docToEntry = null;
|
||||||
|
|
|
@ -123,7 +123,7 @@ class FixedStraightBytesImpl {
|
||||||
try {
|
try {
|
||||||
datOut.copyBytes(cloneData, size * maxDocs);
|
datOut.copyBytes(cloneData, size * maxDocs);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, cloneData);
|
IOUtils.close(cloneData);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDocID += maxDocs;
|
lastDocID += maxDocs;
|
||||||
|
@ -133,7 +133,7 @@ class FixedStraightBytesImpl {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,11 @@ class FixedStraightBytesImpl {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
pool.dropBuffersAndReset();
|
pool.dropBuffersAndReset();
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +235,7 @@ class FixedStraightBytesImpl {
|
||||||
data = new byte[maxDoc];
|
data = new byte[maxDoc];
|
||||||
datIn.readBytes(data, 0, data.length, false);
|
datIn.readBytes(data, 0, data.length, false);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, datIn);
|
IOUtils.close(datIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class Floats {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, datOut);
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,11 +214,13 @@ public class Floats {
|
||||||
bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_INT
|
bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_INT
|
||||||
* ((values.length))));
|
* ((values.length))));
|
||||||
values = null;
|
values = null;
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes 8 bytes (double) per value
|
// Writes 8 bytes (double) per value
|
||||||
|
@ -275,7 +277,11 @@ public class Floats {
|
||||||
bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_LONG
|
bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_LONG
|
||||||
* ((values.length))));
|
* ((values.length))));
|
||||||
values = null;
|
values = null;
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ class IntsImpl {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, datOut);
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,11 @@ class IntsImpl {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
array.clear();
|
array.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +290,7 @@ class IntsImpl {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, datIn);
|
IOUtils.closeWhileHandlingException(datIn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +305,11 @@ class IntsImpl {
|
||||||
datOut.copyBytes(indexInput, bytesPerValue(type) * numDocs);
|
datOut.copyBytes(indexInput, bytesPerValue(type) * numDocs);
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, indexInput);
|
if (success) {
|
||||||
|
IOUtils.close(indexInput);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(indexInput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return numDocs;
|
return numDocs;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +331,7 @@ class IntsImpl {
|
||||||
return source;
|
return source;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, input, datIn);
|
IOUtils.closeWhileHandlingException(input, datIn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +353,7 @@ class IntsImpl {
|
||||||
return inst;
|
return inst;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, input);
|
IOUtils.closeWhileHandlingException(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,11 @@ class VarDerefBytesImpl {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
hash.close();
|
hash.close();
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final IndexOutput idxOut = getIndexOut();
|
final IndexOutput idxOut = getIndexOut();
|
||||||
|
@ -211,7 +215,11 @@ class VarDerefBytesImpl {
|
||||||
w.finish();
|
w.finish();
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success,idxOut);
|
if (success) {
|
||||||
|
IOUtils.close(idxOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
|
}
|
||||||
bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT
|
bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT
|
||||||
* (-docToAddress.length));
|
* (-docToAddress.length));
|
||||||
docToAddress = null;
|
docToAddress = null;
|
||||||
|
|
|
@ -124,7 +124,11 @@ class VarSortedBytesImpl {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
hash.close();
|
hash.close();
|
||||||
}
|
}
|
||||||
final IndexOutput idxOut = getIndexOut();
|
final IndexOutput idxOut = getIndexOut();
|
||||||
|
@ -161,7 +165,11 @@ class VarSortedBytesImpl {
|
||||||
bytesUsed.addAndGet((-docToEntry.length)
|
bytesUsed.addAndGet((-docToEntry.length)
|
||||||
* RamUsageEstimator.NUM_BYTES_INT);
|
* RamUsageEstimator.NUM_BYTES_INT);
|
||||||
docToEntry = null;
|
docToEntry = null;
|
||||||
IOUtils.closeSafely(!success, idxOut);
|
if (success) {
|
||||||
|
IOUtils.close(idxOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,13 +128,13 @@ class VarStraightBytesImpl {
|
||||||
address += numDataBytes; // this is the address after all addr pointers are updated
|
address += numDataBytes; // this is the address after all addr pointers are updated
|
||||||
iter.close();
|
iter.close();
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, cloneIdx);
|
IOUtils.close(cloneIdx);
|
||||||
}
|
}
|
||||||
final IndexInput cloneData = reader.cloneData();
|
final IndexInput cloneData = reader.cloneData();
|
||||||
try {
|
try {
|
||||||
datOut.copyBytes(cloneData, numDataBytes);
|
datOut.copyBytes(cloneData, numDataBytes);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, cloneData);
|
IOUtils.close(cloneData);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.merge(state);
|
super.merge(state);
|
||||||
|
@ -142,7 +142,7 @@ class VarStraightBytesImpl {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,11 @@ class VarStraightBytesImpl {
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, datOut);
|
if (success) {
|
||||||
|
IOUtils.close(datOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(datOut);
|
||||||
|
}
|
||||||
pool.dropBuffersAndReset();
|
pool.dropBuffersAndReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +208,11 @@ class VarStraightBytesImpl {
|
||||||
bytesUsed.addAndGet(-(docToAddress.length)
|
bytesUsed.addAndGet(-(docToAddress.length)
|
||||||
* RamUsageEstimator.NUM_BYTES_INT);
|
* RamUsageEstimator.NUM_BYTES_INT);
|
||||||
docToAddress = null;
|
docToAddress = null;
|
||||||
IOUtils.closeSafely(!success, idxOut);
|
if (success) {
|
||||||
|
IOUtils.close(idxOut);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(idxOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, handle);
|
IOUtils.closeWhileHandlingException(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
|
@ -112,7 +112,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
}
|
}
|
||||||
return mapping;
|
return mapping;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, input);
|
IOUtils.close(input);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO remove once 3.x is not supported anymore
|
// TODO remove once 3.x is not supported anymore
|
||||||
|
@ -121,7 +121,11 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
success = true;
|
success = true;
|
||||||
return mapping;
|
return mapping;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, stream);
|
if (success) {
|
||||||
|
IOUtils.close(stream);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +200,7 @@ public final class CompoundFileDirectory extends Directory {
|
||||||
assert openForWrite;
|
assert openForWrite;
|
||||||
writer.close();
|
writer.close();
|
||||||
} else {
|
} else {
|
||||||
IOUtils.closeSafely(false, handle);
|
IOUtils.close(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ final class CompoundFileWriter implements Closeable{
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, dataOut);
|
IOUtils.closeWhileHandlingException(dataOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ final class CompoundFileWriter implements Closeable{
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
priorException = e;
|
priorException = e;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(priorException, dataOut);
|
IOUtils.closeWhileHandlingException(priorException, dataOut);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
entryTableOut = directory.createOutput(entryTableName, IOContext.DEFAULT);
|
entryTableOut = directory.createOutput(entryTableName, IOContext.DEFAULT);
|
||||||
|
@ -165,7 +165,7 @@ final class CompoundFileWriter implements Closeable{
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
priorException = e;
|
priorException = e;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(priorException, entryTableOut);
|
IOUtils.closeWhileHandlingException(priorException, entryTableOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,13 +205,14 @@ final class CompoundFileWriter implements Closeable{
|
||||||
success = true;
|
success = true;
|
||||||
return length;
|
return length;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(!success, is);
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
IOUtils.close(is);
|
||||||
// copy successful - delete file
|
// copy successful - delete file
|
||||||
fileEntry.dir.deleteFile(fileEntry.file);
|
fileEntry.dir.deleteFile(fileEntry.file);
|
||||||
|
} else {
|
||||||
|
IOUtils.closeWhileHandlingException(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeEntryTable(Collection<FileEntry> entries,
|
protected void writeEntryTable(Collection<FileEntry> entries,
|
||||||
|
|
|
@ -204,7 +204,7 @@ public abstract class Directory implements Closeable {
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
priorException = ioe;
|
priorException = ioe;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(priorException, os, is);
|
IOUtils.closeWhileHandlingException(priorException, os, is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public final class IOUtils {
|
||||||
* @param priorException <tt>null</tt> or an exception that will be rethrown after method completion
|
* @param priorException <tt>null</tt> or an exception that will be rethrown after method completion
|
||||||
* @param objects objects to call <tt>close()</tt> on
|
* @param objects objects to call <tt>close()</tt> on
|
||||||
*/
|
*/
|
||||||
public static <E extends Exception> void closeSafely(E priorException, Closeable... objects) throws E, IOException {
|
public static <E extends Exception> void closeWhileHandlingException(E priorException, Closeable... objects) throws E, IOException {
|
||||||
Throwable th = null;
|
Throwable th = null;
|
||||||
|
|
||||||
for (Closeable object : objects) {
|
for (Closeable object : objects) {
|
||||||
|
@ -76,7 +76,7 @@ public final class IOUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see #closeSafely(Exception, Closeable...) */
|
/** @see #closeSafely(Exception, Closeable...) */
|
||||||
public static <E extends Exception> void closeSafely(E priorException, Iterable<Closeable> objects) throws E, IOException {
|
public static <E extends Exception> void closeWhileHandlingException(E priorException, Iterable<Closeable> objects) throws E, IOException {
|
||||||
Throwable th = null;
|
Throwable th = null;
|
||||||
|
|
||||||
for (Closeable object : objects) {
|
for (Closeable object : objects) {
|
||||||
|
@ -103,18 +103,16 @@ public final class IOUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes all given <tt>Closeable</tt>s, suppressing all thrown exceptions.
|
* Closes all given <tt>Closeable</tt>s. Some of the
|
||||||
* Some of the <tt>Closeable</tt>s may be null, they are ignored. After
|
* <tt>Closeable</tt>s may be null; they are
|
||||||
* everything is closed, and if {@code suppressExceptions} is {@code false},
|
* ignored. After everything is closed, the method either
|
||||||
* method either throws the first of suppressed exceptions, or completes
|
* throws the first exception it hit while closing, or
|
||||||
* normally.
|
* completes normally if there were no exceptions.
|
||||||
*
|
*
|
||||||
* @param suppressExceptions
|
|
||||||
* if true then exceptions that occur during close() are suppressed
|
|
||||||
* @param objects
|
* @param objects
|
||||||
* objects to call <tt>close()</tt> on
|
* objects to call <tt>close()</tt> on
|
||||||
*/
|
*/
|
||||||
public static void closeSafely(boolean suppressExceptions, Closeable... objects) throws IOException {
|
public static void close(Closeable... objects) throws IOException {
|
||||||
Throwable th = null;
|
Throwable th = null;
|
||||||
|
|
||||||
for (Closeable object : objects) {
|
for (Closeable object : objects) {
|
||||||
|
@ -124,12 +122,13 @@ public final class IOUtils {
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
addSuppressed(th, t);
|
addSuppressed(th, t);
|
||||||
if (th == null)
|
if (th == null) {
|
||||||
th = t;
|
th = t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (th != null && !suppressExceptions) {
|
if (th != null) {
|
||||||
if (th instanceof IOException) throw (IOException) th;
|
if (th instanceof IOException) throw (IOException) th;
|
||||||
if (th instanceof RuntimeException) throw (RuntimeException) th;
|
if (th instanceof RuntimeException) throw (RuntimeException) th;
|
||||||
if (th instanceof Error) throw (Error) th;
|
if (th instanceof Error) throw (Error) th;
|
||||||
|
@ -138,9 +137,9 @@ public final class IOUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #closeSafely(boolean, Closeable...)
|
* @see #close(Closeable...)
|
||||||
*/
|
*/
|
||||||
public static void closeSafely(boolean suppressExceptions, Iterable<? extends Closeable> objects) throws IOException {
|
public static void close(Iterable<? extends Closeable> objects) throws IOException {
|
||||||
Throwable th = null;
|
Throwable th = null;
|
||||||
|
|
||||||
for (Closeable object : objects) {
|
for (Closeable object : objects) {
|
||||||
|
@ -150,18 +149,51 @@ public final class IOUtils {
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
addSuppressed(th, t);
|
addSuppressed(th, t);
|
||||||
if (th == null)
|
if (th == null) {
|
||||||
th = t;
|
th = t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (th != null && !suppressExceptions) {
|
if (th != null) {
|
||||||
if (th instanceof IOException) throw (IOException) th;
|
if (th instanceof IOException) throw (IOException) th;
|
||||||
if (th instanceof RuntimeException) throw (RuntimeException) th;
|
if (th instanceof RuntimeException) throw (RuntimeException) th;
|
||||||
if (th instanceof Error) throw (Error) th;
|
if (th instanceof Error) throw (Error) th;
|
||||||
throw new RuntimeException(th);
|
throw new RuntimeException(th);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes all given <tt>Closeable</tt>s, suppressing all thrown exceptions.
|
||||||
|
* Some of the <tt>Closeable</tt>s may be null, they are ignored.
|
||||||
|
*
|
||||||
|
* @param objects
|
||||||
|
* objects to call <tt>close()</tt> on
|
||||||
|
*/
|
||||||
|
public static void closeWhileHandlingException(Closeable... objects) throws IOException {
|
||||||
|
for (Closeable object : objects) {
|
||||||
|
try {
|
||||||
|
if (object != null) {
|
||||||
|
object.close();
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #closeSafely(boolean, Closeable...)
|
||||||
|
*/
|
||||||
|
public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) throws IOException {
|
||||||
|
for (Closeable object : objects) {
|
||||||
|
try {
|
||||||
|
if (object != null) {
|
||||||
|
object.close();
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** This reflected {@link Method} is {@code null} before Java 7 */
|
/** This reflected {@link Method} is {@code null} before Java 7 */
|
||||||
private static final Method SUPPRESS_METHOD;
|
private static final Method SUPPRESS_METHOD;
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class MockFixedIntBlockCodec extends Codec {
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class MockVariableIntBlockCodec extends Codec {
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class MockSingleIntIndexOutput extends IntIndexOutput {
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
IOUtils.closeSafely(true, out);
|
IOUtils.closeWhileHandlingException(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ class PreFlexFieldsWriter extends FieldsConsumer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
IOUtils.closeSafely(false, termsOut, freqOut, proxOut);
|
IOUtils.close(termsOut, freqOut, proxOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PreFlexTermsWriter extends TermsConsumer {
|
private class PreFlexTermsWriter extends TermsConsumer {
|
||||||
|
|
|
@ -98,7 +98,7 @@ final class TermInfosWriter implements Closeable {
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(true, output);
|
IOUtils.closeWhileHandlingException(output);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// cannot happen since we suppress exceptions
|
// cannot happen since we suppress exceptions
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -139,7 +139,7 @@ final class TermInfosWriter implements Closeable {
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely(true, output);
|
IOUtils.closeWhileHandlingException(output);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// cannot happen since we suppress exceptions
|
// cannot happen since we suppress exceptions
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -541,7 +541,7 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
|
|
||||||
verifyIndex(target);
|
verifyIndex(target);
|
||||||
|
|
||||||
IOUtils.closeSafely(false, target, input[0], input[1]);
|
IOUtils.close(target, input[0], input[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOptimizeAddIndexesReader() throws Exception {
|
public void testOptimizeAddIndexesReader() throws Exception {
|
||||||
|
@ -562,7 +562,7 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
verifyIndex(target);
|
verifyIndex(target);
|
||||||
IOUtils.closeSafely(false, target, input[0], input[1]);
|
IOUtils.close(target, input[0], input[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class TestIOUtils extends LuceneTestCase {
|
||||||
// test with prior exception
|
// test with prior exception
|
||||||
try {
|
try {
|
||||||
final TestException t = new TestException();
|
final TestException t = new TestException();
|
||||||
IOUtils.closeSafely(t, new BrokenCloseable(1), new BrokenCloseable(2));
|
IOUtils.closeWhileHandlingException(t, new BrokenCloseable(1), new BrokenCloseable(2));
|
||||||
} catch (TestException e1) {
|
} catch (TestException e1) {
|
||||||
assertEquals("BASE-EXCEPTION", e1.getMessage());
|
assertEquals("BASE-EXCEPTION", e1.getMessage());
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
|
@ -83,7 +83,7 @@ public class TestIOUtils extends LuceneTestCase {
|
||||||
|
|
||||||
// test without prior exception
|
// test without prior exception
|
||||||
try {
|
try {
|
||||||
IOUtils.closeSafely((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2));
|
IOUtils.closeWhileHandlingException((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2));
|
||||||
} catch (TestException e1) {
|
} catch (TestException e1) {
|
||||||
fail("TestException should not be thrown here");
|
fail("TestException should not be thrown here");
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
|
||||||
searcher.close();
|
searcher.close();
|
||||||
iw.close();
|
iw.close();
|
||||||
tw.close();
|
tw.close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -140,7 +140,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
|
||||||
searcher.close();
|
searcher.close();
|
||||||
iw.close();
|
iw.close();
|
||||||
tw.close();
|
tw.close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -184,7 +184,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
|
||||||
searcher.close();
|
searcher.close();
|
||||||
iw.close();
|
iw.close();
|
||||||
tw.close();
|
tw.close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException {
|
private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException {
|
||||||
|
@ -230,7 +230,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
|
||||||
searcher.close();
|
searcher.close();
|
||||||
iw.close();
|
iw.close();
|
||||||
tw.close();
|
tw.close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -275,7 +275,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
|
||||||
searcher.close();
|
searcher.close();
|
||||||
iw.close();
|
iw.close();
|
||||||
tw.close();
|
tw.close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Directory[][] getDirs() throws IOException {
|
private Directory[][] getDirs() throws IOException {
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class TestTotalFacetCounts extends LuceneTestCase {
|
||||||
++partition;
|
++partition;
|
||||||
}
|
}
|
||||||
readers[0].close();
|
readers[0].close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,7 +339,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
|
||||||
readers[0].close();
|
readers[0].close();
|
||||||
r2.close();
|
r2.close();
|
||||||
outputFile.delete();
|
outputFile.delete();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int assertReadFromDisc(TotalFacetCounts totalCounts, int prevGen, String errMsg) {
|
private int assertReadFromDisc(TotalFacetCounts totalCounts, int prevGen, String errMsg) {
|
||||||
|
@ -405,7 +405,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
|
||||||
outputFile.delete();
|
outputFile.delete();
|
||||||
writers[0].close();
|
writers[0].close();
|
||||||
readers[0].close();
|
readers[0].close();
|
||||||
IOUtils.closeSafely(false, dirs[0]);
|
IOUtils.close(dirs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -535,7 +535,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
|
||||||
readers[0].close();
|
readers[0].close();
|
||||||
readers[1].close();
|
readers[1].close();
|
||||||
for (Directory[] dirset : dirs) {
|
for (Directory[] dirset : dirs) {
|
||||||
IOUtils.closeSafely(false, dirset);
|
IOUtils.close(dirset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,8 +247,8 @@ public class TestAddTaxonomies extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
main.close();
|
main.close();
|
||||||
IOUtils.closeSafely(false, dirs);
|
IOUtils.close(dirs);
|
||||||
IOUtils.closeSafely(false, copydirs);
|
IOUtils.close(copydirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,7 @@ public class FSTLookup extends Lookup {
|
||||||
this.automaton = new FST<Object>(new InputStreamDataInput(is), NoOutputs.getSingleton());
|
this.automaton = new FST<Object>(new InputStreamDataInput(is), NoOutputs.getSingleton());
|
||||||
cacheRootArcs();
|
cacheRootArcs();
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, is);
|
IOUtils.close(is);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ public class FSTLookup extends Lookup {
|
||||||
try {
|
try {
|
||||||
this.automaton.save(new OutputStreamDataOutput(os));
|
this.automaton.save(new OutputStreamDataOutput(os));
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeSafely(false, os);
|
IOUtils.close(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -247,7 +247,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
||||||
if (solrCore != null) solrCore.close();
|
if (solrCore != null) solrCore.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (readersToBeClosed != null) IOUtils.closeSafely(true, readersToBeClosed);
|
if (readersToBeClosed != null) IOUtils.closeWhileHandlingException(readersToBeClosed);
|
||||||
if (dirsToBeReleased != null) {
|
if (dirsToBeReleased != null) {
|
||||||
for (Directory dir : dirsToBeReleased) {
|
for (Directory dir : dirsToBeReleased) {
|
||||||
DirectoryFactory dirFactory = core.getDirectoryFactory();
|
DirectoryFactory dirFactory = core.getDirectoryFactory();
|
||||||
|
|
Loading…
Reference in New Issue