git://source.jalview.org
/
jalview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
JAL-4001 Check --nousagestats before doing analytics in headless mode
[jalview.git]
/
src
/
jalview
/
io
/
IdentifyFile.java
diff --git
a/src/jalview/io/IdentifyFile.java
b/src/jalview/io/IdentifyFile.java
index
e2786ae
..
ea87058
100755
(executable)
--- a/
src/jalview/io/IdentifyFile.java
+++ b/
src/jalview/io/IdentifyFile.java
@@
-22,6
+22,9
@@
package jalview.io;
import java.io.File;
import java.io.IOException;
import java.io.File;
import java.io.IOException;
+import java.util.Locale;
+
+import jalview.bin.Console;
/**
* DOCUMENT ME!
/**
* DOCUMENT ME!
@@
-31,9
+34,20
@@
import java.io.IOException;
*/
public class IdentifyFile
{
*/
public class IdentifyFile
{
+
+ public FileFormatI identify(Object file, DataSourceType protocol)
+ throws FileFormatException
+ {
+ // BH 2018
+ return (file instanceof File ? identify((File) file, protocol)
+ : identify((String) file, protocol));
+
+ }
+
public FileFormatI identify(File file, DataSourceType sourceType)
throws FileFormatException
{
public FileFormatI identify(File file, DataSourceType sourceType)
throws FileFormatException
{
+ // BH 2018
String emessage = "UNIDENTIFIED FILE PARSING ERROR";
FileParse parser = null;
try
String emessage = "UNIDENTIFIED FILE PARSING ERROR";
FileParse parser = null;
try
@@
-45,8
+59,7
@@
public class IdentifyFile
}
} catch (Exception e)
{
}
} 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)
emessage = e.getMessage();
}
if (parser != null)
@@
-81,8
+94,7
@@
public class IdentifyFile
}
} catch (Exception e)
{
}
} 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)
emessage = e.getMessage();
}
if (parser != null)
@@
-156,26
+168,39
@@
public class IdentifyFile
if (source.inFile != null)
{
String fileStr = source.inFile.getName();
if (source.inFile != null)
{
String fileStr = source.inFile.getName();
- // possibly a Jalview archive.
- if (fileStr.lastIndexOf(".jar") > -1
- || fileStr.lastIndexOf(".zip") > -1)
+ if (fileStr.contains(".jar") || fileStr.contains(".zip")
+ || fileStr.contains(".jvp"))
{
{
+ // possibly a Jalview archive (but check further)
reply = FileFormat.Jalview;
}
}
if (!lineswereskipped && data.startsWith("PK"))
{
reply = FileFormat.Jalview;
}
}
if (!lineswereskipped && data.startsWith("PK"))
{
- reply = FileFormat.Jalview; // archive.
+ reply = FileFormat.Jalview; // archive
break;
}
}
break;
}
}
- data = data.toUpperCase();
+ data = data.toUpperCase(Locale.ROOT);
if (data.startsWith(ScoreMatrixFile.SCOREMATRIX))
{
reply = FileFormat.ScoreMatrix;
break;
}
if (data.startsWith(ScoreMatrixFile.SCOREMATRIX))
{
reply = FileFormat.ScoreMatrix;
break;
}
+ if (data.startsWith("LOCUS"))
+ {
+ reply = FileFormat.GenBank;
+ break;
+ }
+ if (data.startsWith("ID "))
+ {
+ if (data.substring(2).trim().split(";").length == 7)
+ {
+ reply = FileFormat.Embl;
+ break;
+ }
+ }
if (data.startsWith("H ") && !aaIndexHeaderRead)
{
aaIndexHeaderRead = true;
if (data.startsWith("H ") && !aaIndexHeaderRead)
{
aaIndexHeaderRead = true;
@@
-310,7
+335,7
@@
public class IdentifyFile
if ((lessThan > -1)) // possible Markup Language data i.e HTML,
// RNAML, XML
{
if ((lessThan > -1)) // possible Markup Language data i.e HTML,
// RNAML, XML
{
- String upper = data.toUpperCase();
+ String upper = data.toUpperCase(Locale.ROOT);
if (upper.substring(lessThan).startsWith("<HTML"))
{
reply = FileFormat.Html;
if (upper.substring(lessThan).startsWith("<HTML"))
{
reply = FileFormat.Html;
@@
-382,16
+407,15
@@
public class IdentifyFile
}
} catch (Exception ex)
{
}
} 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)
{
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");
}
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;
}
return reply;
}
@@
-443,6
+467,11
@@
public class IdentifyFile
return true;
}
return true;
}
+ /**
+ *
+ * @param args
+ * @j2sIgnore
+ */
public static void main(String[] args)
{
for (int i = 0; args != null && i < args.length; i++)
public static void main(String[] args)
{
for (int i = 0; args != null && i < args.length; i++)
@@
-454,15
+483,15
@@
public class IdentifyFile
type = ider.identify(args[i], DataSourceType.FILE);
} catch (FileFormatException e)
{
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()));
}
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)
{
}
if (args == null || args.length == 0)
{
- System.err.println("Usage: <Filename> [<Filename> ...]");
+ Console.error("Usage: <Filename> [<Filename> ...]");
}
}
}
}