\r
private CharConverter converterAnsel = null;\r
\r
+ private boolean setBadIndicators = true;\r
+\r
+ byte[] leaderBuffer;\r
/**\r
* Constructs an instance with the specified input stream.\r
*/\r
* Returns true if the iteration has more records, false otherwise.\r
*/\r
public boolean hasNext() {\r
- try {\r
- if (input.available() == 0)\r
+ int available;\r
+ try {\r
+ available = input.available();\r
+ try {\r
+ leaderBuffer = new byte[24];\r
+ input.readFully(leaderBuffer);\r
+ } catch (EOFException eof) {\r
+ // If we are not capable of reading the leader before EOF, we cannot read a record\r
+ // This happens when we read gzipped marc files, that it returns available bytes, but none is present\r
+ available = 0;\r
+ }\r
+ if (available == 0)\r
return false;\r
} catch (IOException e) {\r
throw new MarcException(e.getMessage(), e);\r
record = factory.newRecord();\r
\r
try {\r
-\r
- byte[] byteArray = new byte[24];\r
- input.readFully(byteArray);\r
-\r
- int recordLength = parseRecordLength(byteArray);\r
+ int recordLength = parseRecordLength(leaderBuffer);\r
byte[] recordBuf = new byte[recordLength - 24];\r
input.readFully(recordBuf);\r
- parseRecord(record, byteArray, recordBuf, recordLength);\r
+ parseRecord(record, leaderBuffer, recordBuf, recordLength);\r
return(record);\r
}\r
catch (EOFException e) {\r
inputrec.readFully(byteArray);\r
\r
try {\r
- record.addVariableField(parseDataField(tags[i], byteArray));\r
+ DataField dataField = parseDataField(tags[i], byteArray);\r
+ // dataField could be null if bad indicators\r
+ if (dataField != null) \r
+ record.addVariableField(dataField);\r
} catch (IOException e) {\r
throw new MarcException(\r
"error parsing data field for tag: " + tags[i]\r
\r
DataField dataField = factory.newDataField();\r
dataField.setTag(tag);\r
- dataField.setIndicator1(ind1);\r
- dataField.setIndicator2(ind2);\r
\r
+ boolean badIndicatorFound = false;\r
+ if (setBadIndicators || ind1 >= ' ' )\r
+ dataField.setIndicator1(ind1);\r
+ else\r
+ badIndicatorFound = true;\r
+ if (setBadIndicators || ind2 >= ' ')\r
+ dataField.setIndicator2(ind2);\r
+ else\r
+ badIndicatorFound = true;\r
int code;\r
int size;\r
int readByte;\r
break;\r
}\r
}\r
+ /* Bad Indicators was found, so dropping field */\r
+ if (badIndicatorFound)\r
+ return null;\r
return dataField;\r
}\r
\r
else if (encoding.equals("MARC-8") || encoding.equals("MARC8"))\r
{\r
if (converterAnsel == null) converterAnsel = new AnselToUnicode();\r
+\r
+ for (int index = 0; index < bytes.length; index++)\r
+ if (bytes[index] < 32)\r
+ bytes[index] = ' ';\r
dataElement = converterAnsel.convert(bytes);\r
+ //dataElement = dataElement.replaceAll("\0", " ");\r
}\r
else if (encoding.equals("ISO-8859-1") || encoding.equals("ISO8859_1"))\r
{\r
}\r
return dataElement;\r
}\r
+\r
+ public boolean isBadIndicators() {\r
+ return setBadIndicators;\r
+ }\r
+\r
+ public void setBadIndicators(boolean trueFalse) {\r
+ this.setBadIndicators = trueFalse;\r
+ }\r
\r
}
\ No newline at end of file