You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/11/30 17:05:21 UTC
svn commit: r1642560 -
/lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java
Author: rmuir
Date: Sun Nov 30 16:05:21 2014
New Revision: 1642560
URL: http://svn.apache.org/r1642560
Log:
LUCENE-6082: simplify exception handling in simpletext .si format
Modified:
lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java
Modified: lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java?rev=1642560&r1=1642559&r2=1642560&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java (original)
+++ lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java Sun Nov 30 16:05:21 2014
@@ -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
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
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
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
SimpleTextUtil.writeNewline(output);
SimpleTextUtil.writeChecksum(output, scratch);
- success = true;
- } finally {
- if (!success) {
- IOUtils.closeWhileHandlingException(output);
- } else {
- output.close();
- }
}
}
}