Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2003

Tip: Looking for answers? Try searching our database.

how to read long[] from data input stream ?

Thread view: 
Jimmy Zhang - 31 Oct 2003 10:22 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.