Skip to content

Apache Lucene open-source search software

LUCENE-3892: small cleanups to For/PFor postings formats

Michael McCandless3fb11c875dbe
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java
index f201534dc27..aae122e3b07 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java
@@ -40,29 +40,17 @@ public final class ForFactory extends IntStreamFactory {
private final int blockSize;
public ForFactory() {
- this.blockSize=ForPostingsFormat.DEFAULT_BLOCK_SIZE;
+ this.blockSize = ForPostingsFormat.DEFAULT_BLOCK_SIZE;
}
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
- IndexOutput out = dir.createOutput(fileName, context);
- boolean success = false;
- try {
- FixedIntBlockIndexOutput ret = new ForIndexOutput(out, blockSize);
- success = true;
- return ret;
- } finally {
- if (!success) {
- // TODO: why handle exception like this?
- // and why not use similar codes for read part?
- IOUtils.closeWhileHandlingException(out);
- }
- }
+ return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);
}
+
@Override
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
- FixedIntBlockIndexInput ret = new ForIndexInput(dir.openInput(fileName, context));
- return ret;
+ return new ForIndexInput(dir.openInput(fileName, context));
}
// wrap input and output with buffer support
@@ -102,13 +90,15 @@ public final class ForFactory extends IntStreamFactory {
}
private class ForIndexOutput extends FixedIntBlockIndexOutput {
- private byte[] encoded;
- private IntBuffer encodedBuffer;
+ private final byte[] encoded;
+ private final IntBuffer encodedBuffer;
+
ForIndexOutput(IndexOutput out, int blockSize) throws IOException {
super(out,blockSize);
this.encoded = new byte[blockSize*8+4];
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
}
+
@Override
protected void flushBlock() throws IOException {
final int numBytes = ForUtil.compress(buffer,buffer.length,encodedBuffer);
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java
index fdd40b4d7cb..570f77c0fb8 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForPostingsFormat.java
@@ -46,8 +46,7 @@ public final class ForPostingsFormat extends PostingsFormat {
private final int blockSize;
private final int minBlockSize;
private final int maxBlockSize;
- protected final static int DEFAULT_BLOCK_SIZE = 128;
- protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
+ public final static int DEFAULT_BLOCK_SIZE = 128;
public ForPostingsFormat() {
super("For");
@@ -55,6 +54,7 @@ public final class ForPostingsFormat extends PostingsFormat {
this.minBlockSize = BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE;
this.maxBlockSize = BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE;
}
+
public ForPostingsFormat(int minBlockSize, int maxBlockSize) {
super("For");
this.blockSize = DEFAULT_BLOCK_SIZE;
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java
index 917e6ebb355..64341b4db0e 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java
@@ -45,24 +45,12 @@ public final class PForFactory extends IntStreamFactory {
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
- IndexOutput out = dir.createOutput(fileName, context);
- boolean success = false;
- try {
- FixedIntBlockIndexOutput ret = new PForIndexOutput(out, blockSize);
- success = true;
- return ret;
- } finally {
- if (!success) {
- // TODO: why handle exception like this?
- // and why not use similar codes for read part?
- IOUtils.closeWhileHandlingException(out);
- }
- }
+ return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);
}
+
@Override
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
- FixedIntBlockIndexInput ret = new PForIndexInput(dir.openInput(fileName, context));
- return ret;
+ return new PForIndexInput(dir.openInput(fileName, context));
}
// wrap input and output with buffer support
@@ -102,13 +90,15 @@ public final class PForFactory extends IntStreamFactory {
}
private class PForIndexOutput extends FixedIntBlockIndexOutput {
- private byte[] encoded;
- private IntBuffer encodedBuffer;
+ private final byte[] encoded;
+ private final IntBuffer encodedBuffer;
+
PForIndexOutput(IndexOutput out, int blockSize) throws IOException {
super(out,blockSize);
this.encoded = new byte[blockSize*8+4];
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
}
+
@Override
protected void flushBlock() throws IOException {
final int numBytes = PForUtil.compress(buffer,buffer.length,encodedBuffer);
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java
index 28444535053..ac62e8867cd 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForPostingsFormat.java
@@ -46,8 +46,7 @@ public final class PForPostingsFormat extends PostingsFormat {
private final int blockSize;
private final int minBlockSize;
private final int maxBlockSize;
- protected final static int DEFAULT_BLOCK_SIZE = 128;
- protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
+ public final static int DEFAULT_BLOCK_SIZE = 128;
public PForPostingsFormat() {
super("PFor");