我正在使用Unimarc,使用marc4j库。在我的系统中,我已经能够获得org.marc4j.marc.Record
的一个实例。现在我很难弄清楚如何计算数据的记录长度和基地址。记录前导中使用的。
我一直在尝试使用marc4j库或在它之外找到如何做到这一点,但到目前为止还找不到。
我怎样才能得到这两条信息?
我在文档中找不到任何东西,但我设法做到了。下面的函数:
public String getISO2709 (org.marc4j.marc.Record record ){
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b );
}
public String toString() {
return this.string.toString();
}
};
MarcStreamWriter writer = new MarcStreamWriter(output);
writer.write(record);
return output.toString();
}
public String getNoticeLength(org.marc4j.marc.Record record, org.marc4j.marc.Leader currentLeader){
int recordLength = this.getISO2709(record).length();
String ret = StringUtils.padLeft(String.valueOf(recordLength), '0', 5);
if(ret.length() > 5) ret ="00000"; // since the header has space for only 5 chars, this 00000 will indicate the length was invalid
return ret;
}
public String getBaseAddressOfData(org.marc4j.marc.Record record, org.marc4j.marc.Leader currentLeader){
String iso2709 = this.getISO2709(record);
StringBuilder sb = new StringBuilder();
for (ControlField cf : record.getControlFields()) {
sb.append(cf.getData() + "u001E"); // this is the character that separates the values for the control fields iso2709
}
int index = iso2709.indexOf(sb.toString());
String ret = StringUtils.padLeft(String.valueOf(index), '0', 5);
if(ret.length() > 5) ret="00000";
return ret;
}