ShapeFileIndexReader extends AbstractCommonShapeFileReader<ShapeFileIndexRecord> { @Override public void seek(int recordIndex) throws IOException { readHeader(); int ri = recordIndex; if (ri < 0) { ri = 0; } if (ri >= this.recordCount) { throw new EOFException(); } setReadingPosition(recordIndex, RECORD_SIZE * ri); } ShapeFileIndexReader(ReadableByteChannel channel);  ShapeFileIndexReader(InputStream inputStream); @SuppressWarnings("resource")  ShapeFileIndexReader(File file);  ShapeFileIndexReader(URL file); int getRecordCount(); @Override void seek(int recordIndex);  }
@Test public void testSeek_seekenabled() throws Exception { ShapeFileIndexRecord obj; this.reader.seek(0); obj = this.reader.read(); assertNotNull(obj); assertEquals(0, obj.getRecordIndex()); assertEquals(100, obj.getOffsetInFile()); assertEquals(128, obj.getRecordContentLength()); this.reader.seek(2); obj = this.reader.read(); assertNotNull(obj); assertEquals(2, obj.getRecordIndex()); assertEquals(420, obj.getOffsetInFile()); assertEquals(128, obj.getRecordContentLength()); this.reader.seek(1); obj = this.reader.read(); assertNotNull(obj); assertEquals(1, obj.getRecordIndex()); assertEquals(236, obj.getOffsetInFile()); assertEquals(176, obj.getRecordContentLength()); this.reader.seek(2); obj = this.reader.read(); assertNotNull(obj); assertEquals(2, obj.getRecordIndex()); assertEquals(420, obj.getOffsetInFile()); assertEquals(128, obj.getRecordContentLength()); this.reader.seek(0); obj = this.reader.read(); assertNotNull(obj); assertEquals(0, obj.getRecordIndex()); assertEquals(100, obj.getOffsetInFile()); assertEquals(128, obj.getRecordContentLength()); this.reader.seek(18); obj = this.reader.read(); assertNotNull(obj); assertEquals(18, obj.getRecordIndex()); assertEquals(3860, obj.getOffsetInFile()); assertEquals(256, obj.getRecordContentLength()); try { this.reader.seek(100000); fail("EOFException was expected"); } catch (EOFException exception) { } }
@Test public void testSeek_seekdisabled() throws Exception { this.reader.disableSeek(); try { this.reader.seek(0); fail("IOException was expected"); } catch (IOException exception) { } try { this.reader.seek(2); fail("IOException was expected"); } catch (IOException exception) { } try { this.reader.seek(1); fail("IOException was expected"); } catch (IOException exception) { } try { this.reader.seek(100000); fail("IOException was expected"); } catch (IOException exception) { } }