Apache Lucene open-source search software
LUCENE-5582: remove IndexOutput.length/setLength
Michael McCandlessbb639e561dec
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.javaindex 2ee89dd28ee..d33ccc2f50f 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java@@ -384,7 +384,7 @@ public final class DirectPostingsFormat extends PostingsFormat {final byte[] payloads;if (hasPayloads) {ros.flush();- payloads = new byte[(int) ros.length()];+ payloads = new byte[(int) ros.getFilePointer()];ros.writeTo(payloads, 0);} else {payloads = null;diff --git a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.javaindex 91f72067edc..849fde3e2ad 100644--- a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java+++ b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java@@ -135,9 +135,6 @@ public abstract class BufferedIndexOutput extends IndexOutput {return bufferStart + bufferPosition;}- @Override- public abstract long length() throws IOException;-/*** Returns size of the used output buffer in bytes.* */diff --git a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.javaindex 405bf973c90..ad1265ad894 100644--- a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java+++ b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java@@ -326,12 +326,6 @@ final class CompoundFileWriter implements Closeable{return delegate.getFilePointer() - offset;}- @Override- public long length() throws IOException {- assert !closed;- return delegate.length() - offset;- }-@Overridepublic void writeByte(byte b) throws IOException {assert !closed;diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.javaindex 886752bb2ea..b5721dfc4cb 100644--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java@@ -389,16 +389,6 @@ public abstract class FSDirectory extends BaseDirectory {}}}-- @Override- public long length() throws IOException {- return file.length();- }-- @Override- public void setLength(long length) throws IOException {- file.setLength(length);- }}protected void fsync(String name) throws IOException {diff --git a/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/IndexOutput.javaindex b9196a1d8f5..0a2f608cb0b 100644--- a/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java+++ b/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java@@ -45,20 +45,4 @@ public abstract class IndexOutput extends DataOutput implements Closeable {/** Returns the current checksum of bytes written so far */public abstract long getChecksum() throws IOException;-- /** The number of bytes in the file. */- public abstract long length() throws IOException;-- /** Set the file length. By default, this method does- * nothing (it's optional for a Directory to implement- * it). But, certain Directory implementations (for- * example @see FSDirectory) can use this to inform the- * underlying IO system to pre-allocate the file to the- * specified size. If the length is longer than the- * current file length, the bytes added to the file are- * undefined. Otherwise the file is truncated.- * @param length file length- */- public void setLength(long length) throws IOException {}-}diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.javaindex 1f0c74f78d7..400dcf93878 100644--- a/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java+++ b/lucene/core/src/java/org/apache/lucene/store/RAMOutputStream.java@@ -107,11 +107,6 @@ public class RAMOutputStream extends IndexOutput {flush();}- @Override- public long length() {- return file.length;- }-@Overridepublic void writeByte(byte b) throws IOException {if (bufferPosition == bufferLength) {diff --git a/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.javaindex db74220f6f1..296c7f1a216 100644--- a/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java+++ b/lucene/core/src/java/org/apache/lucene/store/RateLimitedIndexOutput.java@@ -51,11 +51,6 @@ final class RateLimitedIndexOutput extends BufferedIndexOutput {}- @Override- public long length() throws IOException {- return delegate.length();- }-@Overridepublic void flush() throws IOException {try {diff --git a/lucene/core/src/test/org/apache/lucene/store/TestHugeRamFile.java b/lucene/core/src/test/org/apache/lucene/store/TestHugeRamFile.javaindex 01c7ed16cf1..30e9cc6f122 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestHugeRamFile.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestHugeRamFile.java@@ -64,12 +64,12 @@ public class TestHugeRamFile extends LuceneTestCase {b2[i] = (byte) (i & 0x0003F);}long n = 0;- assertEquals("output length must match",n,out.length());+ assertEquals("output length must match",n,out.getFilePointer());while (n <= MAX_VALUE - b1.length) {out.writeBytes(b1,0,b1.length);out.flush();n += b1.length;- assertEquals("output length must match",n,out.length());+ assertEquals("output length must match",n,out.getFilePointer());}//System.out.println("after writing b1's, length = "+out.length()+" (MAX_VALUE="+MAX_VALUE+")");int m = b2.length;@@ -81,7 +81,7 @@ public class TestHugeRamFile extends LuceneTestCase {out.writeBytes(b2,0,m);out.flush();n += m;- assertEquals("output length must match",n,out.length());+ assertEquals("output length must match",n,out.getFilePointer());}out.close();// input partdiff --git a/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java b/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.javaindex eaf78f7025d..4766dbfc766 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/SlowRAMDirectory.java@@ -166,7 +166,6 @@ public class SlowRAMDirectory extends RAMDirectory {@Override public void close() throws IOException { io.close(); }@Override public void flush() throws IOException { io.flush(); }@Override public long getFilePointer() { return io.getFilePointer(); }- @Override public long length() throws IOException { return io.length(); }@Override public long getChecksum() throws IOException { return io.getChecksum(); }}diff --git a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.javaindex 4aee314ac8e..cd288a3f65c 100644--- a/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java+++ b/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java@@ -236,11 +236,6 @@ public class NativeUnixDirectory extends FSDirectory {return filePos + bufferPos;}- @Override- public long length() {- return fileLength + bufferPos;- }-@Overridepublic long getChecksum() throws IOException {throw new UnsupportedOperationException("this directory currently does not work at all!");diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.javaindex 024cacdab03..d426b1a6f39 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java@@ -294,7 +294,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {// Totally truncate the file to zero bytesdeleteFile(name, true);IndexOutput out = in.createOutput(name, LuceneTestCase.newIOContext(randomState));- out.setLength(0);out.close();}if (LuceneTestCase.VERBOSE) {@@ -979,11 +978,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {this.io = io;}- @Override- public long length() throws IOException {- return io.length();- }-@Overrideprotected void flushBuffer(byte[] b, int offset, int len) throws IOException {io.writeBytes(b, offset, len);diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.javaindex 8745bb5ed58..4c056b2c9f7 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java@@ -74,7 +74,7 @@ public class MockIndexOutputWrapper extends IndexOutput {if (realUsage > dir.maxUsedSize) {dir.maxUsedSize = realUsage;}- String message = "fake disk full at " + dir.getRecomputedActualSizeInBytes() + " bytes when writing " + name + " (file length=" + delegate.length();+ String message = "fake disk full at " + dir.getRecomputedActualSizeInBytes() + " bytes when writing " + name + " (file length=" + delegate.getFilePointer();if (freeSpace > 0) {message += "; wrote " + freeSpace + " of " + len + " bytes";}@@ -146,16 +146,6 @@ public class MockIndexOutputWrapper extends IndexOutput {return delegate.getFilePointer();}- @Override- public long length() throws IOException {- return delegate.length();- }-- @Override- public void setLength(long length) throws IOException {- delegate.setLength(length);- }-@Overridepublic void copyBytes(DataInput input, long numBytes) throws IOException {checkCrashed();diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java b/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.javaindex 169c5498201..bcc23250ebf 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java@@ -88,11 +88,6 @@ public class ThrottledIndexOutput extends IndexOutput {return delegate.getFilePointer();}- @Override- public long length() throws IOException {- return delegate.length();- }-@Overridepublic void writeByte(byte b) throws IOException {bytes[0] = b;@@ -136,11 +131,6 @@ public class ThrottledIndexOutput extends IndexOutput {}}- @Override- public void setLength(long length) throws IOException {- delegate.setLength(length);- }-@Overridepublic void copyBytes(DataInput input, long numBytes) throws IOException {delegate.copyBytes(input, numBytes);diff --git a/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java b/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.javaindex 92018fce7af..bc251f0540a 100644--- a/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java+++ b/solr/core/src/java/org/apache/solr/store/blockcache/ReusedBufferedIndexOutput.java@@ -97,11 +97,6 @@ public abstract class ReusedBufferedIndexOutput extends IndexOutput {protected abstract void seekInternal(long pos) throws IOException;- @Override- public long length() throws IOException {- return fileLength;- }-@Overridepublic void writeByte(byte b) throws IOException {if (bufferPosition >= bufferSize) {diff --git a/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java b/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.javaindex 78237087104..ee49f62c2dd 100644--- a/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java+++ b/solr/core/src/java/org/apache/solr/store/hdfs/HdfsDirectory.java@@ -258,11 +258,6 @@ public class HdfsDirectory extends BaseDirectory {throws IOException {writer.writeBytes(b, offset, len);}-- @Override- public long length() throws IOException {- return writer.length();- }}@Overridediff --git a/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java b/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.javaindex 605d2700955..5a21ea7e5f0 100644--- a/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java+++ b/solr/core/src/java/org/apache/solr/store/hdfs/NullIndexOutput.java@@ -44,11 +44,6 @@ public class NullIndexOutput extends IndexOutput {return pos;}- @Override- public long length() throws IOException {- return length;- }-@Overridepublic void writeByte(byte b) throws IOException {pos++;diff --git a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.javaindex 98cebfe4677..e55e5b9f75f 100644--- a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java+++ b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java@@ -196,9 +196,7 @@ public class HdfsDirectoryTest extends SolrTestCaseJ4 {int writes = random.nextInt(MAX_NUMBER_OF_WRITES);int fileLength = random.nextInt(MAX_FILE_SIZE - MIN_FILE_SIZE) + MIN_FILE_SIZE;IndexOutput fsOutput = fsDir.createOutput(name, new IOContext());- fsOutput.setLength(fileLength);IndexOutput hdfsOutput = hdfs.createOutput(name, new IOContext());- hdfsOutput.setLength(fileLength);for (int i = 0; i < writes; i++) {byte[] buf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE,fileLength)) + MIN_BUFFER_SIZE];random.nextBytes(buf);