private String extractIdFromRecord(final String record) { try{ final int fieldEnd = record.indexOf(FIELD_END, HEADER_SIZE); if(record.substring(HEADER_SIZE, HEADER_SIZE + TAG_LENGTH).equals(ID_TAG)){ return record.substring(HEADER_SIZE + TAG_LENGTH, fieldEnd); } throw new MissingIdException(record); } catch (IndexOutOfBoundsException e) { throw new FormatException(INVALID_FORMAT + record, e); } }
private String tryGetRecordId(final Record record) { final String id = record.getRecordId(); if (id == null) { if (!ignoreMissingId) { throw new MissingIdException("record has no id"); } return ""; } return id; }
@Override public void literal(final String name, final String value) { //A Subfield has one character or digit exactly. if (name.length() != 1) { throw new FormatException(name); } if (!entityOpen) { throw new FormatException(name); //new exceptions definition for literal out of entity } final String valueNew = Normalizer.normalize(value, Form.NFD); if (idnControlSubField) { // it is a 003@ field, the same record id delivered with record should follow if (!this.id.equals(value)) { throw new MissingIdException(value); } idnControlSubField = false; //only one record Id will be checked. } builder.append(SUB_DELIMITER); builder.append(name); builder.append(valueNew); }
@Override public void process(final String record) { assert !isClosed(); buffer = StringUtil.copyToBuffer(record, buffer); recordLen = record.length(); if (isRecordEmpty()) { return; } String id = extractRecordId(); if (id == null) { if (!ignoreMissingIdn) { throw new MissingIdException("Record has no id"); } id = ""; } getReceiver().startRecord(id); PicaParserState state = PicaParserState.FIELD_NAME; for (int i = 0; i < recordLen; ++i) { state = state.parseChar(buffer[i], parserContext); } state.endOfInput(parserContext); getReceiver().endRecord(); }