DBaseFileReader implements Iterable<AttributeProvider>, AutoCloseable { public DBaseFileRecord readNextDBFRecord() throws IOException { if (this.recordCount == -1) { throw new MustCallReadHeaderFunctionException(); } if (this.readingPosition >= this.recordCount) { return null; } try { final DBaseFileRecord record = readDBFRecord(this.readingPosition); ++this.readingPosition; return record; } catch (EOFException e) { this.finished = true; return null; } } @SuppressWarnings("resource")  DBaseFileReader(InputStream inputStream); @SuppressWarnings("resource")  DBaseFileReader(File file);  DBaseFileReader(URL url);  DBaseFileReader(ReadableByteChannel channel); @SuppressWarnings({"checkstyle:regexp", "checkstyle:magicnumber"}) static void main(String[] args); @Pure boolean hasOption(int option); void addOption(int option); void removeOption(int option); void setOption(int option, boolean option_is_set); @Override void close(); @Pure boolean isClosed(); @Pure int getDBFRecordCount(); @Pure int getDBFRecordSize(); @Pure @SuppressWarnings("checkstyle:magicnumber") int getDBFHeaderSize(); @Pure int getDBFFieldCount(); @Pure Date getDBFLastUpdateDate(); @Pure DBaseCodePage getDBFLanguage(); @Pure int getDBFVersion(); @SuppressWarnings("checkstyle:magicnumber") void readDBFHeader(); @Pure List<DBaseFileField> getDBFFields(); @Pure String getDBFFieldName(int index); @Pure int getDBFFieldIndex(String name); @Pure DBaseFieldType getDBFFieldType(int index); @SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:magicnumber"}) List<DBaseFileField> readDBFFields(); DBaseFileRecord readNextDBFRecord(); void skip(int skipAmount); void seek(int recordIndex); AttributeProvider readNextAttributeProvider(); List<DBaseFileRecord> readRestOfDBFRecords(); void selectColumn(DBaseFileField column); void selectAllColumns(); @Pure boolean isColumnSelectable(DBaseFileField column); @Override @Pure Iterator<AttributeProvider> iterator(); static final int OPTION_DECODE_STRING; }
@Test public void testReadNextDBFRecord() throws Exception { try { this.reader.readNextDBFRecord(); fail("MustCallReadHeaderFunctionException is expected"); } catch(MustCallReadHeaderFunctionException exception) { } this.reader.readDBFHeader(); this.reader.readDBFFields(); int offset = 161; DBaseFileRecord record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(0, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals(BATIMENT_RELIGIEUX_VALUE, record.getFieldValue(2)); assertEquals(15., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(1, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals(BATIMENT_RELIGIEUX_VALUE, record.getFieldValue(2)); assertEquals(7., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(2, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals(BATIMENT_RELIGIEUX_VALUE, record.getFieldValue(2)); assertEquals(11., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(3, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(5., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(4, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(23., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(5, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(6., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(6, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(6., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(7, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(7., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(8, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(5., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(9, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(2., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(10, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(14., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(11, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(27., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(12, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(8., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(13, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(14., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(14, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(11., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(15, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(30., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(16, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(23., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(17, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(PHOTOGRAMMETRIE_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(35., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(18, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(BDTOPO_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(18., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(19, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(PHOTOGRAMMETRIE_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(15., record.getFieldValue(3)); record = this.reader.readNextDBFRecord(); assertNotNull(record); assertEquals(20, record.getRecordIndex()); assertEquals(offset, record.getRecordOffset()); offset += 94; assertEquals(PHOTOGRAMMETRIE_VALUE, record.getFieldValue(0)); assertEquals("Religieux", record.getFieldValue(1)); assertEquals("Eglise", record.getFieldValue(2)); assertEquals(11., record.getFieldValue(3)); assertNull(this.reader.readNextDBFRecord()); }