Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>net.iryndin</groupId>
<artifactId>jdbf</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<packaging>jar</packaging>

<organization>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/net/iryndin/jdbf/util/DbfMetadataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ public static DbfField createDbfField(byte[] fieldBytes) {
field.setName(new String(fieldBytes, 0, i));
}
// 2. Set type
field.setType(DbfFieldTypeEnum.fromChar((char) fieldBytes[11]));
DbfFieldTypeEnum fieldType = DbfFieldTypeEnum.fromChar((char) fieldBytes[11]);
field.setType(fieldType);
// 3. Set length
{
int length = fieldBytes[16];
if (length < 0) {
length = 256 + length;
int length = 0;
if(fieldType == DbfFieldTypeEnum.Character){
length = BitUtils.makeInt(fieldBytes[16], fieldBytes[17]);
} else {
length = fieldBytes[16];
if (length < 0) {
length = 256 + length;
}
}
field.setLength(length);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/net/iryndin/jdbf/TestDbfReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ public void test2() throws IOException, ParseException {
}
}
}

@Test
public void testTwoBytesLength() throws IOException, ParseException {
Charset stringCharset = Charset.forName("Cp866");

InputStream dbf = getClass().getClassLoader().getResourceAsStream("data1/length_test.dbf");

DbfRecord rec;
try (DbfReader reader = new DbfReader(dbf)) {
while ((rec = reader.read()) != null) {
rec.setStringCharset(stringCharset);
System.out.println(rec.toMap());
String value = rec.getString("F19");
assertEquals(300, value.length());
}
}
}

@Test
public void testEmptyStream() throws IOException {
Expand Down
Binary file added src/test/resources/data1/length_test.dbf
Binary file not shown.