*/
package jalview.io;
-import java.util.Locale;
-
import java.io.File;
import java.io.IOException;
+import java.util.Locale;
+
+import jalview.bin.Console;
/**
* DOCUMENT ME!
public class IdentifyFile
{
+ private static final String XMLHEADER = "<?XML VERSION=\"1.0\" ENCODING=\"UTF-8\" STANDALONE=\"YES\"?>";
+
public FileFormatI identify(Object file, DataSourceType protocol)
throws FileFormatException
{
}
} catch (Exception e)
{
- System.err.println("Error whilst identifying " + file);
- e.printStackTrace(System.err);
+ Console.error("Error whilst identifying " + file, e);
emessage = e.getMessage();
}
if (parser != null)
}
} catch (Exception e)
{
- System.err.println("Error whilst identifying " + file);
- e.printStackTrace(System.err);
+ Console.error("Error whilst identifying " + file, e);
emessage = e.getMessage();
}
if (parser != null)
String data;
int bytesRead = 0;
int trimmedLength = 0;
+ boolean isXml = false; // set true if first line is XMLHEADER
boolean lineswereskipped = false;
boolean isBinary = false; // true if length is non-zero and non-printable
// characters are encountered
reply = FileFormat.ScoreMatrix;
break;
}
+ if (data.startsWith(XMLHEADER) && !lineswereskipped)
+ {
+ isXml = true;
+ }
if (data.startsWith("LOCUS"))
{
reply = FileFormat.GenBank;
reply = FileFormat.Rnaml;
break;
}
+ if (isXml && data.contains(
+ "<NS2:JALVIEWUSERCOLOURS SCHEMENAME=\"SEQUENCE FEATURES\" XMLNS:NS2=\"WWW.JALVIEW.ORG/COLOURS\">"))
+ {
+ reply = FileFormat.FeatureSettings;
+ break;
+ }
}
if ((data.length() < 1) || (data.indexOf("#") == 0))
}
} catch (Exception ex)
{
- System.err.println("File Identification failed!\n" + ex);
+ Console.error("File Identification failed!\n" + ex);
throw new FileFormatException(source.errormessage);
}
if (trimmedLength == 0)
{
- System.err.println(
- "File Identification failed! - Empty file was read.");
+ Console.error("File Identification failed! - Empty file was read.");
throw new FileFormatException("EMPTY DATA FILE");
}
- System.out.println("File format identified as " + reply.toString());
+ Console.debug("File format identified as " + reply.toString());
return reply;
}
type = ider.identify(args[i], DataSourceType.FILE);
} catch (FileFormatException e)
{
- System.err.println(
+ Console.error(
String.format("Error '%s' identifying file type for %s",
args[i], e.getMessage()));
}
- System.out.println("Type of " + args[i] + " is " + type);
+ Console.debug("Type of " + args[i] + " is " + type);
}
if (args == null || args.length == 0)
{
- System.err.println("Usage: <Filename> [<Filename> ...]");
+ Console.error("Usage: <Filename> [<Filename> ...]");
}
}