private void readASCII(final BufferedReader buffer) throws NumberFormatException, IOException {
  RajLog.i("StlPaser: Reading ASCII");
  final List<Float> vertices=new ArrayList<Float>();
  final List<Float> normals=new ArrayList<Float>();
  final float[] tempNorms=new float[3];
  int nextOffset, prevOffset, i, insert;
  String line;
  line=buffer.readLine();
  while ((line=buffer.readLine()) != null) {
    if (line.contains("facet normal ")) {
      nextOffset=line.lastIndexOf(" ");
      tempNorms[2]=Float.parseFloat(line.substring(nextOffset + 1));
      prevOffset=nextOffset;
      nextOffset=line.lastIndexOf(" ",prevOffset - 1);
      tempNorms[1]=Float.parseFloat(line.substring(nextOffset + 1,prevOffset));
      prevOffset=nextOffset;
      nextOffset=line.lastIndexOf(" ",prevOffset - 1);
      tempNorms[0]=Float.parseFloat(line.substring(nextOffset + 1,prevOffset));
      for (i=0; i < 3; i++) {
        normals.add(tempNorms[0]);
        normals.add(tempNorms[1]);
        normals.add(tempNorms[2]);
      }
    }
 else     if (line.contains("vertex ")) {
      insert=vertices.size();
      nextOffset=line.lastIndexOf(" ");
      vertices.add(Float.parseFloat(line.substring(nextOffset + 1)));
      prevOffset=nextOffset;
      nextOffset=line.lastIndexOf(" ",prevOffset - 1);
      vertices.add(insert,Float.parseFloat(line.substring(nextOffset + 1,prevOffset)));
      prevOffset=nextOffset;
      nextOffset=line.lastIndexOf(" ",prevOffset - 1);
      vertices.add(insert,Float.parseFloat(line.substring(nextOffset + 1,prevOffset)));
    }
  }
  float[] verticesArr=new float[vertices.size()];
  float[] normalsArr=new float[normals.size()];
  for (i=0; i < verticesArr.length; i++) {
    verticesArr[i]=vertices.get(i);
    normalsArr[i]=normals.get(i);
  }
  vertices.clear();
  normals.clear();
  int[] indicesArr=new int[verticesArr.length / 3];
  for (i=0; i < indicesArr.length; i++)   indicesArr[i]=i;
  mRootObject.setData(verticesArr,normalsArr,null,null,indicesArr,false);
}

private void readASCII ( final BufferedReader buffer ) throws NumberFormatException , IOException { RajLog . i ( "StlPaser: Reading ASCII" ) ; final List < Float > vertices = new ArrayList < Float > ( ) ; final List < Float > normals = new ArrayList < Float > ( ) ; final float [ ] tempNorms = new float [ 3 ] ; int nextOffset , prevOffset , i , insert ; String line ; line = buffer . readLine ( ) ; while ( ( line = buffer . readLine ( ) ) != null ) { if ( line . contains ( "facet normal " ) ) { nextOffset = line . lastIndexOf ( " " ) ; tempNorms [ 2 ] = Float . parseFloat ( line . substring ( nextOffset + 1 ) ) ; prevOffset = nextOffset ; nextOffset = line . lastIndexOf ( " " , prevOffset - 1 ) ; tempNorms [ 1 ] = Float . parseFloat ( line . substring ( nextOffset + 1 , prevOffset ) ) ; prevOffset = nextOffset ; nextOffset = line . lastIndexOf ( " " , prevOffset - 1 ) ; tempNorms [ 0 ] = Float . parseFloat ( line . substring ( nextOffset + 1 , prevOffset ) ) ; for ( i = 0 ; i < 3 ; i ++ ) { normals . add ( tempNorms [ 0 ] ) ; normals . add ( tempNorms [ 1 ] ) ; normals . add ( tempNorms [ 2 ] ) ; } } else if ( line . contains ( "vertex " ) ) { insert = vertices . size ( ) ; nextOffset = line . lastIndexOf ( " " ) ; vertices . add ( Float . parseFloat ( line . substring ( nextOffset + 1 ) ) ) ; prevOffset = nextOffset ; nextOffset = line . lastIndexOf ( " " , prevOffset - 1 ) ; vertices . add ( insert , Float . parseFloat ( line . substring ( nextOffset + 1 , prevOffset ) ) ) ; prevOffset = nextOffset ; nextOffset = line . lastIndexOf ( " " , prevOffset - 1 ) ; vertices . add ( insert , Float . parseFloat ( line . substring ( nextOffset + 1 , prevOffset ) ) ) ; } } float [ ] verticesArr = new float [ vertices . size ( ) ] ; float [ ] normalsArr = new float [ normals . size ( ) ] ; for ( i = 0 ; i < verticesArr . length ; i ++ ) { verticesArr [ i ] = vertices . get ( i ) ; normalsArr [ i ] = normals . get ( i ) ; } vertices . clear ( ) ; normals . clear ( ) ; int [ ] indicesArr = new int [ verticesArr . length / 3 ] ; for ( i = 0 ; i < indicesArr . length ; i ++ ) indicesArr [ i ] = i ; mRootObject . setData ( verticesArr , normalsArr , null , null , indicesArr , false ) ; }
read stream as ascii . while this works well , ascii is painfully slow on mobile devices due to tight memory constraints and lower processing power compared to desktops . it is advisable to use the binary parser whenever possible .
