title: How to read and parse a big STL file?
body: <p>How to read and parse a big STL file? I write a application to view the 3D STL file. The 3D STL file can be binary or ACSII. I need to read the STL file from sdcard and then parse the data to render using OpenGL. But I have the "out of memory" when the 3D STL is big. How to fix this problem. I use two arraylists to store the facet formal and vertex.</p>
  
  <p>The below code is implemented "read and parse the binary STL file":</p>
  
  <pre><code>private void processBinarySTL(){
      Thread processThread =new Thread(new Runnable() {
  
          @Override
          public void run() {
              // TODO Auto-generated method stub
              File file=new File("/mnt/sdcard/3D/Lost_Pleiade_Ready.stl");
  
              InputStream inputStream = null;
              try {
                  inputStream = mContext.getContentResolver().openInputStream(Uri.fromFile(file));
                  int n = 0;
                  byte[] buffer = new byte[4];
                  inputStream.skip(80);
                  n = inputStream.read(buffer);
                  System.out.println("n=="+n);
                  int size=getIntWithLittleEndian(buffer,0);
                  System.out.println("size=="+size);
                  List&lt;Float&gt; normalList=new ArrayList&lt;Float&gt;();
                  List&lt;Float&gt; vertexList = new ArrayList&lt;Float&gt;();
                  for (int i = 0; i &lt; size; i++) {
                      //normal
                      for(int k=0;k&lt;3;k++){
                      inputStream.read(buffer);
                      normalList.add(Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0)));
                      }
  
  
                      for(int j=0;j&lt;3;j++){
                      inputStream.read(buffer);
                      float x = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0));
                      inputStream.read(buffer);
                      float y = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0));
                      inputStream.read(buffer);
                      float z = Float.intBitsToFloat(getIntWithLittleEndian(buffer, 0));
                      adjustMaxMin(x, y, z);
                      vertexList.add(x);
                      vertexList.add(y);
                      vertexList.add(z);
                      }
                      inputStream.skip(2);
  
                  }
                  System.out.println("normalList size== "+normalList.size());
                  System.out.println("vertexList size== "+vertexList.size());
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }finally{
                  if(inputStream!=null)
                      try {
                          inputStream.close();
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
              }
  
          }
      });
      processThread.start();
  }
  </code></pre>