• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binary(Little-endian) file reading problem in applet

 
Greenhorn
Posts: 2
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm reading a STL binary file using the following code:

public void LoadSTLBinary(DataInputStream datainputstream) throws Exception {

datainputstream.read(new byte[80]);
int iTriaCount = readInt(datainputstream);
System.out.println("Tiangles_bitwise : " + iTriaCount);
triangles = new Triangle[iTriaCount];
......
......
datainputstream.close();
}

//Needed since binary file is in little endian format
public int readInt(DataInputStream datainputstream) throws IOException {
int i = datainputstream.readInt();
return ((i & 0xff) << 24) + ((i & 0xff00) << 8) + ((i & 0xff0000) >> 8) + (i >> 24 & 0xff);
}


Note: unable to attach Sample STL binary file. please go through http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL

When i run the code as a java application, the system.out.println outputs - "Tiangles_bitwise : 4"
but when called in a applet , the system.out.println outputs - "Tiangles_bitwise : 1146060800"

Any help highly appreciated.

Regards,
Rajan_M
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For one, the DataInputStream is used to read files generated through DataOutputStream, not binary files created in any other way. Try InputStream.read().
 
Rajan Manoharan
Greenhorn
Posts: 2
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Carey,

I tried with BufferedInputStream but the problem remains the same.
i'm opening the file within applet like this:

InputStream instream = (new URL(filepath)).openConnection().getInputStream();
BufferedInputStream datainputstream = new BufferedInputStream( instream );

Note: i've a sample stl binary file but i'm not able to attach it.

Regards,
Rajan.M
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajan Manoharan wrote:


I have tried that code with a simple example, and that part works. That means that if you're not getting the results you expect the problem is somewhere else. So please show us the code that's reading the STL file in both the application and the applet.
 
reply
    Bookmark Topic Watch Topic
  • New Topic