LUCENE-5582: remove IndexOutput.length/setLength

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1586743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-04-11 18:46:43 +00:00
parent 56d171f2f2
commit bb639e561d
17 changed files with 5 additions and 99 deletions

View File

@ -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;

View File

@ -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.
* */

View File

@ -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;
}
@Override
public void writeByte(byte b) throws IOException {
assert !closed;

View File

@ -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 {

View File

@ -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 {}
}

View File

@ -107,11 +107,6 @@ public class RAMOutputStream extends IndexOutput {
flush();
}
@Override
public long length() {
return file.length;
}
@Override
public void writeByte(byte b) throws IOException {
if (bufferPosition == bufferLength) {

View File

@ -51,11 +51,6 @@ final class RateLimitedIndexOutput extends BufferedIndexOutput {
}
@Override
public long length() throws IOException {
return delegate.length();
}
@Override
public void flush() throws IOException {
try {

View File

@ -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 part

View File

@ -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(); }
}

View File

@ -236,11 +236,6 @@ public class NativeUnixDirectory extends FSDirectory {
return filePos + bufferPos;
}
@Override
public long length() {
return fileLength + bufferPos;
}
@Override
public long getChecksum() throws IOException {
throw new UnsupportedOperationException("this directory currently does not work at all!");

View File

@ -294,7 +294,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
// Totally truncate the file to zero bytes
deleteFile(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();
}
@Override
protected void flushBuffer(byte[] b, int offset, int len) throws IOException {
io.writeBytes(b, offset, len);

View File

@ -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);
}
@Override
public void copyBytes(DataInput input, long numBytes) throws IOException {
checkCrashed();

View File

@ -88,11 +88,6 @@ public class ThrottledIndexOutput extends IndexOutput {
return delegate.getFilePointer();
}
@Override
public long length() throws IOException {
return delegate.length();
}
@Override
public 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);
}
@Override
public void copyBytes(DataInput input, long numBytes) throws IOException {
delegate.copyBytes(input, numBytes);

View File

@ -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;
}
@Override
public void writeByte(byte b) throws IOException {
if (bufferPosition >= bufferSize) {

View File

@ -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();
}
}
@Override

View File

@ -44,11 +44,6 @@ public class NullIndexOutput extends IndexOutput {
return pos;
}
@Override
public long length() throws IOException {
return length;
}
@Override
public void writeByte(byte b) throws IOException {
pos++;

View File

@ -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);