Changeset 4205


Ignore:
Timestamp:
07/17/08 13:58:00 (12 years ago)
Author:
melissa
Message:

Added isThisType(RandomAccessStream) to IFormatReader API. Closes #256.

Location:
trunk/loci/formats
Files:
67 edited

Legend:

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

    r4101 r4205  
    234234  public boolean isThisType(byte[] block) { 
    235235    return reader.isThisType(block); 
     236  } 
     237 
     238  /* @see IFormatReader#isThisType(RandomAccessStream) */ 
     239  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     240    return reader.isThisType(stream); 
    236241  } 
    237242 
  • trunk/loci/formats/FormatReader.java

    r4048 r4205  
    147147    try { 
    148148      RandomAccessStream ras = new RandomAccessStream(name); 
    149       long len = ras.length(); 
    150       if (len > maxLen) len = maxLen; 
    151       byte[] buf = new byte[(int) len]; 
    152       ras.readFully(buf); 
     149      boolean isThisType = isThisType(ras); 
    153150      ras.close(); 
    154       return isThisType(buf); 
     151      return isThisType; 
    155152    } 
    156153    catch (IOException exc) { 
     
    247244  } 
    248245 
     246  /* @see IFormatReader#isThisType(byte[]) */ 
     247  public boolean isThisType(byte[] block) { 
     248    try { 
     249      RandomAccessStream stream = new RandomAccessStream(block); 
     250      boolean isThisType = isThisType(stream); 
     251      stream.close(); 
     252      return isThisType; 
     253    } 
     254    catch (IOException e) { 
     255      if (debug) LogTools.trace(e); 
     256    } 
     257    return false; 
     258  } 
     259 
    249260  /* @see IFormatReader#getImageCount() */ 
    250261  public int getImageCount() { 
  • trunk/loci/formats/FormatTools.java

    r4194 r4205  
    2323 
    2424package loci.formats; 
     25 
     26import java.io.IOException; 
    2527 
    2628/** 
     
    501503  } 
    502504 
     505  public static boolean validStream(RandomAccessStream stream, int len, 
     506    boolean littleEndian) throws IOException 
     507  { 
     508    stream.seek(0); 
     509    stream.order(littleEndian); 
     510    return stream.length() >= len; 
     511  } 
     512 
    503513  // -- Utility methods -- other 
    504514 
  • trunk/loci/formats/IFormatReader.java

    r4048 r4205  
    5858  /** Checks if the given block is a valid header for this file format. */ 
    5959  boolean isThisType(byte[] block); 
     60 
     61  /** Checks if the given stream is a valid stream for this file format. */ 
     62  boolean isThisType(RandomAccessStream stream) throws IOException; 
    6063 
    6164  /** Determines the number of images in the current file. */ 
  • trunk/loci/formats/ImageReader.java

    r4090 r4205  
    178178  } 
    179179 
     180  /* @see IFormatReader.isThisType(RandomAccessStream) */ 
     181  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     182    for (int i=0; i<readers.length; i++) { 
     183      if (readers[i].isThisType(stream)) return true; 
     184    } 
     185    return false; 
     186  } 
     187 
    180188  /* @see IFormatReader#getImageCount() */ 
    181189  public int getImageCount() { 
  • trunk/loci/formats/ReaderWrapper.java

    r4048 r4205  
    6868  } 
    6969 
     70  public boolean isThisType(RandomAccessStream stream) throws IOException{ 
     71    return reader.isThisType(stream); 
     72  } 
     73 
    7074  public void setId(String id) throws FormatException, IOException { 
    7175    reader.setId(id); 
  • trunk/loci/formats/TiffTools.java

    r4203 r4205  
    227227 
    228228  /** 
     229   * Tests the given stream to see if it represents 
     230   * a TIFF file. 
     231   */ 
     232  public static boolean isValidHeader(RandomAccessStream stream) { 
     233    try { 
     234      return checkHeader(stream) != null; 
     235    } 
     236    catch (IOException e) { 
     237      return false; 
     238    } 
     239  } 
     240 
     241  /** 
    229242   * Checks the TIFF header. 
    230243   * @return true if little-endian, 
     
    233246   */ 
    234247  public static Boolean checkHeader(byte[] block) { 
    235     if (block.length < 4) return null; 
     248    try { 
     249      RandomAccessStream s = new RandomAccessStream(block); 
     250      Boolean result = checkHeader(s); 
     251      s.close(); 
     252      return result; 
     253    } 
     254    catch (IOException e) { 
     255      return null; 
     256    } 
     257  } 
     258 
     259  /** 
     260   * Checks the TIFF header. 
     261   * @return true if little-endian, 
     262   *         false if big-endian, 
     263   *         or null if not a TIFF. 
     264   */ 
     265  public static Boolean checkHeader(RandomAccessStream stream) 
     266    throws IOException 
     267  { 
     268    if (stream.length() < 4) return null; 
    236269 
    237270    // byte order must be II or MM 
    238     boolean littleEndian = block[0] == LITTLE && block[1] == LITTLE; // II 
    239     boolean bigEndian = block[0] == BIG && block[1] == BIG; // MM 
     271    int endianOne = stream.read(); 
     272    int endianTwo = stream.read(); 
     273    boolean littleEndian = endianOne == LITTLE && endianTwo == LITTLE; // II 
     274    boolean bigEndian = endianOne == BIG && endianTwo == BIG; // MM 
    240275    if (!littleEndian && !bigEndian) return null; 
    241276 
    242277    // check magic number (42) 
    243     short magic = DataTools.bytesToShort(block, 2, littleEndian); 
     278    stream.order(littleEndian); 
     279    short magic = stream.readShort(); 
    244280    if (magic != MAGIC_NUMBER && magic != BIG_TIFF_MAGIC_NUMBER) return null; 
    245281 
     
    368404    } 
    369405    throw new UnknownTagException(); 
    370   } 
    371  
    372   /** 
    373    * Checks the TIFF header. 
    374    * @return true if little-endian, 
    375    *         false if big-endian, 
    376    *         or null if not a TIFF. 
    377    */ 
    378   public static Boolean checkHeader(RandomAccessStream in) throws IOException { 
    379     if (DEBUG) debug("getIFDs: reading IFD entries"); 
    380  
    381     // start at the beginning of the file 
    382     in.seek(0); 
    383  
    384     byte[] header = new byte[4]; 
    385     in.readFully(header); 
    386     Boolean b = checkHeader(header); 
    387     if (b != null) in.order(b.booleanValue()); 
    388     return b; 
    389406  } 
    390407 
  • trunk/loci/formats/in/APLReader.java

    r4200 r4205  
    5555  // -- IFormatReader API methods -- 
    5656 
    57   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    58   public boolean isThisType(byte[] block) { 
     57  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     58  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    5959    return false; 
    6060  } 
  • trunk/loci/formats/in/APNGReader.java

    r4200 r4205  
    7272  // -- IFormatReader API methods -- 
    7373 
    74   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    75   public boolean isThisType(byte[] block) { 
     74  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     75  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    7676    return true; 
    7777  } 
  • trunk/loci/formats/in/AVIReader.java

    r4200 r4205  
    8484  // -- IFormatReader API methods -- 
    8585 
    86   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    87   public boolean isThisType(byte[] block) { 
    88     if (block.length < blockCheckLen) return false; 
    89     return block[0] == 'R' && block[1] == 'I' && 
    90       block[2] == 'F' && block[3] == 'F'; 
     86  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     87  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     88    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     89    return stream.readString(4).equals("RIFF"); 
    9190  } 
    9291 
  • trunk/loci/formats/in/AliconaReader.java

    r4200 r4205  
    5656  // -- IFormatReader API methods -- 
    5757 
    58   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    59   public boolean isThisType(byte[] block) { 
    60     if (block.length < blockCheckLen) return false; 
    61     return (new String(block)).indexOf("Alicona") != -1; 
     58  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     59  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     60    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     61    return (stream.readString(blockCheckLen)).indexOf("Alicona") != -1; 
    6262  } 
    6363 
  • trunk/loci/formats/in/BMPReader.java

    r4200 r4205  
    7878  // -- IFormatReader API methods -- 
    7979 
    80   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    81   public boolean isThisType(byte[] block) { 
    82     if (block.length < blockCheckLen) return false; 
    83     return new String(block).startsWith("BM"); 
     80  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     81  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     82    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     83    return stream.readString(blockCheckLen).startsWith("BM"); 
    8484  } 
    8585 
  • trunk/loci/formats/in/BioRadReader.java

    r4200 r4205  
    190190    if (checkSuffix(name, PIC_SUFFIX)) return true; 
    191191    String fname = new File(name.toLowerCase()).getName(); 
    192     if (fname.equals("lse.xml") || fname.equals("data.raw")) return true; 
    193     return false; 
    194   } 
    195  
    196   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    197   public boolean isThisType(byte[] block) { 
    198     if (block.length < blockCheckLen) return false; 
    199     return DataTools.bytesToShort(block, 54, LITTLE_ENDIAN) == PIC_FILE_ID || 
    200       new String(block).startsWith("[Input Sources]"); 
     192    return fname.equals("lse.xml") || fname.equals("data.raw"); 
     193  } 
     194 
     195  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     196  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     197    if (!FormatTools.validStream(stream, blockCheckLen, LITTLE_ENDIAN)) { 
     198      return false; 
     199    } 
     200    String c = stream.readString(blockCheckLen); 
     201    stream.seek(54); 
     202    return stream.readShort() == PIC_FILE_ID || c.startsWith("[Input Sources]"); 
    201203  } 
    202204 
  • trunk/loci/formats/in/DeltavisionReader.java

    r4200 r4205  
    7878  // -- IFormatReader API methods -- 
    7979 
    80   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    81   public boolean isThisType(byte[] block) { 
     80  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     81  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    8282    return false; 
    8383  } 
  • trunk/loci/formats/in/DicomReader.java

    r4200 r4205  
    131131  } 
    132132 
    133   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    134   public boolean isThisType(byte[] block) { 
    135     if (block.length < blockCheckLen) return false; 
    136     return new String(block, 0, blockCheckLen).indexOf("DICM") >= 0; 
     133  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     134  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     135    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     136    return stream.readString(blockCheckLen).indexOf("DICM") >= 0; 
    137137  } 
    138138 
  • trunk/loci/formats/in/EPSReader.java

    r4200 r4205  
    6666  // -- IFormatReader API methods -- 
    6767 
    68   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    69   public boolean isThisType(byte[] block) { 
     68  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     69  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    7070    return false; 
    7171  } 
  • trunk/loci/formats/in/FEIReader.java

    r4200 r4205  
    5252  // -- IFormatReader API methods -- 
    5353 
    54   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    55   public boolean isThisType(byte[] block) { 
    56     return block[0] == 'X' && block[1] == 'L'; 
     54  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     55  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     56    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     57    return stream.readString(blockCheckLen).startsWith("XL"); 
    5758  } 
    5859 
  • trunk/loci/formats/in/FV1000Reader.java

    r4203 r4205  
    111111  } 
    112112 
    113   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    114   public boolean isThisType(byte[] block) { 
    115     if (block.length < blockCheckLen) return false; 
    116     String s = DataTools.stripString(new String(block)); 
     113  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     114  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     115    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     116    String s = DataTools.stripString(stream.readString(blockCheckLen)); 
    117117    return s.indexOf("FileInformation") != -1 || 
    118118      s.indexOf("Acquisition Parameters") != -1; 
  • trunk/loci/formats/in/FitsReader.java

    r4200 r4205  
    5353  // -- IFormatReader API methods -- 
    5454 
    55   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    56   public boolean isThisType(byte[] block) { 
     55  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     56  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    5757    return true; 
    5858  } 
  • trunk/loci/formats/in/FluoviewReader.java

    r4200 r4205  
    9696  } 
    9797 
    98   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    99   public boolean isThisType(byte[] block) { 
    100     try { 
    101       RandomAccessStream stream = new RandomAccessStream(block); 
    102       boolean isThisType = isThisType(stream); 
    103       stream.close(); 
    104       return isThisType; 
    105     } 
    106     catch (IOException e) { 
    107       if (debug) trace(e); 
    108     } 
    109     return false; 
     98  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     99  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     100    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     101    String com = TiffTools.getComment(ifd); 
     102    if (com == null) com = ""; 
     103    if (ifd == null) return false; 
     104    return com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 && 
     105      ifd.containsKey(new Integer(MMHEADER)) || 
     106      ifd.containsKey(new Integer(MMSTAMP)); 
    110107  } 
    111108 
     
    436433  } 
    437434 
    438   // -- Helper methods -- 
    439  
    440   private boolean isThisType(RandomAccessStream stream) throws IOException { 
    441     Hashtable ifd = TiffTools.getFirstIFD(stream); 
    442     String com = TiffTools.getComment(ifd); 
    443     if (com == null) com = ""; 
    444     if (ifd == null) return false; 
    445     return com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 && 
    446       ifd.containsKey(new Integer(MMHEADER)) || 
    447       ifd.containsKey(new Integer(MMSTAMP)); 
    448   } 
    449  
    450435} 
  • trunk/loci/formats/in/GIFReader.java

    r4200 r4205  
    109109  // -- IFormatReader API methods -- 
    110110 
    111   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    112   public boolean isThisType(byte[] block) { 
    113     if (block.length < blockCheckLen) return false; 
    114     return new String(block).startsWith("GIF"); 
     111  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     112  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     113    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     114    return stream.readString(blockCheckLen).startsWith("GIF"); 
    115115  } 
    116116 
  • trunk/loci/formats/in/GatanReader.java

    r4200 r4205  
    8484  // -- IFormatReader API methods -- 
    8585 
    86   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    87   public boolean isThisType(byte[] block) { 
    88     if (block == null || block.length < 4) return false; 
    89     return DataTools.bytesToInt(block, false) == 3; 
     86  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     87  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     88    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     89    return stream.readInt() == 3; 
    9090  } 
    9191 
  • trunk/loci/formats/in/ICSReader.java

    r4200 r4205  
    112112  // -- IFormatReader API methods -- 
    113113 
    114   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    115   public boolean isThisType(byte[] block) { 
     114  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     115  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    116116    return false; 
    117117  } 
  • trunk/loci/formats/in/IPLabReader.java

    r4200 r4205  
    6060  // -- IFormatReader API methods -- 
    6161 
    62   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    63   public boolean isThisType(byte[] block) { 
    64     if (block.length < blockCheckLen) return false; // block length too short 
    65     String s = new String(block, 0, 4); 
     62  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     63  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     64    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     65    String s = stream.readString(4); 
    6666    boolean big = s.equals("iiii"); 
    6767    boolean little = s.equals("mmmm"); 
    6868    if (!big && !little) return false; 
    69     int size = DataTools.bytesToInt(block, 4, 4, little); 
     69    stream.order(little); 
     70    int size = stream.readInt(); 
    7071    if (size != 4) return false; // first block size should be 4 
    71     int version = DataTools.bytesToInt(block, 8, 4, little); 
     72    int version = stream.readInt(); 
    7273    return version >= 0x100e; 
    7374  } 
  • trunk/loci/formats/in/IPWReader.java

    r4200 r4205  
    5555  // -- IFormatReader API methods -- 
    5656 
    57   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    58   public boolean isThisType(byte[] block) { 
    59     return block[0] == 0xd0 && block[1] == 0xcf && 
    60       block[2] == 0x11 && block[3] == 0xe0; 
     57  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     58  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     59    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     60    return stream.readInt() == 0xd0cf11e0; 
    6161  } 
    6262 
  • trunk/loci/formats/in/ImageIOReader.java

    r4200 r4205  
    5757  // -- IFormatReader API methods -- 
    5858 
    59   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    60   public boolean isThisType(byte[] block) { return false; } 
     59  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     60  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     61    return false; 
     62  } 
    6163 
    6264  /** 
  • trunk/loci/formats/in/ImarisHDFReader.java

    r4200 r4205  
    6464  // -- IFormatReader API methods -- 
    6565 
    66   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    67   public boolean isThisType(byte[] block) { 
    68     if (block.length < blockCheckLen) return false; 
    69     return new String(block, 0, 8).indexOf("HDF") >= 0; 
     66  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     67  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     68    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     69    return stream.readString(8).indexOf("HDF") >= 0; 
    7070  } 
    7171 
  • trunk/loci/formats/in/ImarisReader.java

    r4200 r4205  
    6666  // -- IFormatReader API methods -- 
    6767 
    68   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    69   public boolean isThisType(byte[] block) { 
    70     if (block.length < blockCheckLen) return false; 
    71     return DataTools.bytesToInt(block, 0, 4, IS_LITTLE) == IMARIS_MAGIC_NUMBER; 
     68  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     69  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     70    if (!FormatTools.validStream(stream, blockCheckLen, IS_LITTLE)) { 
     71      return false; 
     72    } 
     73    return stream.readInt() == IMARIS_MAGIC_NUMBER; 
    7274  } 
    7375 
  • trunk/loci/formats/in/ImprovisionTiffReader.java

    r4200 r4205  
    7070  } 
    7171 
    72   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    73   public boolean isThisType(byte[] block) { 
    74     try { 
    75       RandomAccessStream stream = new RandomAccessStream(block); 
    76       boolean isThisType = isThisType(stream); 
    77       stream.close(); 
    78       return isThisType; 
    79     } 
    80     catch (IOException e) { 
    81       if (debug) trace(e); 
    82     } 
    83     return false; 
     72  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     73  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     74    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     75    String comment = TiffTools.getComment(ifd); 
     76    return comment != null && comment.indexOf("Improvision") != -1; 
    8477  } 
    8578 
     
    230223  } 
    231224 
    232   // -- Helper methods -- 
    233  
    234   private boolean isThisType(RandomAccessStream stream) throws IOException { 
    235     Hashtable ifd = TiffTools.getFirstIFD(stream); 
    236     String comment = TiffTools.getComment(ifd); 
    237     if (comment == null) return false; 
    238     return comment.indexOf("Improvision") != -1; 
    239   } 
    240  
    241225} 
  • trunk/loci/formats/in/InCellReader.java

    r4201 r4205  
    7474  // -- IFormatReader API methods -- 
    7575 
    76   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    77   public boolean isThisType(byte[] block) { 
     76  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     77  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    7878    return false; 
    7979  } 
  • trunk/loci/formats/in/KhorosReader.java

    r4200 r4205  
    5353  // -- IFormatReader API methods -- 
    5454 
    55   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    56   public boolean isThisType(byte[] block) { 
    57     return block[0] == (byte) 0xab && block[1] == 1; 
     55  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     56  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     57    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     58    return stream.readShort() == 0xab01; 
    5859  } 
    5960 
  • trunk/loci/formats/in/L2DReader.java

    r4200 r4205  
    5858  // -- IFormatReader API methods -- 
    5959 
    60   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    61   public boolean isThisType(byte[] block) { 
     60  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     61  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    6262    return false; 
    6363  } 
  • trunk/loci/formats/in/LIFReader.java

    r4203 r4205  
    6969  // -- IFormatReader API methods -- 
    7070 
    71   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    72   public boolean isThisType(byte[] block) { 
    73     return block[0] == 0x70; 
     71  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     72  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     73    return stream.read() == 0x70; 
    7474  } 
    7575 
  • trunk/loci/formats/in/LIMReader.java

    r4200 r4205  
    4949  // -- IFormatReader API methods -- 
    5050 
    51   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    52   public boolean isThisType(byte[] block) { 
     51  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     52  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    5353    return false; 
    5454  } 
  • trunk/loci/formats/in/LegacyND2Reader.java

    r4200 r4205  
    8181  } 
    8282 
    83   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    84   public boolean isThisType(byte[] block) { 
     83  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     84  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    8585    return false; 
    8686  } 
  • trunk/loci/formats/in/LegacyQTReader.java

    r4200 r4205  
    7373  // -- IFormatReader API methods -- 
    7474 
    75   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    76   public boolean isThisType(byte[] block) { return false; } 
     75  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     76  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     77    return false; 
     78  } 
    7779 
    7880  /** 
  • trunk/loci/formats/in/LeicaReader.java

    r4200 r4205  
    117117  } 
    118118 
    119   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    120   public boolean isThisType(byte[] block) { 
    121     if (block.length < blockCheckLen) return false; 
    122     try { 
    123       RandomAccessStream stream = new RandomAccessStream(block); 
    124       Hashtable ifd = TiffTools.getFirstIFD(stream); 
    125       stream.close(); 
    126       return ifd.containsKey(new Integer(LEICA_MAGIC_TAG)); 
    127     } 
    128     catch (IOException e) { 
    129       if (debug) LogTools.trace(e); 
    130     } 
    131     return false; 
     119  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     120  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     121    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     122    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     123    return ifd.containsKey(new Integer(LEICA_MAGIC_TAG)); 
    132124  } 
    133125 
  • trunk/loci/formats/in/MINCReader.java

    r4165 r4205  
    5353  // -- IFormatReader API methods -- 
    5454 
    55   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    56   public boolean isThisType(byte[] block) { 
     55  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     56  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    5757    return false; 
    5858  } 
  • trunk/loci/formats/in/MNGReader.java

    r4132 r4205  
    5757  // -- IFormatReader API methods -- 
    5858 
    59   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    60   public boolean isThisType(byte[] block) { 
    61     if (block.length < 8) return false; 
    62     return block[0] == 0x8a && block[1] == 0x4d && block[2] == 0x4e && 
    63       block[3] == 0x47 && block[4] == 0x0d && block[5] == 0x0a && 
    64       block[6] == 0x1a && block[7] == 0x0a; 
     59  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     60  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     61    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     62    return stream.readLong() == 0x8a4d4e470d0a1a0aL; 
    6563  } 
    6664 
  • trunk/loci/formats/in/MRCReader.java

    r4200 r4205  
    6060  // -- IFormatReader API methods -- 
    6161 
    62   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    63   public boolean isThisType(byte[] block) { 
     62  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     63  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    6464    return false; // no way to tell if this is an MRC file or not 
    6565  } 
  • trunk/loci/formats/in/MetamorphTiffReader.java

    r4200 r4205  
    8686  } 
    8787 
    88   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    89   public boolean isThisType(byte[] block) { 
    90     try { 
    91       RandomAccessStream stream = new RandomAccessStream(block); 
    92       boolean isThisType = isThisType(stream); 
    93       stream.close(); 
    94       return isThisType; 
    95     } 
    96     catch (IOException e) { 
    97       if (debug) trace(e); 
    98     } 
    99     return false; 
     88  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     89  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     90    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     91    String comment = TiffTools.getComment(TiffTools.getFirstIFD(stream)); 
     92    return comment != null && comment.trim().startsWith("<MetaData>"); 
    10093  } 
    10194 
     
    216209  } 
    217210 
    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  
    225211} 
  • trunk/loci/formats/in/MicromanagerReader.java

    r4200 r4205  
    7979  } 
    8080 
    81   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    82   public boolean isThisType(byte[] b) { 
    83     return tiffReader.isThisType(b); 
     81  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     82  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     83    return tiffReader.isThisType(stream); 
    8484  } 
    8585 
  • trunk/loci/formats/in/MinimalTiffReader.java

    r4203 r4205  
    6262  // -- IFormatReader API methods -- 
    6363 
    64   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    65   public boolean isThisType(byte[] block) { 
    66     return TiffTools.isValidHeader(block); 
     64  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     65  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     66    return TiffTools.isValidHeader(stream); 
    6767  } 
    6868 
  • trunk/loci/formats/in/NAFReader.java

    r4200 r4205  
    5757  // -- IFormatReader API methods -- 
    5858 
    59   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    60   public boolean isThisType(byte[] block) { 
     59  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     60  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    6161    return true; 
    6262  } 
  • trunk/loci/formats/in/ND2Reader.java

    r4203 r4205  
    9090 
    9191  /** Constructs a new ND2 reader. */ 
    92   public ND2Reader() { super("Nikon ND2", new String[] {"nd2", "jp2"}); } 
     92  public ND2Reader() { 
     93    super("Nikon ND2", new String[] {"nd2", "jp2"}); 
     94    blockCheckLen = 8; 
     95  } 
    9396 
    9497  // -- ND2Reader API methods -- 
     
    104107  // -- IFormatReader API methods -- 
    105108 
    106   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    107   public boolean isThisType(byte[] block) { 
    108     if (block.length < 8) return false; 
    109     return block[4] == 0x6a && block[5] == 0x50 && block[6] == 0x20 && 
    110       block[7] == 0x20; 
     109  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     110  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     111    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     112    stream.seek(4); 
     113    return stream.readInt() == 0x6a502020; 
    111114  } 
    112115 
  • trunk/loci/formats/in/NRRDReader.java

    r4202 r4205  
    5656 
    5757  /** Constructs a new NRRD reader. */ 
    58   public NRRDReader() { super("NRRD", new String[] {"nrrd", "nhdr"}); } 
     58  public NRRDReader() { 
     59    super("NRRD", new String[] {"nrrd", "nhdr"}); 
     60    blockCheckLen = 4; 
     61  } 
    5962 
    6063  // -- IFormatReader API methods -- 
    6164 
    62   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    63   public boolean isThisType(byte[] block) { 
    64     if (block.length < 4) return false; 
    65     return new String(block).startsWith("NRRD"); 
     65  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     66  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     67    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     68    return stream.readString(blockCheckLen).startsWith("NRRD"); 
    6669  } 
    6770 
  • trunk/loci/formats/in/NikonReader.java

    r4147 r4205  
    144144  } 
    145145 
    146   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    147   public boolean isThisType(byte[] block) { 
    148     try { 
    149       RandomAccessStream stream = new RandomAccessStream(block); 
    150       boolean isThisType = isThisType(stream); 
    151       stream.close(); 
    152       return isThisType; 
    153     } 
    154     catch (IOException e) { 
    155       if (debug) trace(e); 
    156     } 
    157     return false; 
     146  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     147  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     148    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     149    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     150    return ifd != null && ifd.containsKey(new Integer(TIFF_EPS_STANDARD)); 
    158151  } 
    159152 
     
    400393  } 
    401394 
    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  
    407395} 
  • trunk/loci/formats/in/OMETiffReader.java

    r4202 r4205  
    5858  // -- IFormatReader API methods -- 
    5959 
    60   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    61   public boolean isThisType(byte[] block) { 
    62     return TiffTools.isValidHeader(block); 
     60  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     61  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     62    return TiffTools.isValidHeader(stream); 
    6363  } 
    6464 
  • trunk/loci/formats/in/OMEXMLReader.java

    r4203 r4205  
    8181 
    8282  /** Constructs a new OME-XML reader. */ 
    83   public OMEXMLReader() { super("OME-XML", "ome"); } 
     83  public OMEXMLReader() { 
     84    super("OME-XML", "ome"); 
     85    blockCheckLen = 64; 
     86  } 
    8487 
    8588  // -- IFormatReader API methods -- 
    8689 
    87   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    88   public boolean isThisType(byte[] block) { 
    89     String xml = new String(block); 
     90  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     91  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     92    String xml = stream.readString(blockCheckLen); 
    9093    return xml.startsWith("<?xml") && xml.indexOf("<OME") >= 0; 
    9194  } 
  • trunk/loci/formats/in/OpenlabRawReader.java

    r4202 r4205  
    6363  // -- IFormatReader API methods -- 
    6464 
    65   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    66   public boolean isThisType(byte[] block) { 
    67     if (block.length < blockCheckLen) return false; 
    68     return new String(block).startsWith("OLRW"); 
     65  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     66  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     67    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     68    return stream.readString(blockCheckLen).startsWith("OLRW"); 
    6969  } 
    7070 
  • trunk/loci/formats/in/OpenlabReader.java

    r4202 r4205  
    103103  // -- IFormatReader API methods -- 
    104104 
    105   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    106   public boolean isThisType(byte[] block) { 
    107     if (block.length < blockCheckLen) return false; 
    108     return block[0] == 0 && block[1] == 0 && 
    109       block[2] == -1 && block[3] == -1 && block[4] == 105 && 
    110       block[5] == 109 && block[6] == 112 && block[7] == 114; 
     105  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     106  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     107    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     108    return stream.readLong() == 0xffff696d7072L; 
    111109  } 
    112110 
  • trunk/loci/formats/in/PCIReader.java

    r4202 r4205  
    4949 
    5050  /** Constructs a new SimplePCI reader. */ 
    51   public PCIReader() { super("Compix Simple-PCI", "cxd"); } 
     51  public PCIReader() { 
     52    super("Compix Simple-PCI", "cxd"); 
     53    blockCheckLen = 4; 
     54  } 
    5255 
    5356  // -- IFormatReader API methods -- 
    5457 
    55   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    56   public boolean isThisType(byte[] block) { 
    57     return (block[0] == 0xd0 && block[1] == 0xcf && block[2] == 0x11 && 
    58       block[3] == 0xe0); 
     58  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     59  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     60    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     61    return stream.readInt() == 0xd0cf11e0; 
    5962  } 
    6063 
  • trunk/loci/formats/in/PCXReader.java

    r4202 r4205  
    6060  // -- IFormatReader API methods -- 
    6161 
    62   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    63   public boolean isThisType(byte[] block) { 
    64     return block.length >= blockCheckLen && block[0] == 10; 
     62  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     63  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     64    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     65    return stream.read() == 10; 
    6566  } 
    6667 
  • trunk/loci/formats/in/PGMReader.java

    r4202 r4205  
    5151 
    5252  /** Constructs a new PGMReader. */ 
    53   public PGMReader() { super("Portable Gray Map", "pgm"); } 
     53  public PGMReader() { 
     54    super("Portable Gray Map", "pgm"); 
     55    blockCheckLen = 1; 
     56  } 
    5457 
    5558  // -- IFormatReader API methods -- 
    5659 
    57   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    58   public boolean isThisType(byte[] block) { 
    59     return block[0] == 'P'; 
     60  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     61  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     62    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     63    return stream.read() == 'P'; 
    6064  } 
    6165 
  • trunk/loci/formats/in/PSDReader.java

    r4202 r4205  
    5252 
    5353  /** Constructs a new PSD reader. */ 
    54   public PSDReader() { super("Adobe Photoshop", "psd"); } 
     54  public PSDReader() { 
     55    super("Adobe Photoshop", "psd"); 
     56    blockCheckLen = 4; 
     57  } 
    5558 
    5659  // -- IFormatReader API methods -- 
    5760 
    58   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    59   public boolean isThisType(byte[] block) { 
    60     return new String(block).startsWith("8BPS"); 
     61  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     62  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     63    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     64    return stream.readString(blockCheckLen).startsWith("8BPS"); 
    6165  } 
    6266 
  • trunk/loci/formats/in/PerkinElmerReader.java

    r4202 r4205  
    122122  } 
    123123 
    124   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    125   public boolean isThisType(byte[] block) { return false; } 
     124  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     125  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     126    return false; 
     127  } 
    126128 
    127129  /* @see loci.formats.IFormatReader#fileGroupOption(String) */ 
  • trunk/loci/formats/in/PictReader.java

    r4202 r4205  
    8989 
    9090  /** Constructs a new PICT reader. */ 
    91   public PictReader() { super("PICT", new String[] {"pict", "pct"}); } 
     91  public PictReader() { 
     92    super("PICT", new String[] {"pict", "pct"}); 
     93    blockCheckLen = 528; 
     94  } 
    9295 
    9396  // -- PictReader API methods -- 
     
    189192  // -- IFormatReader API methods -- 
    190193 
    191   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    192   public boolean isThisType(byte[] block) { 
    193     return block.length >= 528; 
     194  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     195  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     196    return FormatTools.validStream(stream, blockCheckLen, false); 
    194197  } 
    195198 
  • trunk/loci/formats/in/PrairieReader.java

    r4202 r4205  
    118118  } 
    119119 
    120   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    121   public boolean isThisType(byte[] block) { 
    122     if (block.length < blockCheckLen) return false; 
    123  
    124     String s = new String(block); 
     120  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     121  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     122    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     123    String s = stream.readString(blockCheckLen); 
    125124    if (s.indexOf("xml") != -1 && s.indexOf("PV") != -1) return true; 
    126125 
    127     try { 
    128       RandomAccessStream stream = new RandomAccessStream(block); 
    129       Hashtable ifd = TiffTools.getFirstIFD(stream); 
    130       String software = (String) TiffTools.getIFDValue(ifd, TiffTools.SOFTWARE); 
    131       stream.close(); 
    132       return software.indexOf("Prairie") != -1 && 
    133         ifd.containsKey(new Integer(PRAIRIE_TAG_1)) && 
    134         ifd.containsKey(new Integer(PRAIRIE_TAG_2)) && 
    135         ifd.containsKey(new Integer(PRAIRIE_TAG_3)); 
    136     } 
    137     catch (Exception e) { 
    138       if (debug) LogTools.trace(e); 
    139     } 
    140     return false; 
     126    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     127    String software = (String) TiffTools.getIFDValue(ifd, TiffTools.SOFTWARE); 
     128    return software.indexOf("Prairie") != -1 && 
     129      ifd.containsKey(new Integer(PRAIRIE_TAG_1)) && 
     130      ifd.containsKey(new Integer(PRAIRIE_TAG_2)) && 
     131      ifd.containsKey(new Integer(PRAIRIE_TAG_3)); 
    141132  } 
    142133 
  • trunk/loci/formats/in/QTReader.java

    r4203 r4205  
    113113 
    114114  /** Constructs a new QuickTime reader. */ 
    115   public QTReader() { super("QuickTime", "mov"); } 
     115  public QTReader() { 
     116    super("QuickTime", "mov"); 
     117    blockCheckLen = 64; 
     118  } 
    116119 
    117120  // -- QTReader API methods -- 
     
    127130 
    128131    if (open) { 
    129       byte[] b; 
    130132      try { 
    131         in = new RandomAccessStream(name); 
    132         long len = in.length(); 
    133         if (len > 16) len = 16; 
    134         b = new byte[(int) len]; 
    135         in.readFully(b); 
    136         in.close(); 
    137       } 
    138       catch (IOException exc) { 
    139         if (debug) trace(exc); 
     133        RandomAccessStream s = new RandomAccessStream(name); 
     134        boolean isThisType = isThisType(s); 
     135        s.close(); 
     136        return isThisType; 
     137      } 
     138      catch (IOException e) { 
     139        if (debug) LogTools.trace(e); 
    140140        return false; 
    141141      } 
    142       return isThisType(b); 
    143142    } 
    144143    else { // not allowed to check the file contents 
     
    147146  } 
    148147 
    149   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    150   public boolean isThisType(byte[] block) { 
     148  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     149  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    151150    // use a crappy hack for now 
    152     String s = new String(block); 
     151    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     152    String s = stream.readString(blockCheckLen); 
    153153    for (int i=0; i<CONTAINER_TYPES.length; i++) { 
    154154      if (s.indexOf(CONTAINER_TYPES[i]) >= 0) return true; 
  • trunk/loci/formats/in/SDTReader.java

    r4202 r4205  
    9999  // -- IFormatReader API methods -- 
    100100 
    101   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    102   public boolean isThisType(byte[] block) { return false; } 
     101  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     102  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     103    return false; 
     104  } 
    103105 
    104106  /* @see loci.formats.IFormatReader#getChannelDimLengths() */ 
  • trunk/loci/formats/in/SlidebookReader.java

    r4202 r4205  
    5353 
    5454  /** Constructs a new Slidebook reader. */ 
    55   public SlidebookReader() { super("Olympus Slidebook", "sld"); } 
     55  public SlidebookReader() { 
     56    super("Olympus Slidebook", "sld"); 
     57    blockCheckLen = 8; 
     58  } 
    5659 
    5760  // -- IFormatReader API methods -- 
    5861 
    59   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    60   public boolean isThisType(byte[] block) { 
    61     if (block.length < 8) return false; 
    62     return block[0] == 0x6c && block[1] == 0 && block[2] == 0 && 
    63       block[3] == 1 && block[4] == 0x49 && block[5] == 0x49 && block[6] == 0; 
     62  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     63  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     64    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     65    return stream.readLong() == 0x6c000001494900L; 
    6466  } 
    6567 
  • trunk/loci/formats/in/TCSReader.java

    r4203 r4205  
    104104  } 
    105105 
    106   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    107   public boolean isThisType(byte[] block) { 
    108     try { 
    109       return isThisType(new RandomAccessStream(block)); 
    110     } 
    111     catch (IOException e) { 
    112       if (debug) LogTools.trace(e); 
    113       return false; 
    114     } 
     106  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     107  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     108    // check for Leica TCS IFD directory entries 
     109    Hashtable ifd = TiffTools.getFirstIFD(stream); 
     110 
     111    if (ifd == null) return false; 
     112    String document = (String) ifd.get(new Integer(TiffTools.DOCUMENT_NAME)); 
     113    if (document == null) document = ""; 
     114    Object s = ifd.get(new Integer(TiffTools.SOFTWARE)); 
     115    String software = null; 
     116    if (s instanceof String) software = (String) s; 
     117    else if (s instanceof String[]) { 
     118      String[] ss = (String[]) s; 
     119      if (ss.length > 0) software = ss[0]; 
     120    } 
     121    if (software == null) software = ""; 
     122    return document.startsWith("CHANNEL") || software.trim().equals("TCSNTV"); 
    115123  } 
    116124 
     
    414422  } 
    415423 
    416   // -- Helper methods -- 
    417  
    418   private boolean isThisType(RandomAccessStream stream) throws IOException { 
    419     // check for Leica TCS IFD directory entries 
    420     Hashtable ifd = TiffTools.getFirstIFD(stream); 
    421     stream.close(); 
    422  
    423     if (ifd == null) return false; 
    424     String document = (String) ifd.get(new Integer(TiffTools.DOCUMENT_NAME)); 
    425     if (document == null) document = ""; 
    426     Object s = ifd.get(new Integer(TiffTools.SOFTWARE)); 
    427     String software = null; 
    428     if (s instanceof String) software = (String) s; 
    429     else if (s instanceof String[]) { 
    430       String[] ss = (String[]) s; 
    431       if (ss.length > 0) software = ss[0]; 
    432     } 
    433     if (software == null) software = ""; 
    434     return document.startsWith("CHANNEL") || software.trim().equals("TCSNTV"); 
    435   } 
    436  
    437424} 
  • trunk/loci/formats/in/TillVisionReader.java

    r4200 r4205  
    5252  // -- IFormatReader API methods -- 
    5353 
    54   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    55   public boolean isThisType(byte[] block) { 
     54  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     55  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    5656    return false; 
    5757  } 
  • trunk/loci/formats/in/VisitechReader.java

    r4202 r4205  
    5656  // -- IFormatReader API methods -- 
    5757 
    58   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    59   public boolean isThisType(byte[] block) { 
     58  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     59  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    6060    return false; 
    6161  } 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r4202 r4205  
    8484 
    8585  /** Constructs a new ZeissZVI reader. */ 
    86   public ZeissZVIReader() { super("Zeiss Vision Image (ZVI)", "zvi"); } 
     86  public ZeissZVIReader() { 
     87    super("Zeiss Vision Image (ZVI)", "zvi"); 
     88    blockCheckLen = 4; 
     89  } 
    8790 
    8891  // -- IFormatReader API methods -- 
    8992 
    90   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    91   public boolean isThisType(byte[] block) { 
    92     return (block[0] == 0xd0 && block[1] == 0xcf && 
    93       block[2] == 0x11 && block[3] == 0xe0); 
     93  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     94  public boolean isThisType(RandomAccessStream stream) throws IOException { 
     95    if (!FormatTools.validStream(stream, blockCheckLen, false)) return false; 
     96    return stream.readInt() == 0xd0cf11e0; 
    9497  } 
    9598 
  • trunk/loci/formats/ome/OMEROReader.java

    r4203 r4205  
    8383  } 
    8484 
    85   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    86   public boolean isThisType(byte[] block) { 
     85  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     86  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    8787    return false; 
    8888  } 
  • trunk/loci/formats/ome/OMEReader.java

    r4203 r4205  
    254254  // -- IFormatReader API methods -- 
    255255 
    256   /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    257   public boolean isThisType(byte[] block) { 
     256  /* @see loci.formats.IFormatReader#isThisType(RandomAccessStream) */ 
     257  public boolean isThisType(RandomAccessStream stream) throws IOException { 
    258258    return true; 
    259259  } 
Note: See TracChangeset for help on using the changeset viewer.