Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataInputStream/ByteArrayInputStream/Binary Data and Encoding/Decoding

Muhammad Asif
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing a strange sort of issue.

I have some binary data (consisting of a set of floating point numbers), which i am encoding using Base64.encode to convert to a Character.

I put the data in some temporary storage(DB), and getting it back for processing.

When i get the string back, i decode it back using Base64.decode, and get a byteArray.

In order to read the float data, i am using

DataInputStream dis = DataInputStream(ByteArrayInputStream(byteArray);

while ( (myfloat = dis.readFloat()) != -1){
// Built myfloat list

The data that i am getting using the above code, and the data which i get using directly reading from the file, is totally different.
DataInputStream dis1 = new DataInputStream(new File(fileName));

while ( (myfloat2 = dis1.readFloat()) != -1){
//build myfloat2 list

The data in myfloat and myfloat2 list is entirely different.

Am i doing something really stupid here ?

P.S. I haven't touched Java for last 6 years, so kind of rusty at the moment! I will get there slowly but surely

I agree. Here's the link:
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic