mirror of https://github.com/apache/lucene.git
LUCENE-6082: simplify exception handling in simpletext .si format
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1642560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
effff3b1c7
commit
4d18ac3959
|
@ -36,7 +36,6 @@ import org.apache.lucene.store.IOContext;
|
|||
import org.apache.lucene.store.IndexOutput;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.BytesRefBuilder;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.StringHelper;
|
||||
import org.apache.lucene.util.Version;
|
||||
|
||||
|
@ -63,9 +62,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
|
|||
public SegmentInfo read(Directory directory, String segmentName, byte[] segmentID, IOContext context) throws IOException {
|
||||
BytesRefBuilder scratch = new BytesRefBuilder();
|
||||
String segFileName = IndexFileNames.segmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
|
||||
ChecksumIndexInput input = directory.openChecksumInput(segFileName, context);
|
||||
boolean success = false;
|
||||
try {
|
||||
try (ChecksumIndexInput input = directory.openChecksumInput(segFileName, context)) {
|
||||
SimpleTextUtil.readLine(input, scratch);
|
||||
assert StringHelper.startsWith(scratch.get(), SI_VERSION);
|
||||
final Version version;
|
||||
|
@ -125,14 +122,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
|
|||
SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,
|
||||
isCompoundFile, null, diagnostics, id);
|
||||
info.setFiles(files);
|
||||
success = true;
|
||||
return info;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(input);
|
||||
} else {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,10 +136,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
|
|||
String segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
|
||||
si.addFile(segFileName);
|
||||
|
||||
boolean success = false;
|
||||
IndexOutput output = dir.createOutput(segFileName, ioContext);
|
||||
|
||||
try {
|
||||
try (IndexOutput output = dir.createOutput(segFileName, ioContext)) {
|
||||
BytesRefBuilder scratch = new BytesRefBuilder();
|
||||
|
||||
SimpleTextUtil.write(output, SI_VERSION);
|
||||
|
@ -201,13 +188,6 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
|
|||
SimpleTextUtil.writeNewline(output);
|
||||
|
||||
SimpleTextUtil.writeChecksum(output, scratch);
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(output);
|
||||
} else {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue