how to read long[] from data input stream ?

Discussion in 'Java' started by Jimmy Zhang, Oct 31, 2003.

  1. Jimmy Zhang

    Jimmy Zhang Guest

    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
    Jimmy Zhang, Oct 31, 2003
    #1
    1. Advertising

  2. 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
    Marco Schmidt, Oct 31, 2003
    #2
    1. Advertising

  3. Jimmy Zhang

    ak Guest

    you could also at first read data in byte array and then convert bytes in
    longs


    "Jimmy Zhang" <> 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
    >
    >
    ak, Oct 31, 2003
    #3
  4. Jimmy Zhang

    Roedy Green Guest

    On Fri, 31 Oct 2003 09:22:27 GMT, "Jimmy Zhang" <>
    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.
    Roedy Green, Oct 31, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    659
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,178
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Replies:
    9
    Views:
    614
    Alex Buell
    Apr 27, 2006
  4. Kashif Ur Rehman
    Replies:
    2
    Views:
    855
    Tom Hawtin
    May 17, 2007
  5. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    461
    santosh
    Jul 24, 2007
Loading...

Share This Page