forked from iryndin/jdbf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jdbf 2.0: add ability to read DBF files with MEMO fields
- Loading branch information
Showing
17 changed files
with
392 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.iryndin.jdbf.core; | ||
|
||
import net.iryndin.jdbf.util.BitUtils; | ||
|
||
/** | ||
* See http://msdn.microsoft.com/en-US/library/8599s21w(v=vs.80).aspx | ||
*/ | ||
public class MemoFileHeader { | ||
private byte[] headerBytes; | ||
private int nextFreeBlockLocation; | ||
private int blockSize; | ||
|
||
public static MemoFileHeader create(byte[] headerBytes) { | ||
MemoFileHeader h = new MemoFileHeader(); | ||
h.setHeaderBytes(headerBytes); | ||
h.calculateHeaderFields(); | ||
return h; | ||
} | ||
|
||
private void calculateHeaderFields() { | ||
this.nextFreeBlockLocation = BitUtils.makeInt(headerBytes[3],headerBytes[2],headerBytes[1],headerBytes[0]); | ||
this.blockSize = BitUtils.makeInt(headerBytes[7],headerBytes[6]); | ||
} | ||
|
||
private void setHeaderBytes(byte[] headerBytes) { | ||
this.headerBytes = headerBytes; | ||
} | ||
|
||
public int getNextFreeBlockLocation() { | ||
return nextFreeBlockLocation; | ||
} | ||
|
||
public int getBlockSize() { | ||
return blockSize; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MemoFileHeader{" + | ||
"nextFreeBlockLocation=" + nextFreeBlockLocation + | ||
", blockSize=" + blockSize + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.iryndin.jdbf.core; | ||
|
||
import net.iryndin.jdbf.util.BitUtils; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
public class MemoRecord { | ||
private final int blockSize; | ||
private final int offsetInBlocks; | ||
private byte[] value; | ||
private int length; | ||
private MemoRecordTypeEnum memoType; | ||
|
||
public MemoRecord(byte[] header, byte[] value, int blockSize, int offsetInBlocks) { | ||
this.value = value; | ||
calculateFields(header); | ||
this.blockSize = blockSize; | ||
this.offsetInBlocks = offsetInBlocks; | ||
} | ||
|
||
private void calculateFields(byte[] bytes) { | ||
int type = BitUtils.makeInt(bytes[3],bytes[2],bytes[1],bytes[0]); | ||
this.memoType = MemoRecordTypeEnum.fromInt(type); | ||
this.length = BitUtils.makeInt(bytes[7],bytes[6],bytes[5],bytes[4]); | ||
} | ||
|
||
public byte[] getValue() { | ||
return value; | ||
} | ||
|
||
public String getValueAsString(Charset charset) { | ||
return new String(value, charset); | ||
} | ||
|
||
/** | ||
* Memo record length in bytes | ||
* @return | ||
*/ | ||
public int getLength() { | ||
return length; | ||
} | ||
|
||
public MemoRecordTypeEnum getMemoType() { | ||
return memoType; | ||
} | ||
|
||
public int getBlockSize() { | ||
return blockSize; | ||
} | ||
|
||
public int getOffsetInBlocks() { | ||
return offsetInBlocks; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/net/iryndin/jdbf/core/MemoRecordTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.iryndin.jdbf.core; | ||
|
||
public enum MemoRecordTypeEnum { | ||
IMAGE(0x0), | ||
TEXT(0x1); | ||
|
||
final int type; | ||
|
||
MemoRecordTypeEnum(int type) { | ||
this.type= type; | ||
} | ||
|
||
public static MemoRecordTypeEnum fromInt(int type) { | ||
for (MemoRecordTypeEnum e : MemoRecordTypeEnum.values()) { | ||
if (e.type == type) { | ||
return e; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.