Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to read long[] from data input stream ?

Reply
Thread Tools

how to read long[] from data input stream ?

 
 
Jimmy Zhang
Guest
Posts: n/a
 
      10-31-2003
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


 
Reply With Quote
 
 
 
 
Marco Schmidt
Guest
Posts: n/a
 
      10-31-2003
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
--
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
 
Reply With Quote
 
 
 
 
ak
Guest
Posts: n/a
 
      10-31-2003
you could also at first read data in byte array and then convert bytes in
longs


"Jimmy Zhang" <(E-Mail Removed)> schrieb im Newsbeitrag
news:nRpob.68283$Tr4.191729@attbi_s03...
> 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
>
>



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-31-2003
On Fri, 31 Oct 2003 09:22:27 GMT, "Jimmy Zhang" <(E-Mail Removed)>
wrote or quoted :

>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.
 
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
Conversion from Input Stream to Output Stream Kashif Ur Rehman Java 2 05-17-2007 07:50 PM
How to GET multi-word input from a *file* stream as opposed to a *console* stream? sherifffruitfly@gmail.com C++ 9 04-27-2006 04:14 PM
J2me, data input stream, Sony Ericsson's K750i, Boki Java 25 11-01-2005 05:01 PM
Read input stream of HttpUrlConnection SPG Java 1 07-26-2004 10:15 AM
Creating an object that is read from an input stream. Jason Heyes C++ 21 12-15-2003 01:07 PM



Advertisments