mirror of https://github.com/apache/lucene.git
LUCENE-3680: exception consistency in o.a.l.store
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1228727 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
defd51a11b
commit
19801a4d87
|
@ -17,6 +17,7 @@ package org.apache.lucene.store;
|
|||
* the License.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -340,7 +341,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {
|
|||
throw new IOException(ioe.getMessage() + ": " + this, ioe);
|
||||
}
|
||||
if (n < 0) {
|
||||
throw new IOException("eof: " + this);
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
buffer.rewind();
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class WindowsDirectory extends FSDirectory {
|
|||
}
|
||||
|
||||
if (bytesRead != length) {
|
||||
throw new EOFException("Read past EOF (resource: " + this + ")");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.lucene.store;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
|
||||
/** Base implementation class for buffered {@link IndexInput}. */
|
||||
|
@ -138,7 +139,7 @@ public abstract class BufferedIndexInput extends IndexInput {
|
|||
if(bufferLength<len){
|
||||
// Throw an exception when refill() could not read len bytes:
|
||||
System.arraycopy(buffer, 0, b, offset, bufferLength);
|
||||
throw new IOException("read past EOF");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
} else {
|
||||
System.arraycopy(buffer, 0, b, offset, len);
|
||||
bufferPosition=len;
|
||||
|
@ -153,7 +154,7 @@ public abstract class BufferedIndexInput extends IndexInput {
|
|||
// had in the buffer.
|
||||
long after = bufferStart+bufferPosition+len;
|
||||
if(after > length())
|
||||
throw new IOException("read past EOF");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
readInternal(b, offset, len);
|
||||
bufferStart = after;
|
||||
bufferPosition = 0;
|
||||
|
@ -231,7 +232,7 @@ public abstract class BufferedIndexInput extends IndexInput {
|
|||
end = length();
|
||||
int newLength = (int)(end - start);
|
||||
if (newLength <= 0)
|
||||
throw new IOException("read past EOF");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
|
||||
if (buffer == null) {
|
||||
newBuffer(new byte[bufferSize]); // allocate buffer lazily
|
||||
|
|
|
@ -100,11 +100,11 @@ public final class ByteArrayDataInput extends DataInput {
|
|||
|
||||
@Override
|
||||
public int readVInt() {
|
||||
checkBounds();
|
||||
assert checkBounds();
|
||||
byte b = bytes[pos++];
|
||||
int i = b & 0x7F;
|
||||
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
|
||||
checkBounds();
|
||||
assert checkBounds();
|
||||
b = bytes[pos++];
|
||||
i |= (b & 0x7F) << shift;
|
||||
}
|
||||
|
@ -113,11 +113,11 @@ public final class ByteArrayDataInput extends DataInput {
|
|||
|
||||
@Override
|
||||
public long readVLong() {
|
||||
checkBounds();
|
||||
assert checkBounds();
|
||||
byte b = bytes[pos++];
|
||||
long i = b & 0x7F;
|
||||
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
|
||||
checkBounds();
|
||||
assert checkBounds();
|
||||
b = bytes[pos++];
|
||||
i |= (b & 0x7FL) << shift;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public final class ByteArrayDataInput extends DataInput {
|
|||
// NOTE: AIOOBE not EOF if you read too much
|
||||
@Override
|
||||
public byte readByte() {
|
||||
checkBounds();
|
||||
assert checkBounds();
|
||||
return bytes[pos++];
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,6 @@ public final class ByteArrayDataInput extends DataInput {
|
|||
}
|
||||
|
||||
private boolean checkBounds() {
|
||||
assert pos < limit;
|
||||
return true;
|
||||
return pos < limit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public final class CompoundFileDirectory extends Directory {
|
|||
final String id = IndexFileNames.stripSegmentName(name);
|
||||
final FileEntry entry = entries.get(id);
|
||||
if (entry == null) {
|
||||
throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
||||
throw new FileNotFoundException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
||||
}
|
||||
return handle.openSlice(name, entry.offset, entry.length);
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ public final class CompoundFileDirectory extends Directory {
|
|||
final String id = IndexFileNames.stripSegmentName(name);
|
||||
final FileEntry entry = entries.get(id);
|
||||
if (entry == null) {
|
||||
throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
||||
throw new FileNotFoundException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");
|
||||
}
|
||||
return new IndexInputSlicer() {
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for performing read operations of Lucene's low-level
|
||||
* data types.
|
||||
|
@ -166,7 +168,7 @@ public abstract class DataInput implements Cloneable {
|
|||
int length = readVInt();
|
||||
final byte[] bytes = new byte[length];
|
||||
readBytes(bytes, 0, length);
|
||||
return new String(bytes, 0, length, "UTF-8");
|
||||
return new String(bytes, 0, length, IOUtils.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
/** Returns a clone of this stream.
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.lucene.store;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.Closeable;
|
||||
|
@ -305,7 +306,7 @@ public abstract class Directory implements Closeable {
|
|||
protected void readInternal(byte[] b, int offset, int len) throws IOException {
|
||||
long start = getFilePointer();
|
||||
if(start + len > length)
|
||||
throw new IOException("read past EOF");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
base.seek(fileOffset + start);
|
||||
base.readBytes(b, offset, len, false);
|
||||
}
|
||||
|
@ -338,7 +339,7 @@ public abstract class Directory implements Closeable {
|
|||
if (numBytes > 0) {
|
||||
long start = getFilePointer();
|
||||
if (start + numBytes > length) {
|
||||
throw new IOException("read past EOF");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
base.seek(fileOffset + start);
|
||||
base.copyBytes(out, numBytes);
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.lucene.store;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
|
@ -303,7 +304,7 @@ public class MMapDirectory extends FSDirectory {
|
|||
do {
|
||||
curBufIndex++;
|
||||
if (curBufIndex >= buffers.length) {
|
||||
throw new IOException("read past EOF: " + this);
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
curBuf = buffers[curBufIndex];
|
||||
curBuf.position(0);
|
||||
|
@ -326,7 +327,7 @@ public class MMapDirectory extends FSDirectory {
|
|||
offset += curAvail;
|
||||
curBufIndex++;
|
||||
if (curBufIndex >= buffers.length) {
|
||||
throw new IOException("read past EOF: " + this);
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
curBuf = buffers[curBufIndex];
|
||||
curBuf.position(0);
|
||||
|
@ -394,12 +395,12 @@ public class MMapDirectory extends FSDirectory {
|
|||
if (pos < 0L) {
|
||||
throw new IllegalArgumentException("Seeking to negative position: " + this);
|
||||
}
|
||||
throw new IOException("seek past EOF");
|
||||
throw new EOFException("seek past EOF: " + this);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
if (pos < 0L) {
|
||||
throw new IllegalArgumentException("Seeking to negative position: " + this);
|
||||
}
|
||||
throw new IOException("seek past EOF: " + this);
|
||||
throw new EOFException("seek past EOF: " + this);
|
||||
} catch (NullPointerException npe) {
|
||||
throw new AlreadyClosedException("MMapIndexInput already closed: " + this);
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ public class NIOFSDirectory extends FSDirectory {
|
|||
long pos = getFilePointer() + off;
|
||||
|
||||
if (pos + len > end) {
|
||||
throw new EOFException("read past EOF (resource: " + this + ")");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -91,7 +91,7 @@ public class RAMInputStream extends IndexInput implements Cloneable {
|
|||
if (currentBufferIndex >= file.numBuffers()) {
|
||||
// end of file reached, no more buffers left
|
||||
if (enforceEOF) {
|
||||
throw new EOFException("Read past EOF (resource: " + this + ")");
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
} else {
|
||||
// Force EOF if a read takes place at this position
|
||||
currentBufferIndex--;
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.lucene.store;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
@ -145,7 +146,7 @@ public class SimpleFSDirectory extends FSDirectory {
|
|||
int total = 0;
|
||||
|
||||
if (position + len > end) {
|
||||
throw new IOException("read past EOF: " + this);
|
||||
throw new EOFException("read past EOF: " + this);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.apache.lucene.util;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -59,7 +60,7 @@ public class TestByteBlockPool extends LuceneTestCase {
|
|||
try {
|
||||
input.readByte();
|
||||
fail("must be EOF");
|
||||
} catch (IOException e) {
|
||||
} catch (EOFException e) {
|
||||
// expected - read past EOF
|
||||
}
|
||||
dir.close();
|
||||
|
|
Loading…
Reference in New Issue