Changeset 3879


Ignore:
Timestamp:
04/03/08 13:54:32 (12 years ago)
Author:
melissa
Message:

Fixed OOMEs when reading XML string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/in/ND2Reader.java

    r3875 r3879  
    634634      in.seek(off + 5); 
    635635      String xml = in.readString((int) (in.length() - in.getFilePointer())); 
    636  
    637       // strip out binary data at the end - this is irrelevant for our purposes 
    638       xml = "\n" + xml.substring(0, xml.lastIndexOf("</MetadataSeq>") + 14); 
    639  
    640       // strip out all comments 
    641       xml = xml.replaceAll("<!--.*-->", ""); 
    642       xml = xml.replaceAll("\n.*xml", ""); 
     636      StringTokenizer st = new StringTokenizer(xml, "\n"); 
     637      StringBuffer sb = new StringBuffer(); 
    643638 
    644639      // stored XML doesn't have a root node - add one, so that we can parse 
    645640      // using SAX 
    646641 
    647       xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><NIKON>" + xml + 
    648         "</NIKON>"; 
     642      sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><NIKON>"); 
     643 
     644      while (st.hasMoreTokens()) { 
     645        String token = st.nextToken(); 
     646        token = token.replaceAll("<!--.*-->", ""); 
     647        token = token.replaceAll(".*xml", "").trim(); 
     648        token = token.substring(0, token.lastIndexOf(">") + 1); 
     649        if (token.startsWith("<")) sb.append(token); 
     650      } 
     651      sb.append("</NIKON>"); 
     652      xml = sb.toString(); 
    649653 
    650654      ND2Handler handler = new ND2Handler(); 
     
    683687    status("Populating metadata"); 
    684688    if (core.imageCount[0] == 0) { 
    685       core.sizeZ[0] = zs.size() == 0 ? 1 : zs.size(); 
     689      core.sizeZ[0] = zs.size() == 0 ? vs.size() : zs.size(); 
    686690      core.sizeT[0] = ts.size() == 0 ? 1 : ts.size(); 
    687691      core.sizeC[0] = (vs.size() + 1) / (core.sizeT[0] * core.sizeZ[0]); 
     
    897901      else if (qName.startsWith("TextInfoItem")) { 
    898902        String value = attributes.getValue("value"); 
    899         if (value.indexOf("Dimensions") != -1) { 
     903        if (value != null && value.indexOf("Dimensions") != -1) { 
    900904          int ndx = value.indexOf("Dimensions"); 
    901905          value = value.substring(ndx + 11, value.indexOf("\n", ndx)).trim(); 
     
    955959      gain = value; 
    956960    } 
    957     else if (key.endsWith("dLampVoltage value")) 
    958     { 
     961    else if (key.endsWith("dLampVoltage value")) { 
    959962      voltage = value; 
    960963    } 
    961     else if (key.endsWith("dObjectiveMag value")) 
    962     { 
     964    else if (key.endsWith("dObjectiveMag value")) { 
    963965      mag = value; 
    964966    } 
    965     else if (key.endsWith("dObjectiveNA value")) 
    966     { 
     967    else if (key.endsWith("dObjectiveNA value")) { 
    967968      na = value; 
    968969    } 
Note: See TracChangeset for help on using the changeset viewer.