mirror of https://github.com/apache/lucene.git
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:
parent
56d171f2f2
commit
bb639e561d
|
@ -384,7 +384,7 @@ public final class DirectPostingsFormat extends PostingsFormat {
|
||||||
final byte[] payloads;
|
final byte[] payloads;
|
||||||
if (hasPayloads) {
|
if (hasPayloads) {
|
||||||
ros.flush();
|
ros.flush();
|
||||||
payloads = new byte[(int) ros.length()];
|
payloads = new byte[(int) ros.getFilePointer()];
|
||||||
ros.writeTo(payloads, 0);
|
ros.writeTo(payloads, 0);
|
||||||
} else {
|
} else {
|
||||||
payloads = null;
|
payloads = null;
|
||||||
|
|
|
@ -135,9 +135,6 @@ public abstract class BufferedIndexOutput extends IndexOutput {
|
||||||
return bufferStart + bufferPosition;
|
return bufferStart + bufferPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract long length() throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns size of the used output buffer in bytes.
|
* Returns size of the used output buffer in bytes.
|
||||||
* */
|
* */
|
||||||
|
|
|
@ -326,12 +326,6 @@ final class CompoundFileWriter implements Closeable{
|
||||||
return delegate.getFilePointer() - offset;
|
return delegate.getFilePointer() - offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
assert !closed;
|
|
||||||
return delegate.length() - offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeByte(byte b) throws IOException {
|
public void writeByte(byte b) throws IOException {
|
||||||
assert !closed;
|
assert !closed;
|
||||||
|
|
|
@ -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 {
|
protected void fsync(String name) throws IOException {
|
||||||
|
|
|
@ -45,20 +45,4 @@ public abstract class IndexOutput extends DataOutput implements Closeable {
|
||||||
|
|
||||||
/** Returns the current checksum of bytes written so far */
|
/** Returns the current checksum of bytes written so far */
|
||||||
public abstract long getChecksum() throws IOException;
|
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 {}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,11 +107,6 @@ public class RAMOutputStream extends IndexOutput {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() {
|
|
||||||
return file.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeByte(byte b) throws IOException {
|
public void writeByte(byte b) throws IOException {
|
||||||
if (bufferPosition == bufferLength) {
|
if (bufferPosition == bufferLength) {
|
||||||
|
|
|
@ -51,11 +51,6 @@ final class RateLimitedIndexOutput extends BufferedIndexOutput {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return delegate.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -64,12 +64,12 @@ public class TestHugeRamFile extends LuceneTestCase {
|
||||||
b2[i] = (byte) (i & 0x0003F);
|
b2[i] = (byte) (i & 0x0003F);
|
||||||
}
|
}
|
||||||
long n = 0;
|
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) {
|
while (n <= MAX_VALUE - b1.length) {
|
||||||
out.writeBytes(b1,0,b1.length);
|
out.writeBytes(b1,0,b1.length);
|
||||||
out.flush();
|
out.flush();
|
||||||
n += b1.length;
|
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+")");
|
//System.out.println("after writing b1's, length = "+out.length()+" (MAX_VALUE="+MAX_VALUE+")");
|
||||||
int m = b2.length;
|
int m = b2.length;
|
||||||
|
@ -81,7 +81,7 @@ public class TestHugeRamFile extends LuceneTestCase {
|
||||||
out.writeBytes(b2,0,m);
|
out.writeBytes(b2,0,m);
|
||||||
out.flush();
|
out.flush();
|
||||||
n += m;
|
n += m;
|
||||||
assertEquals("output length must match",n,out.length());
|
assertEquals("output length must match",n,out.getFilePointer());
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
// input part
|
// input part
|
||||||
|
|
|
@ -166,7 +166,6 @@ public class SlowRAMDirectory extends RAMDirectory {
|
||||||
@Override public void close() throws IOException { io.close(); }
|
@Override public void close() throws IOException { io.close(); }
|
||||||
@Override public void flush() throws IOException { io.flush(); }
|
@Override public void flush() throws IOException { io.flush(); }
|
||||||
@Override public long getFilePointer() { return io.getFilePointer(); }
|
@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(); }
|
@Override public long getChecksum() throws IOException { return io.getChecksum(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,11 +236,6 @@ public class NativeUnixDirectory extends FSDirectory {
|
||||||
return filePos + bufferPos;
|
return filePos + bufferPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() {
|
|
||||||
return fileLength + bufferPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getChecksum() throws IOException {
|
public long getChecksum() throws IOException {
|
||||||
throw new UnsupportedOperationException("this directory currently does not work at all!");
|
throw new UnsupportedOperationException("this directory currently does not work at all!");
|
||||||
|
|
|
@ -294,7 +294,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
|
||||||
// Totally truncate the file to zero bytes
|
// Totally truncate the file to zero bytes
|
||||||
deleteFile(name, true);
|
deleteFile(name, true);
|
||||||
IndexOutput out = in.createOutput(name, LuceneTestCase.newIOContext(randomState));
|
IndexOutput out = in.createOutput(name, LuceneTestCase.newIOContext(randomState));
|
||||||
out.setLength(0);
|
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
if (LuceneTestCase.VERBOSE) {
|
if (LuceneTestCase.VERBOSE) {
|
||||||
|
@ -979,11 +978,6 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
|
||||||
this.io = io;
|
this.io = io;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return io.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void flushBuffer(byte[] b, int offset, int len) throws IOException {
|
protected void flushBuffer(byte[] b, int offset, int len) throws IOException {
|
||||||
io.writeBytes(b, offset, len);
|
io.writeBytes(b, offset, len);
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class MockIndexOutputWrapper extends IndexOutput {
|
||||||
if (realUsage > dir.maxUsedSize) {
|
if (realUsage > dir.maxUsedSize) {
|
||||||
dir.maxUsedSize = realUsage;
|
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) {
|
if (freeSpace > 0) {
|
||||||
message += "; wrote " + freeSpace + " of " + len + " bytes";
|
message += "; wrote " + freeSpace + " of " + len + " bytes";
|
||||||
}
|
}
|
||||||
|
@ -146,16 +146,6 @@ public class MockIndexOutputWrapper extends IndexOutput {
|
||||||
return delegate.getFilePointer();
|
return delegate.getFilePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return delegate.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLength(long length) throws IOException {
|
|
||||||
delegate.setLength(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyBytes(DataInput input, long numBytes) throws IOException {
|
public void copyBytes(DataInput input, long numBytes) throws IOException {
|
||||||
checkCrashed();
|
checkCrashed();
|
||||||
|
|
|
@ -88,11 +88,6 @@ public class ThrottledIndexOutput extends IndexOutput {
|
||||||
return delegate.getFilePointer();
|
return delegate.getFilePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return delegate.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeByte(byte b) throws IOException {
|
public void writeByte(byte b) throws IOException {
|
||||||
bytes[0] = b;
|
bytes[0] = b;
|
||||||
|
@ -136,11 +131,6 @@ public class ThrottledIndexOutput extends IndexOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLength(long length) throws IOException {
|
|
||||||
delegate.setLength(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyBytes(DataInput input, long numBytes) throws IOException {
|
public void copyBytes(DataInput input, long numBytes) throws IOException {
|
||||||
delegate.copyBytes(input, numBytes);
|
delegate.copyBytes(input, numBytes);
|
||||||
|
|
|
@ -97,11 +97,6 @@ public abstract class ReusedBufferedIndexOutput extends IndexOutput {
|
||||||
|
|
||||||
protected abstract void seekInternal(long pos) throws IOException;
|
protected abstract void seekInternal(long pos) throws IOException;
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return fileLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeByte(byte b) throws IOException {
|
public void writeByte(byte b) throws IOException {
|
||||||
if (bufferPosition >= bufferSize) {
|
if (bufferPosition >= bufferSize) {
|
||||||
|
|
|
@ -258,11 +258,6 @@ public class HdfsDirectory extends BaseDirectory {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
writer.writeBytes(b, offset, len);
|
writer.writeBytes(b, offset, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return writer.length();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,11 +44,6 @@ public class NullIndexOutput extends IndexOutput {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long length() throws IOException {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeByte(byte b) throws IOException {
|
public void writeByte(byte b) throws IOException {
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -196,9 +196,7 @@ public class HdfsDirectoryTest extends SolrTestCaseJ4 {
|
||||||
int writes = random.nextInt(MAX_NUMBER_OF_WRITES);
|
int writes = random.nextInt(MAX_NUMBER_OF_WRITES);
|
||||||
int fileLength = random.nextInt(MAX_FILE_SIZE - MIN_FILE_SIZE) + MIN_FILE_SIZE;
|
int fileLength = random.nextInt(MAX_FILE_SIZE - MIN_FILE_SIZE) + MIN_FILE_SIZE;
|
||||||
IndexOutput fsOutput = fsDir.createOutput(name, new IOContext());
|
IndexOutput fsOutput = fsDir.createOutput(name, new IOContext());
|
||||||
fsOutput.setLength(fileLength);
|
|
||||||
IndexOutput hdfsOutput = hdfs.createOutput(name, new IOContext());
|
IndexOutput hdfsOutput = hdfs.createOutput(name, new IOContext());
|
||||||
hdfsOutput.setLength(fileLength);
|
|
||||||
for (int i = 0; i < writes; i++) {
|
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];
|
byte[] buf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE,fileLength)) + MIN_BUFFER_SIZE];
|
||||||
random.nextBytes(buf);
|
random.nextBytes(buf);
|
||||||
|
|
Loading…
Reference in New Issue