Which class is better for reading binary data?

Discussion in 'Java' started by Royan, Apr 13, 2008.

  1. Royan

    Royan Guest

    Recently I have faced a problem of choosing a proper class from
    java.io package (my goal is to use standard java.io package). So I had
    to find an alias of BufferedReader but designed specifically for
    reading raw binary data. I wonder what could you advice me on that?
     
    Royan, Apr 13, 2008
    #1
    1. Advertising

  2. Royan

    Arne Vajhøj Guest

    Royan wrote:
    > Recently I have faced a problem of choosing a proper class from
    > java.io package (my goal is to use standard java.io package). So I had
    > to find an alias of BufferedReader but designed specifically for
    > reading raw binary data. I wonder what could you advice me on that?


    The class for reading binary data is DataInputStream (any InputStream
    are OK for reading bytes, but if you need to read other simple data
    types then DataInputStream is it).

    BufferedReader are for reading lines of text.

    Arne
     
    Arne Vajhøj, Apr 13, 2008
    #2
    1. Advertising

  3. Royan

    Guest

    On Apr 13, 9:12 am, Royan <> wrote:
    > Recently I have faced a problem of choosing a proper class from
    > java.io package (my goal is to use standard java.io package). So I had
    > to find an alias of BufferedReader but designed specifically for
    > reading raw binary data. I wonder what could you advice me on that?


    Don't use BufferedReader (I meand Reader) because it converts bytes
    from local stream to unicode characters and so can't be used for raw
    data.

    It's not clear what you try to achieve bit it it looks like yo need
    buffer for speed (BufferedInputStream) and raw data access
    (DataInputStream). Java is wonderful language and it can combine and
    create stream exactly what you need. So, based on what I think it
    would be like this:

    new DataInputStream(new BufferedInputStream(new
    FileInputStream("abc.raw")))

    So you will have speed of buffer and data conversion ability of data
    stream to read raw data.
    And, of course, you always can use "low" level of any stream to read
    real raw data byte by byte or all of them in one buffer.

    Alex.
    http://www.myjavaserver.com/~alexfromohio/
     
    , Apr 13, 2008
    #3
  4. Royan

    Royan Guest

    On 13 ÁÐÒ, 20:16, wrote:
    > On Apr 13, 9:12 am, Royan <> wrote:
    >
    > > Recently I have faced a problem of choosing a proper class from
    > > java.io package (my goal is to use standard java.io package). So I had
    > > to find an alias of BufferedReader but designed specifically for
    > > reading raw binary data. I wonder what could you advice me on that?

    >
    > Don't use BufferedReader (I meand Reader) because it converts bytes
    > from local stream to unicode characters and so can't be used for raw
    > data.
    >
    > It's not clear what you try to achieve bit it it looks like yo need
    > buffer for speed (BufferedInputStream) and raw data access
    > (DataInputStream). Java is wonderful language and it can combine and
    > create stream exactly what you need. So, based on what I think it
    > would be like this:
    >
    > new DataInputStream(new BufferedInputStream(new
    > FileInputStream("abc.raw")))
    >
    > So you will have speed of buffer and data conversion ability of data
    > stream to read raw data.
    > And, of course, you always can use "low" level of any stream to read
    > real raw data byte by byte or all of them in one buffer.
    >
    > Alex.http://www.myjavaserver.com/~alexfromohio/


    Arne and Lew thanks!
    Alex, I think you have answered my question. I'll use a combination of
    DataInputStream, BufferedInputStream and FileInputStream just as
    you've suggested.
     
    Royan, Apr 13, 2008
    #4
  5. Royan

    Roedy Green Guest

    On Sun, 13 Apr 2008 06:12:12 -0700 (PDT), Royan <>
    wrote, quoted or indirectly quoted someone who said :

    >So I had
    >to find an alias of BufferedReader but designed specifically for
    >reading raw binary data. I wonder what could you advice me on that?


    see http://mindprod.com/applet/fileio.html
    to generate you sample code. Use either a DataStream or an
    ObjectStream.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Apr 14, 2008
    #5
  6. Royan

    Roedy Green Guest

    On Sun, 13 Apr 2008 06:12:12 -0700 (PDT), Royan <>
    wrote, quoted or indirectly quoted someone who said :

    >Recently I have faced a problem of choosing a proper class from
    >java.io package (my goal is to use standard java.io package). So I had
    >to find an alias of BufferedReader but designed specifically for
    >reading raw binary data. I wonder what could you advice me on that?


    Your choices are DataInputStream for big-endian
    LEDataInputStream for little-endian
    and possibly nio for low level high performance.

    see http://mindprod.com/applet/fileio.html
    for sample code for DataInputStream and LEDataInputStream
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Apr 24, 2008
    #6
    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. Luqman
    Replies:
    0
    Views:
    367
    Luqman
    Apr 3, 2006
  2. George2
    Replies:
    0
    Views:
    329
    George2
    Apr 12, 2008
  3. afshar
    Replies:
    2
    Views:
    404
    Peter Flynn
    Nov 1, 2008
  4. John Goche
    Replies:
    9
    Views:
    696
    Arne Vajhøj
    Dec 3, 2011
  5. ksachdeva
    Replies:
    0
    Views:
    82
    ksachdeva
    Apr 9, 2007
Loading...

Share This Page