I am looking for ways to read data into a long array from data input stream
directly. I feel that wrapping Fileinputstream
using DataInputStream filter is kinda inefficient, if there is a way to let
the datainputstream to arrange 8 bytes into a long directly, it wouild be
really nice.
Any suggestions on how to realize this?
Thanks,
Jimmy
Marco Schmidt - 31 Oct 2003 10:50 GMT
Jimmy Zhang:
>I am looking for ways to read data into a long array from data input stream
>directly. I feel that wrapping Fileinputstream
>using DataInputStream filter is kinda inefficient, if there is a way to let
>the datainputstream to arrange 8 bytes into a long directly, it wouild be
>really nice.
Why do you think it's not efficient? It's a normal approach in Java to
wrap I/O objects into other I/O objects. Just try the
DataInputStream/FileInputStream combination. However, make sure you
also include a buffering stream:
DataInput in = new DataInputStream(new BufferedInputStream(new
FileInputStream("file.dat")));
long l1 = in.readLong();
long l2 = in.readLong();
...
Regards,
Marco

Signature
Please reply in the newsgroup, not by email!
Java programming tips: http://jiu.sourceforge.net/javatips.html
Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
ak - 31 Oct 2003 14:44 GMT
you could also at first read data in byte array and then convert bytes in
longs
> I am looking for ways to read data into a long array from data input stream
> directly. I feel that wrapping Fileinputstream
[quoted text clipped - 6 lines]
> Thanks,
> Jimmy
Roedy Green - 31 Oct 2003 20:28 GMT
>using DataInputStream filter is kinda inefficient, if there is a way to let
>the datainputstream to arrange 8 bytes into a long directly,
Have a look at the source code for DataInputStream to see how it does
it. If you can't find that look at the code for the little-endian
version at http://mindprod.com/products.html#LEADATASTREAM
For sample code for packing and unpacking bytes see
http://mindprod.com/jgloss/endian.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.