Skip to content

Commit

Permalink
fix issue iryndin#4
Browse files Browse the repository at this point in the history
should parse update date from DBF file with respect to file type
  • Loading branch information
iryndin committed Jul 23, 2014
1 parent 2c5a5df commit 41cd06e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 14 additions & 1 deletion src/main/java/net/iryndin/jdbf/util/DbfMetadataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,27 @@ private static int calculateFullHeaderLength(List<DbfField> fields) {

public static void fillHeaderFields(DbfMetadata metadata, byte[] headerBytes) {
metadata.setType(DbfFileTypeEnum.fromInt(headerBytes[0]));
metadata.setUpdateDate(JdbfUtils.createDate(headerBytes[1], headerBytes[2], headerBytes[3]));
metadata.setUpdateDate(parseHeaderUpdateDate(headerBytes[1], headerBytes[2], headerBytes[3], metadata.getType()));
metadata.setRecordsQty(BitUtils.makeInt(headerBytes[4], headerBytes[5], headerBytes[6], headerBytes[7]));
metadata.setFullHeaderLength(BitUtils.makeInt(headerBytes[8], headerBytes[9]));
metadata.setOneRecordLength(BitUtils.makeInt(headerBytes[10], headerBytes[11]));
metadata.setUncompletedTxFlag(headerBytes[14]);
metadata.setEcnryptionFlag(headerBytes[15]);
}

@SuppressWarnings("deprecation")
public static Date parseHeaderUpdateDate(byte yearByte, byte monthByte, byte dayByte, DbfFileTypeEnum fileType) {
int year = yearByte + 2000 - 1900;
switch (fileType) {
case FoxBASEPlus1:
year = yearByte;
}
int month = monthByte - 1;
int day = dayByte;
return new Date(year,month,day);

}

public static void readFields(DbfMetadata metadata, ByteArrayInputStream inputStream) throws IOException {
List<DbfField> fields = new ArrayList<>();
byte[] fieldBytes = new byte[JdbfUtils.FIELD_RECORD_LENGTH];
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/net/iryndin/jdbf/util/JdbfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public static DbfField createDbfFieldFromString(String s) {
return f;
}

@SuppressWarnings("deprecation")
public static Date createDate(byte b1, byte b2, byte b3) {
int year = b1 + 2000 - 1900;
int month = b2 - 1;
int day = b3;
return new Date(year,month,day);
}

public static byte[] writeDateForHeader(Date date) {
byte[] headerBytes = {
(byte)(date.getYear()-100),
Expand Down

0 comments on commit 41cd06e

Please sign in to comment.