package jalview.io;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Locale;
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
+ throws FileFormatException, FileNotFoundException
{
// BH 2018
return (file instanceof File ? identify((File) file, protocol)
* @throws FileFormatException
*/
public FileFormatI identify(String file, DataSourceType sourceType)
- throws FileFormatException
+ throws FileFormatException, FileNotFoundException
{
String emessage = "UNIDENTIFIED FILE PARSING ERROR";
FileParse parser = null;
+ FileNotFoundException fnf = null;
try
{
parser = new FileParse(file, sourceType);
{
return identify(parser);
}
+ } catch (FileNotFoundException e)
+ {
+ fnf = e;
+ emessage = "Could not find '" + file + "'";
+ Console.error("Could not find '" + file + "'", e);
+ } catch (IOException e)
+ {
+ Console.error("Error whilst trying to read " + file, e);
} catch (Exception e)
{
Console.error("Error whilst identifying " + file, e);
{
throw new FileFormatException(parser.errormessage);
}
+ if (fnf != null)
+ {
+ throw (fnf);
+ }
throw new FileFormatException(emessage);
}
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))
try
{
type = ider.identify(args[i], DataSourceType.FILE);
+ } catch (FileNotFoundException e)
+ {
+ Console.error(String.format("Error '%s' fetching file %s", args[i],
+ e.getMessage()));
} catch (FileFormatException e)
{
Console.error(