Changeset 3901


Ignore:
Timestamp:
04/08/08 15:38:30 (12 years ago)
Author:
melissa
Message:

Added isThisType(RandomAccessStream) and updated other isThisType methods to use it when appropriate.

File:
1 edited

Legend:

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

    r3854 r3901  
    5151  public ImprovisionTiffReader() { 
    5252    super("Improvision TIFF", new String[] {"tif", "tiff"}); 
    53     blockCheckLen = 524288; 
    5453    suffixSufficient = false; 
    5554  } 
     
    6059  public boolean isThisType(byte[] block) { 
    6160    try { 
    62       RandomAccessStream ras = new RandomAccessStream(block); 
    63       Hashtable ifd = TiffTools.getFirstIFD(ras); 
    64       ras.close(); 
    65       if (ifd == null) return false; 
    66  
    67       String comment = TiffTools.getComment(ifd); 
    68       return comment != null && comment.indexOf("Improvision") != -1; 
    69     } 
    70     catch (IOException exc) { 
    71       if (debug) LogTools.trace(exc); 
    72     } 
    73     catch (ArrayIndexOutOfBoundsException exc) { 
    74       if (debug) LogTools.trace(exc); 
     61      RandomAccessStream stream = new RandomAccessStream(block); 
     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 
     72  /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ 
     73  public boolean isThisType(String name, boolean open) { 
     74    if (!open) return false; 
     75 
     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); 
    7584    } 
    7685    return false; 
     
    224233  } 
    225234 
     235  // -- Helper methods -- 
     236 
     237  private boolean isThisType(RandomAccessStream stream) throws IOException { 
     238    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     239    String comment = TiffTools.getComment(ifd); 
     240    if (comment == null) return false; 
     241    return comment.indexOf("Improvision") != -1; 
     242  } 
     243 
    226244} 
Note: See TracChangeset for help on using the changeset viewer.