diff --git a/README.md b/README.md index bf1ff1c..db1535d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ date (D) | `java.util.Date` float (F) | `java.lang.Float` logical (L) | `java.lang.Boolean` numeric (N) | `java.lang.Number` +integer (I) | `java.lang.Integer` ### How to use diff --git a/dbf-reader/src/main/java/org/jamel/dbf/DbfReader.java b/dbf-reader/src/main/java/org/jamel/dbf/DbfReader.java index 468eb79..ec1c312 100644 --- a/dbf-reader/src/main/java/org/jamel/dbf/DbfReader.java +++ b/dbf-reader/src/main/java/org/jamel/dbf/DbfReader.java @@ -1,14 +1,22 @@ package org.jamel.dbf; +import java.io.BufferedInputStream; +import java.io.Closeable; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.util.Date; +import java.util.GregorianCalendar; + import org.jamel.dbf.exception.DbfException; import org.jamel.dbf.structure.DbfField; import org.jamel.dbf.structure.DbfHeader; import org.jamel.dbf.utils.DbfUtils; -import java.io.*; -import java.util.Date; -import java.util.GregorianCalendar; - /** * Dbf reader. * This class is not thread safe. @@ -121,6 +129,7 @@ private Object readFieldValue(DbfField field) throws IOException { case FLOAT: return readFloatValue(field, buf); case LOGICAL: return readLogicalValue(field, buf); case NUMERIC: return readNumericValue(field, buf); + case INTEGER: return readIntegerValue(field, buf); default: return null; } } @@ -161,6 +170,16 @@ protected Number readNumericValue(DbfField field, byte[] buf) throws IOException } } + protected Integer readIntegerValue(DbfField field, byte[] buf) throws IOException { + try { + if (buf.length != 4) throw new DbfException("Failed to parse Integer from " + field.getName()); + int x = java.nio.ByteBuffer.wrap(buf).order(java.nio.ByteOrder.LITTLE_ENDIAN).getInt(); + return x; + } catch (NumberFormatException e) { + throw new DbfException("Failed to parse Integer from " + field.getName(), e); + } + } + /** * @return the number of records in the Dbf. */ diff --git a/dbf-reader/src/main/java/org/jamel/dbf/structure/DbfDataType.java b/dbf-reader/src/main/java/org/jamel/dbf/structure/DbfDataType.java index 8ac0ae0..7da2f48 100644 --- a/dbf-reader/src/main/java/org/jamel/dbf/structure/DbfDataType.java +++ b/dbf-reader/src/main/java/org/jamel/dbf/structure/DbfDataType.java @@ -9,7 +9,8 @@ public enum DbfDataType { DATE('D'), FLOAT('F'), LOGICAL('L'), - NUMERIC('N'); + NUMERIC('N'), + INTEGER('I'); public final byte byteValue;