Changeset 4092


Ignore:
Timestamp:
06/02/08 16:28:28 (12 years ago)
Author:
curtis
Message:

Clean up TIFF-based isThisType implementations:

  • Fixes miscellaneous debugging exceptions
  • Paves the way for an eventual isThisType(RandomAccessStream) method
Location:
trunk/loci/formats
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/RABytes.java

    r4048 r4092  
    9191  public int read(byte[] b, int off, int len) throws IOException { 
    9292    if (fp + len > array.length) len = array.length - fp; 
    93     System.arraycopy(array, fp, b, off, len); 
     93    if (len > 0) System.arraycopy(array, fp, b, off, len); 
    9494    fp += len; 
    9595    return len; 
  • trunk/loci/formats/in/FluoviewReader.java

    r4048 r4092  
    8181  // -- IFormatReader API methods -- 
    8282 
     83  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ 
     84  public boolean isThisType(String name, boolean open) { 
     85    if (!open) return false; 
     86    try { 
     87      RandomAccessStream stream = new RandomAccessStream(name); 
     88      boolean isThisType = isThisType(stream); 
     89      stream.close(); 
     90      return isThisType; 
     91    } 
     92    catch (IOException e) { 
     93      if (debug) trace(e); 
     94    } 
     95    return false; 
     96  } 
     97 
    8398  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    8499  public boolean isThisType(byte[] block) { 
    85100    try { 
    86101      RandomAccessStream stream = new RandomAccessStream(block); 
    87       Hashtable ifd = TiffTools.getFirstIFD(stream); 
     102      boolean isThisType = isThisType(stream); 
    88103      stream.close(); 
    89       String com = TiffTools.getComment(ifd); 
    90       if (com == null) com = ""; 
    91       return com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 && 
    92         ifd.containsKey(new Integer(MMHEADER)) || 
    93         ifd.containsKey(new Integer(MMSTAMP)); 
     104      return isThisType; 
    94105    } 
    95106    catch (IOException e) { 
    96       if (debug) LogTools.trace(e); 
    97     } 
    98     catch (ArrayIndexOutOfBoundsException e) { 
    99       if (debug) LogTools.trace(e); 
     107      if (debug) trace(e); 
    100108    } 
    101109    return false; 
     
    432440  } 
    433441 
     442  // -- Helper methods -- 
     443 
     444  private boolean isThisType(RandomAccessStream stream) throws IOException { 
     445    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     446    String com = TiffTools.getComment(ifd); 
     447    if (com == null) com = ""; 
     448    return com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 && 
     449      ifd.containsKey(new Integer(MMHEADER)) || 
     450      ifd.containsKey(new Integer(MMSTAMP)); 
     451  } 
     452 
    434453} 
  • trunk/loci/formats/in/ImprovisionTiffReader.java

    r4048 r4092  
    5555  // -- IFormatReader API methods -- 
    5656 
     57  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ 
     58  public boolean isThisType(String name, boolean open) { 
     59    if (!open) return false; 
     60    try { 
     61      RandomAccessStream stream = new RandomAccessStream(name); 
     62      boolean isThisType = isThisType(stream); 
     63      stream.close(); 
     64      return isThisType; 
     65    } 
     66    catch (IOException e) { 
     67      if (debug) trace(e); 
     68    } 
     69    return false; 
     70  } 
     71 
    5772  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    5873  public boolean isThisType(byte[] block) { 
    5974    try { 
    6075      RandomAccessStream stream = new RandomAccessStream(block); 
    61       boolean isThisType = isThisType(stream); 
    62       stream.close(); 
    63       return isThisType; 
    64     } 
    65     catch (IOException e) { 
    66       if (debug) trace(e); 
    67     } 
    68     return false; 
    69   } 
    70  
    71   /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ 
    72   public boolean isThisType(String name, boolean open) { 
    73     if (!open) return false; 
    74  
    75     try { 
    76       RandomAccessStream stream = new RandomAccessStream(name); 
    7776      boolean isThisType = isThisType(stream); 
    7877      stream.close(); 
  • trunk/loci/formats/in/MetamorphTiffReader.java

    r4048 r4092  
    7171  // -- IFormatReader API methods -- 
    7272 
     73  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ 
     74  public boolean isThisType(String name, boolean open) { 
     75    if (!open) return false; 
     76    try { 
     77      RandomAccessStream stream = new RandomAccessStream(name); 
     78      boolean isThisType = isThisType(stream); 
     79      stream.close(); 
     80      return isThisType; 
     81    } 
     82    catch (IOException e) { 
     83      if (debug) trace(e); 
     84    } 
     85    return false; 
     86  } 
     87 
    7388  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    7489  public boolean isThisType(byte[] block) { 
    7590    try { 
    7691      RandomAccessStream stream = new RandomAccessStream(block); 
    77       String comment = TiffTools.getComment(TiffTools.getFirstIFD(stream)); 
     92      boolean isThisType = isThisType(stream); 
    7893      stream.close(); 
    79       return comment != null && comment.trim().startsWith("<MetaData>"); 
     94      return isThisType; 
    8095    } 
    8196    catch (IOException e) { 
    82       if (debug) LogTools.trace(e); 
    83     } 
    84     catch (ArrayIndexOutOfBoundsException e) { 
    85       if (debug) LogTools.trace(e); 
     97      if (debug) trace(e); 
    8698    } 
    8799    return false; 
     
    204216  } 
    205217 
     218  // -- Helper methods -- 
     219 
     220  private boolean isThisType(RandomAccessStream stream) throws IOException { 
     221    String comment = TiffTools.getComment(TiffTools.getFirstIFD(stream)); 
     222    return comment != null && comment.trim().startsWith("<MetaData>"); 
     223  } 
     224 
    206225} 
  • trunk/loci/formats/in/NikonReader.java

    r4048 r4092  
    130130    // extension is sufficient as long as it is NEF 
    131131    if (checkSuffix(name, NEF_SUFFIX)) return true; 
    132     return super.isThisType(name, open); 
     132 
     133    if (!open) return false; 
     134    try { 
     135      RandomAccessStream stream = new RandomAccessStream(name); 
     136      boolean isThisType = isThisType(stream); 
     137      stream.close(); 
     138      return isThisType; 
     139    } 
     140    catch (IOException e) { 
     141      if (debug) trace(e); 
     142    } 
     143    return false; 
    133144  } 
    134145 
     
    137148    try { 
    138149      RandomAccessStream stream = new RandomAccessStream(block); 
    139       Hashtable ifd = TiffTools.getFirstIFD(stream); 
    140       return ifd != null && ifd.containsKey(new Integer(TIFF_EPS_STANDARD)); 
     150      boolean isThisType = isThisType(stream); 
     151      stream.close(); 
     152      return isThisType; 
    141153    } 
    142154    catch (IOException e) { 
    143       if (debug) LogTools.trace(e); 
    144     } 
    145     catch (ArrayIndexOutOfBoundsException e) { 
    146       if (debug) LogTools.trace(e); 
     155      if (debug) trace(e); 
    147156    } 
    148157    return false; 
     
    391400  } 
    392401 
     402  private boolean isThisType(RandomAccessStream stream) throws IOException { 
     403    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     404    return ifd != null && ifd.containsKey(new Integer(TIFF_EPS_STANDARD)); 
     405  } 
     406 
    393407} 
Note: See TracChangeset for help on using the changeset viewer.