Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Equivalent of "fread" C function in Java

Reply
Thread Tools

Equivalent of "fread" C function in Java

 
 
news.amnet.net.au
Guest
Posts: n/a
 
      01-15-2004
Hi

I have an Oracle parser which works well on String values but which I would
like to use also to read in binary files. The aim is extract particular
bytes (based on a known offset, up to a point further on), then converting
the selected bytes to sensible string values.

I know there is a function in C called "fread" which is able to sort binary
content, allowing for big and little endian swaps and also able to make
sense of mantissa and exponent for floating numbers.

Is there an equivalent function in Java, and if so, how would one use it?

At the moment, my parser gets an html input stream, like this:

<snip>
String documentContent = "";
BufferedReader dataStream =
new BufferedReader(htmlStream);

for (String line = dataStream.readLine();line != null;
line = dataStream.readLine())
{
documentContent = documentContent + line + "\n";
}

<snip>

.... so I end up with all the data in a String object called documentContent.
I am actually not sure if this is appropriate for capturing binary data.

Anyway, I would like to have a function where I read in the binary data, but
then extract the data back to strings, depending on the offset I specify. I
would need something similar to fread i.e. something which not only converts
bytes to characters but also tranlates the characters back to sensible unit
strings.

Can anyone help me with a code example, something like a function which is
called up (so I can also use it as a bean), e.g:

String mySensibleString = parseByte(documentContent);

and then the function itself:

private String parseByte (String parseString){

....something like the C function "fread" here with the ability to read
bytecode at an offset point up to a point further along
then a conversion to a string value, which then can be returned.

return resultString;

}

Any help will be greatly appreciated.

Thanks very much

Hugo




 
Reply With Quote
 
 
 
 
Anthony Borla
Guest
Posts: n/a
 
      01-15-2004

"news.amnet.net.au" <(E-Mail Removed)> wrote in message
news:newscache$6rvirh$u7a$(E-Mail Removed).. .
> Hi
>
> I have an Oracle parser which works well on String values
> but which I would like to use also to read in binary files.
> The aim is extract particular bytes (based on a known
> offset, up to a point further on), then converting
> the selected bytes to sensible string values.
>
> I know there is a function in C called "fread" which is able
> to sort binary content, allowing for big and little endian
> swaps and also able to make sense of mantissa and exponent
> for floating numbers.
>
> Is there an equivalent function in Java, and if so, how
> would one use it?
>


Take a look at the documentation for:

java.nio.ByteBuffer;

It sounds like the type of functionality you require. Google for related
tutorials / examples.

I hope this helps.

Anthony Borla


 
Reply With Quote
 
 
 
 
ak
Guest
Posts: n/a
 
      01-15-2004
> I know there is a function in C called "fread" which is able to sort
binary
> content, allowing for big and little endian swaps and also able to make
> sense of mantissa and exponent for floating numbers.


DataInputStream#readLine(); - however no big/little endian swapping
performed.

I have written UnifiedIO which can read big/little endian - currently it is
a part of ImageroReader,
later it will be available as standalone package. see
http://reader.imagero.com for more info.

____________

http://reader.imagero.com the best java image reader.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is an equivalent TimeSerial() function of VBscript in the Java Script?? divya Javascript 7 09-25-2006 05:14 AM
Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function ycoci0@gmail.com Python 3 06-12-2006 07:45 AM
Java equivalent to VB 'string' function (create string with repeatingcharacters)? ohaya Java 5 10-19-2005 02:41 AM
Equivalent of "fread" C function in Java news.amnet.net.au Perl Misc 1 01-15-2004 09:08 AM
java equivalent function of c atoi() function lonelyplanet999 Java 8 11-03-2003 01:07 AM



Advertisments