Equivalent of "fread" C function in Java

N

news.amnet.net.au

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top