Article View: borland.public.jbuilder.java.api
Article #88Re: Problem reading a file generated by a Delphi application
From: Kevin Dean [TeamB]
Date: Tue, 05 Apr 2005 15:19
Date: Tue, 05 Apr 2005 15:19
43 lines
2846 bytes
2846 bytes
Ronaldo wrote:
> Because the application developed in Delphi uses a format proprietor
> to record the header, and my problem is exactly to read this header,
> the compacted data I am not having problem with them, it is enough to
> ignore the data of the header. But I need to read that header with
> Java to manipulate the data that were migrated of a legated system,
> that they are not compacted, but they were recorded with that header.
> A solution not very elegant it would be to write a .SO in Kylix that
> makes that work, but I would like to implement a solution purely Java.
Reading binary files is always tricky. The first thing you should do
is determine whether or not you are in the right place in the file.
After reading each field with Delphi, print out the current file
position. Do the same in Java. If the output differs, then you're
reading the wrong number of bytes.
Once you have the file positions lined up, then output the fields
themselves in Delphi and in Java. Typically your integers will be
different, and that can be resolved in Java by reading one byte at a
time. Assuming that the number stored is a 32-bit integer:
int result = 0;
for (int index = 0; index < 4; index++) {
// Bytes are high-order first, so shift the result by one byte.
result <<= 8;
// Add (through bitwise OR) the next byte.
result |= s.readByte();
}
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<xn0e0myyh7wsvg000-kdean@www.teamb.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<42515016@newsgroups.borland.com> <xn0e0lmi7194rjq005-kdean@www.teamb.com> <4252780e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1089d0,e0d9b07a5e544a79
X-Google-Attributes: gid1089d0,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Kevin Dean [TeamB]" <NkOdSePaAnM@datadevelopment.com>
Subject: Re: Problem reading a file generated by a Delphi application
Newsgroups: borland.public.jbuilder.java.api
References: <42515016@newsgroups.borland.com> <xn0e0lmi7194rjq005-kdean@www.teamb.com> <4252780e$1@newsgroups.borland.com>
Organization: Dolphin Data Development Ltd.
User-Agent: XanaNews/1.17.3.1
X-Face: ":yn4zt^A_dn>6~{YJmu^B\'4w)e:apPM\VC=Dvf&*tASxX9|BYczkFd$xr.$vNSZ[3Uobr
p]c4\+\l){!WQI.$]veP({HLd;CDYH?iN
Message-ID: <xn0e0myyh7wsvg000-kdean@www.teamb.com>
X-Ref: newsgroups.borland.com ~XNS:0000014F
NNTP-Posting-Host: 24.57.153.235
Date: 5 Apr 2005 07:19:49 -0800
X-Trace: newsgroups.borland.com 1112710789 24.57.153.235 (5 Apr 2005 07:19:49 -0800)
Lines: 43
X-Authenticated-User: kdean
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail