albfernandez / javadbf

Java library for reading and writing Xbase (dBase/DBF) files.
GNU Lesser General Public License v3.0
220 stars 98 forks source link

Possibility to read MEMO field as binary data, regardless of field defintion #98

Closed HelmutL closed 7 months ago

HelmutL commented 2 years ago

I have a file in an application that has been written using Visual Foxpro. The file contains MEMO type fields. The byte 18 of the field definition is 0x00, The byte 3 in the Memo Block Header (in the memofile) is set to 0x01 (text).

Nevertheless, this field contains images (e.g. JPG type) and it seems Visual Foxpro does not care.

Now, reading these fields by DBFReader converts them to String, which makes the data unusable, even if converted to byte[] by String.getBytes();

I need a possiblity to bypass this conversion and read the field's "raw data" to a byte[].

Regards

albfernandez commented 7 months ago

Hi

A new method will be available in 2.0 to override default, and force to read memo fieds as binary

setReadMemoFieldAsBinary You must call this method before read the data

Example:

File file = new File("src/test/resources/fixtures/dbase_8b.dbf");
DBFReader reader  = null;
try {
    reader = new DBFReader( new BufferedInputStream(new FileInputStream(file)));
    reader.setMemoFile(new File("src/test/resources/fixtures/dbase_8b.dbt"));
    reader.setReadMemoFieldsAsBinary("MEMO");
    DBFRow row = null;
    while ((row = reader.nextRow()) != null) {
        byte[] data = row.getBytes("MEMO");
        // Do whatever you wan't with de data
    }

}
finally {
    DBFUtils.close(reader);
}
HelmutL commented 7 months ago

Hi,

just in case you might be interested. I had the challenge to create files useable by existing VFP (Visual FoxPro) programs, also having memory files.

I wrote a "quick and dirty" class  DBFWrite2 (derived from DBFWRITE) to make it possible. It certainly would need a better integration to javadbf and error checking.

To achieve this, I had to do some modifications in existing modules:

Attached the sources

Regards Helmut Leiniinger

-- Diese E-Mail wurde von Avast-Antivirussoftware auf Viren geprüft. www.avast.com

albfernandez commented 6 months ago

Hi @HelmutL

The files are missed. Maybe you can upload the files on the issue related to write memo files #40