Changeset 6763


Ignore:
Timestamp:
08/03/10 08:54:37 (9 years ago)
Author:
melissa
Message:

Adjusted AnalyzeReader's isThisType implementations, so that AnalyzeReader does not try to pick up PDS files. This was a Mac-specific bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/AnalyzeReader.java

    r6655 r6763  
    4545public class AnalyzeReader extends FormatReader { 
    4646 
     47  // -- Constants -- 
     48 
     49  private static final int MAGIC = 0x15c; 
     50 
    4751  // -- Fields -- 
    4852 
     
    6973  public boolean isThisType(String name, boolean open) { 
    7074    if (!super.isThisType(name, open)) return false; 
     75    String headerFile = checkSuffix(name, "hdr") ? name : null; 
    7176    String extension = name.substring(name.lastIndexOf(".") + 1); 
    7277    name = name.substring(0, name.lastIndexOf(".")); 
     
    7580    else if (extension.equals("hdr")) extension = "img"; 
    7681    else if (extension.equals("HDR")) extension = "IMG"; 
    77  
    78     return new Location(name + "." + extension).exists(); 
     82    if (extension.equalsIgnoreCase("hdr")) { 
     83      headerFile = name + "." + extension; 
     84    } 
     85 
     86    boolean validHeader = false; 
     87    try { 
     88      RandomAccessInputStream headerStream = 
     89        new RandomAccessInputStream(headerFile); 
     90      validHeader = isThisType(headerStream); 
     91      headerStream.close(); 
     92    } 
     93    catch (IOException e) { } 
     94 
     95    return new Location(name + "." + extension).exists() && validHeader; 
     96  } 
     97 
     98  /* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ 
     99  public boolean isThisType(RandomAccessInputStream stream) throws IOException { 
     100    final int blockLen = 4; 
     101    if (!FormatTools.validStream(stream, blockLen, false)) return false; 
     102    stream.order(true); 
     103    int checkLittleEndian = stream.readInt(); 
     104    stream.seek(stream.getFilePointer() - 4); 
     105    stream.order(false); 
     106    int checkBigEndian = stream.readInt(); 
     107    return checkLittleEndian == MAGIC || checkBigEndian == MAGIC; 
    79108  } 
    80109 
Note: See TracChangeset for help on using the changeset viewer.