else
{
FileFormatI format = null;
+ boolean file_not_found=false;
+ String fmtmessage="";
try
{
format = new IdentifyFile().identify(url, DataSourceType.URL);
} catch (FileNotFoundException e)
{
jalview.bin.Console.error("URL '" + url + "' not found", e);
+ file_not_found=true;
} catch (FileFormatException e)
{
jalview.bin.Console.error(
"File at URL '" + url + "' format not recognised", e);
+ fmtmessage = e.getLocalizedMessage();
}
if (format == null)
{
- String msg = MessageManager.formatMessage("label.couldnt_locate",
- url);
- JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
- MessageManager.getString("label.url_not_found"),
- JvOptionPane.WARNING_MESSAGE);
+ if (file_not_found) {
+ String msg = MessageManager.formatMessage("label.couldnt_locate",
+ url);
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
+ MessageManager.getString("label.url_not_found"),
+ JvOptionPane.WARNING_MESSAGE);
+ } else {
+ String msg = MessageManager.formatMessage("label.error_retrieving_data",
+ url);
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg +"<br/>"+fmtmessage,
+ MessageManager.getString("label.error_retrieving_data"),
+ JvOptionPane.WARNING_MESSAGE);
+
+ }
return;
}
protected boolean error = true;
+ /**
+ * set if location coordinates resolved to no data..
+ */
+ protected boolean filenotfound = false;
+
protected String warningMessage = null;
/**
private boolean checkFileSource(String fileStr) throws IOException
{
error = false;
+ filenotfound=false;
this.inFile = new File(fileStr);
- // check to see if it's a Jar file in disguise.
+
if (!inFile.exists())
{
errormessage = "FILE NOT FOUND";
- error = true;
- }
- if (!inFile.canRead())
- {
- errormessage = "FILE CANNOT BE OPENED FOR READING";
- error = true;
+ filenotfound = true;
+ return(error = true);
}
if (inFile.isDirectory())
{
// this is really a 'complex' filetype - but we don't handle directory
// reads yet.
errormessage = "FILE IS A DIRECTORY";
- error = true;
+ return(error = true);
+ }
+ if (!inFile.canRead())
+ {
+ errormessage = "FILE CANNOT BE OPENED FOR READING";
+ return(error = true);
}
+ // final check - whether we have a gzipped source
if (!error)
{
try
int rc = conn.getResponseCode();
if (rc != HttpURLConnection.HTTP_OK)
{
+ filenotfound=true;
throw new FileNotFoundException("Response status from " + urlStr
+ " was " + conn.getResponseCode());
}
bytes = Platform.getFileBytes(file);
dataSourceType = sourceType;
error = false;
- boolean filenotfound = false;
+ filenotfound = false;
if (sourceType == DataSourceType.FILE)
{
}
else if (checkFileSource(fileStr))
{
+ boolean fileStrNotFound=filenotfound;
String suffixLess = extractSuffix(fileStr);
if (suffixLess != null)
{
if (checkFileSource(suffixLess))
{
+ if (filenotfound)
+ {
+ throw(new FileNotFoundException("Couldn't find '"+suffixLess+"'"+ (fileStrNotFound ? " and also couldn't find "+fileStr : "")));
+ }
throw new IOException(MessageManager.formatMessage(
"exception.problem_opening_file_also_tried",
new String[]
}
else
{
+ if (filenotfound)
+ {
+ throw(new FileNotFoundException("Couldn't find '"+fileStr+"'"));
+ }
throw new IOException(MessageManager.formatMessage(
"exception.problem_opening_file", new String[]
{ inFile.getName(), errormessage }));
*/
public boolean isExporting()
{
- return !error && dataIn == null;
+ return isValid() && dataIn == null;
}
/**
*/
public boolean isValid()
{
- return !error;
+ return !error && !filenotfound;
}
/**
{
errormessage = "EXCEPTION ON CLOSE";
error = true;
+ filenotfound = false;
dataIn.close();
dataIn = null;
errormessage = "SOURCE IS CLOSED";
* @param file
* @param sourceType
* @return
- * @throws FileFormatException
+ * @throws FileFormatException, FileNotFoundException
*/
public FileFormatI identify(String file, DataSourceType sourceType)
throws FileFormatException, FileNotFoundException
fnf = e;
emessage = "Could not find '" + file + "'";
Console.error("Could not find '" + file + "'", e);
+ throw(fnf);
} catch (IOException e)
{
Console.error("Error whilst trying to read " + file, e);
{
throw new FileFormatException(parser.errormessage);
}
- if (fnf != null)
- {
- throw (fnf);
- }
throw new FileFormatException(emessage);
}
//
};
}
-
+ @Test(groups="Functional")
+ public void testFileNotFound()
+ {
+ try {
+ new IdentifyFile().identify("/path/that/does/not/exist", DataSourceType.FILE);
+ }
+ catch (FileNotFoundException ff)
+ {
+ return;
+ }
+ catch (Exception other) {
+ Assert.fail("Wrong exception raised for file not found",other);
+ }
+ Assert.fail("Expected to raise a FileNotFoundException");
+ }
}
+