protected Header readHeaderFromStream(InputStream is) throws IOException { ReadableByteChannel channel = Channels.newChannel(is); // Read header fixed portion ByteBuffer headerBuffer = ShapefileUtils.readByteChannelToBuffer(channel, FIXED_HEADER_LENGTH); Header header = this.readHeaderFromBuffer(headerBuffer); // Read fields description header int fieldsHeaderLength = header.headerLength - FIXED_HEADER_LENGTH; header.fieldsHeaderBuffer = ShapefileUtils.readByteChannelToBuffer(channel, fieldsHeaderLength); return header; }
protected List<DBaseRecord> readRecordsFromStream(InputStream is) throws IOException { List<DBaseRecord> records = new ArrayList<DBaseRecord>(); ByteBuffer recordBuffer = ByteBuffer.allocate(this.getRecordLength()); ReadableByteChannel channel = Channels.newChannel(is); // Read all records for (int i = 0; i < this.getNumberOfRecords(); i++) { // Read record recordBuffer.rewind(); ShapefileUtils.readByteChannelToBuffer(channel, this.getRecordLength(), recordBuffer); records.add(DBaseRecord.fromBuffer(this, recordBuffer, i + 1)); } return records; }