Skip to content

Commit

Permalink
Always check the type of the Prairie XML file
Browse files Browse the repository at this point in the history
This prevents the Prairie reader from flagging XML files which do not
belong to a Prairie dataset at all (e.g. ScanR's experiment_descriptor.xml).

Fixes the type checking fixes introduced in
3c7425a.

Noticed by Jenkins' BIOFORMATS-per-commit-test job.
  • Loading branch information
melissalinkert committed Apr 5, 2012
1 parent 69f125f commit 8610163
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions components/bio-formats/src/loci/formats/in/PrairieReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,28 @@ public boolean isThisType(String name, boolean open) {
// check for appropriately named XML file

Location xml = new Location(parent, prefix + ".xml");
if (!xml.exists() && prefix.indexOf("_") != -1) {
prefix = prefix.substring(0, prefix.indexOf("_"));
while (!xml.exists() && prefix.indexOf("_") != -1) {
prefix = prefix.substring(0, prefix.lastIndexOf("_"));
xml = new Location(parent, prefix + ".xml");
}

return xml.exists() && super.isThisType(name, false);
boolean validXML = false;
try {
RandomAccessInputStream xmlStream =
new RandomAccessInputStream(xml.getAbsolutePath());
validXML = isThisType(xmlStream);
xmlStream.close();
}
catch (IOException e) {
LOGGER.trace("Failed to check XML file's type", e);
}

return xml.exists() && super.isThisType(name, false) && validXML;
}

/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
final int blockLen = 1048608;
final int blockLen = (int) Math.min(1048608, stream.length());
if (!FormatTools.validStream(stream, blockLen, false)) return false;
String s = stream.readString(blockLen);
if (s.indexOf("xml") != -1 && s.indexOf("PV") != -1) return true;
Expand Down

0 comments on commit 8610163

Please sign in to comment.