Skip to content

Commit 8c7b585

Browse files
committed
Write system chars to correct position in record
The ISO 2709 record builder wrote individually set system chars to the wrong position in the record label. Fixes #284 (cherry picked from commit 46dee86)
1 parent b26fd24 commit 8c7b585

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/LabelBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void setSystemChars(final char[] systemChars) {
124124

125125
void setSystemChar(final int index, final char value) {
126126
assert 0 <= index && index < SYSTEM_CHARS_LENGTH;
127-
buffer.setWritePosition(SYSTEM_CHARS_LENGTH + index);
127+
buffer.setWritePosition(SYSTEM_CHARS_START + index);
128128
buffer.writeChar(value);
129129
}
130130

metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordBuilderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ public void shouldThrowExceptionIfSystemCharsIsNull() {
183183
builder.setSystemChars(null); // Exception expected
184184
}
185185

186+
@Test
187+
public void shouldWriteSystemCharToRecordLabel() {
188+
builder.setSystemChar(0, 'U');
189+
builder.setSystemChar(1, 'S');
190+
builder.setSystemChar(2, 'C');
191+
192+
final byte[] record = builder.build();
193+
194+
assertEquals(0x55, record[17]);
195+
assertEquals(0x53, record[18]);
196+
assertEquals(0x43, record[19]);
197+
}
186198
@Test(expected = IllegalArgumentException.class)
187199
public void shouldThrowExceptionIfSystemCharIndexGreaterThan2() {
188200
builder.setSystemChar(3, '1');

0 commit comments

Comments
 (0)