Index: lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java =================================================================== --- lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java (revision 1190231) +++ lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java (working copy) @@ -76,6 +76,7 @@ protected static class WindowsIndexInput extends BufferedIndexInput { private final long fd; private final long length; + private final File path; boolean isClone; boolean isOpen; @@ -84,6 +85,7 @@ fd = WindowsDirectory.open(file.getPath()); length = WindowsDirectory.length(fd); isOpen = true; + this.path = file; } @Override @@ -116,6 +118,11 @@ clone.isClone = true; return clone; } + + @Override + public String toString() { + return getClass().getSimpleName() + " path=" + path; + } } /** Opens a handle to a file. */ Index: lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java =================================================================== --- lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java (revision 1190231) +++ lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java (working copy) @@ -237,6 +237,7 @@ private final FileInputStream fis; private final FileChannel channel; private final int bufferSize; + private final File path; private boolean isOpen; private boolean isClone; @@ -254,7 +255,9 @@ isClone = false; filePos = -bufferSize; bufferPos = bufferSize; - //System.out.println("D open " + path + " this=" + this); + //System.out.println("D open " + path + " this=" + + //this); + this.path = path; } // for clone @@ -269,6 +272,7 @@ isClone = true; //System.out.println("D clone this=" + this); seek(other.getFilePointer()); + this.path = other.path; } @Override @@ -368,5 +372,10 @@ throw new RuntimeException(ioe); } } + + @Override + public String toString() { + return getClass().getSimpleName() + " path=" + path; + } } } Index: lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (revision 1190231) +++ lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (working copy) @@ -122,7 +122,7 @@ "31.optimized.nocfs", }; - /** This test checks that *only* IndexFormatTooOldExceptions are throws when you open and operate on too old indexes! */ + /** This test checks that *only* IndexFormatTooOldExceptions are thrown when you open and operate on too old indexes! */ public void testUnsupportedOldIndexes() throws Exception { for(int i=0;i FORMAT_CURRENT) - throw new IndexFormatTooNewException(fn, format, FORMAT_MINIMUM, FORMAT_CURRENT); + throw new IndexFormatTooNewException(in, format, FORMAT_MINIMUM, FORMAT_CURRENT); return format; } Index: lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java (working copy) @@ -18,12 +18,13 @@ */ import java.io.IOException; -import org.apache.lucene.store.IndexInput; + +import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.FieldInfos; +import org.apache.lucene.index.IndexFormatTooNewException; +import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.index.Term; -import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IndexFormatTooOldException; -import org.apache.lucene.index.IndexFormatTooNewException; +import org.apache.lucene.store.IndexInput; /** * @deprecated (4.0) No longer used with flex indexing, except for @@ -70,7 +71,7 @@ isIndex = isi; maxSkipLevels = 1; // use single-level skip lists for formats > -3 - int firstInt = input.readInt(); + int firstInt = i.readInt(); if (firstInt >= 0) { // original-format file, without explicit format version number format = 0; @@ -85,9 +86,9 @@ // check that it is a format we can understand if (format > FORMAT_MINIMUM) - throw new IndexFormatTooOldException(null, format, FORMAT_MINIMUM, FORMAT_CURRENT); + throw new IndexFormatTooOldException(i, format, FORMAT_MINIMUM, FORMAT_CURRENT); if (format < FORMAT_CURRENT) - throw new IndexFormatTooNewException(null, format, FORMAT_MINIMUM, FORMAT_CURRENT); + throw new IndexFormatTooNewException(i, format, FORMAT_MINIMUM, FORMAT_CURRENT); size = input.readLong(); // read the size Index: lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java (working copy) @@ -48,10 +48,10 @@ // check that it is a format we can understand if (format > DefaultSegmentInfosWriter.FORMAT_MINIMUM) - throw new IndexFormatTooOldException(segmentsFileName, format, + throw new IndexFormatTooOldException(input, format, DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT); if (format < DefaultSegmentInfosWriter.FORMAT_CURRENT) - throw new IndexFormatTooNewException(segmentsFileName, format, + throw new IndexFormatTooNewException(input, format, DefaultSegmentInfosWriter.FORMAT_MINIMUM, DefaultSegmentInfosWriter.FORMAT_CURRENT); infos.version = input.readLong(); // read version @@ -92,7 +92,7 @@ // If it's a 3x index touched by 3.1+ code, then segments record their // version, whether they are 2.x ones or not. We detect that and throw // appropriate exception. - throw new IndexFormatTooOldException(si.name, si.getVersion()); + throw new IndexFormatTooOldException(input, si.getVersion()); } infos.add(si); } Index: lucene/src/java/org/apache/lucene/index/codecs/DefaultFieldsReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/DefaultFieldsReader.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/index/codecs/DefaultFieldsReader.java (working copy) @@ -88,9 +88,9 @@ try { int format = idxStream.readInt(); if (format < DefaultFieldsWriter.FORMAT_MINIMUM) - throw new IndexFormatTooOldException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); + throw new IndexFormatTooOldException(idxStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); if (format > DefaultFieldsWriter.FORMAT_CURRENT) - throw new IndexFormatTooNewException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); + throw new IndexFormatTooNewException(idxStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); } finally { idxStream.close(); } @@ -128,9 +128,9 @@ format = cloneableIndexStream.readInt(); if (format < DefaultFieldsWriter.FORMAT_MINIMUM) - throw new IndexFormatTooOldException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); + throw new IndexFormatTooOldException(cloneableIndexStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); if (format > DefaultFieldsWriter.FORMAT_CURRENT) - throw new IndexFormatTooNewException(indexStreamFN, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); + throw new IndexFormatTooNewException(cloneableIndexStream, format, DefaultFieldsWriter.FORMAT_MINIMUM, DefaultFieldsWriter.FORMAT_CURRENT); fieldsStream = (IndexInput) cloneableFieldsStream.clone(); @@ -271,33 +271,4 @@ return fieldsStream; } - - /** - * Skip the field. We still have to read some of the information about the field, but can skip past the actual content. - * This will have the most payoff on large fields. - */ - private void skipField(int numeric) throws IOException { - final int numBytes; - switch(numeric) { - case 0: - numBytes = fieldsStream.readVInt(); - break; - case DefaultFieldsWriter.FIELD_IS_NUMERIC_INT: - case DefaultFieldsWriter.FIELD_IS_NUMERIC_FLOAT: - numBytes = 4; - break; - case DefaultFieldsWriter.FIELD_IS_NUMERIC_LONG: - case DefaultFieldsWriter.FIELD_IS_NUMERIC_DOUBLE: - numBytes = 8; - break; - default: - throw new FieldReaderException("Invalid numeric type: " + Integer.toHexString(numeric)); - } - - skipFieldBytes(numBytes); - } - - private void skipFieldBytes(int toRead) throws IOException { - fieldsStream.seek(fieldsStream.getFilePointer() + toRead); - } } Index: lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java (working copy) @@ -83,8 +83,8 @@ public IndexInputSlicer createSlicer(final String name, final IOContext context) throws IOException { ensureOpen(); - final File file = new File(getDirectory(), name); - final Descriptor descriptor = new Descriptor(file, "r"); + final File path = new File(getDirectory(), name); + final Descriptor descriptor = new Descriptor(path, "r"); return new Directory.IndexInputSlicer() { @Override @@ -94,7 +94,7 @@ @Override public IndexInput openSlice(long offset, long length) throws IOException { - return new NIOFSIndexInput(descriptor, descriptor.getChannel(), offset, + return new NIOFSIndexInput(path, descriptor, descriptor.getChannel(), offset, length, BufferedIndexInput.bufferSize(context), getReadChunkSize()); } @@ -119,8 +119,8 @@ channel = file.getChannel(); } - public NIOFSIndexInput(Descriptor file, FileChannel fc, long off, long length, int bufferSize, int chunkSize) throws IOException { - super(file, off, length, bufferSize, chunkSize); + public NIOFSIndexInput(File path, Descriptor file, FileChannel fc, long off, long length, int bufferSize, int chunkSize) throws IOException { + super(path, file, off, length, bufferSize, chunkSize); channel = fc; isClone = true; } Index: lucene/src/java/org/apache/lucene/store/MMapDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/MMapDirectory.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/MMapDirectory.java (working copy) @@ -213,7 +213,7 @@ File f = new File(getDirectory(), name); RandomAccessFile raf = new RandomAccessFile(f, "r"); try { - return new MMapIndexInput(raf, 0, raf.length(), chunkSizePower); + return new MMapIndexInput(f, raf, 0, raf.length(), chunkSizePower); } finally { raf.close(); } @@ -221,7 +221,7 @@ public IndexInputSlicer createSlicer(final String name, final IOContext context) throws IOException { ensureOpen(); - File f = new File(getDirectory(), name); + final File f = new File(getDirectory(), name); final RandomAccessFile raf = new RandomAccessFile(f, "r"); return new IndexInputSlicer() { @Override @@ -231,7 +231,7 @@ @Override public IndexInput openSlice(long offset, long length) throws IOException { - return new MMapIndexInput(raf, offset, length, chunkSizePower); + return new MMapIndexInput(f, raf, offset, length, chunkSizePower); } @Override @@ -256,8 +256,11 @@ private ByteBuffer curBuf; // redundant for speed: buffers[curBufIndex] private boolean isClone = false; + + private final File path; - MMapIndexInput(RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException { + MMapIndexInput(File path, RandomAccessFile raf, long offset, long length, int chunkSizePower) throws IOException { + this.path = path; this.length = length; this.chunkSizePower = chunkSizePower; this.chunkSize = 1L << chunkSizePower; @@ -420,6 +423,11 @@ buffers = null; } } + + @Override + public String toString() { + return getClass().getSimpleName() + ": path=" + path; + } } } Index: lucene/src/java/org/apache/lucene/store/Directory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/Directory.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/Directory.java (working copy) @@ -344,5 +344,10 @@ base.copyBytes(out, numBytes); } } + + @Override + public String toString() { + return getClass().getSimpleName() + "(" + base + ")"; + } } } Index: lucene/src/java/org/apache/lucene/store/RAMDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/RAMDirectory.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/RAMDirectory.java (working copy) @@ -183,7 +183,7 @@ if (file == null) { throw new FileNotFoundException(name); } - return new RAMInputStream(file); + return new RAMInputStream(name, file); } /** Closes the store to future operations, releasing associated memory. */ Index: lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java (working copy) @@ -74,7 +74,7 @@ @Override public IndexInput openSlice(long offset, long length) throws IOException { - return new SimpleFSIndexInput(descriptor, offset, + return new SimpleFSIndexInput(file, descriptor, offset, length, BufferedIndexInput.bufferSize(context), getReadChunkSize()); } @@ -116,17 +116,20 @@ protected final int chunkSize; protected final long off; protected final long end; + protected final File path; public SimpleFSIndexInput(File path, IOContext context, int chunkSize) throws IOException { super(context); + this.path = path; this.file = new Descriptor(path, "r"); this.chunkSize = chunkSize; this.off = 0L; this.end = file.length; } - public SimpleFSIndexInput(Descriptor file, long off, long length, int bufferSize, int chunkSize) throws IOException { + public SimpleFSIndexInput(File path, Descriptor file, long off, long length, int bufferSize, int chunkSize) throws IOException { super(bufferSize); + this.path = path; this.file = file; this.chunkSize = chunkSize; this.off = off; @@ -211,5 +214,10 @@ // If out is FSIndexOutput, the copy will be optimized out.copyBytes(this, numBytes); } + + @Override + public String toString() { + return getClass().getSimpleName() + ": path=" + path; + } } } Index: lucene/src/java/org/apache/lucene/store/ChecksumIndexInput.java =================================================================== --- lucene/src/java/org/apache/lucene/store/ChecksumIndexInput.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/ChecksumIndexInput.java (working copy) @@ -73,4 +73,9 @@ public long length() { return main.length(); } + + @Override + public String toString() { + return getClass().getSimpleName() + "(" + main.toString() + ")"; + } } Index: lucene/src/java/org/apache/lucene/store/RAMInputStream.java =================================================================== --- lucene/src/java/org/apache/lucene/store/RAMInputStream.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/store/RAMInputStream.java (working copy) @@ -34,8 +34,9 @@ private int bufferPosition; private long bufferStart; private int bufferLength; + private final String name; - public RAMInputStream(RAMFile f) throws IOException { + public RAMInputStream(String name, RAMFile f) throws IOException { file = f; length = file.length; if (length/BUFFER_SIZE >= Integer.MAX_VALUE) { @@ -46,6 +47,7 @@ // first needed buffer lazily currentBufferIndex = -1; currentBuffer = null; + this.name = name; } @Override @@ -137,4 +139,9 @@ } bufferPosition = (int) (pos % BUFFER_SIZE); } + + @Override + public String toString() { + return getClass().getSimpleName() + " name=" + name; + } } Index: lucene/src/java/org/apache/lucene/util/CodecUtil.java =================================================================== --- lucene/src/java/org/apache/lucene/util/CodecUtil.java (revision 1190231) +++ lucene/src/java/org/apache/lucene/util/CodecUtil.java (working copy) @@ -18,14 +18,14 @@ */ -import org.apache.lucene.store.DataInput; -import org.apache.lucene.store.DataOutput; +import java.io.IOException; + import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; -import java.io.IOException; - /** * @lucene.experimental */ @@ -58,20 +58,20 @@ // Safety to guard against reading a bogus string: final int actualHeader = in.readInt(); if (actualHeader != CODEC_MAGIC) { - throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC); + throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC + "; input=" + in); } final String actualCodec = in.readString(); if (!actualCodec.equals(codec)) { - throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec); + throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec + "; input=" + in); } final int actualVersion = in.readInt(); if (actualVersion < minVersion) { - throw new IndexFormatTooOldException(null, actualVersion, minVersion, maxVersion); + throw new IndexFormatTooOldException(in, actualVersion, minVersion, maxVersion); } if (actualVersion > maxVersion) { - throw new IndexFormatTooNewException(null, actualVersion, minVersion, maxVersion); + throw new IndexFormatTooNewException(in, actualVersion, minVersion, maxVersion); } return actualVersion;