import java.awt.Color;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
try
{
format = new IdentifyFile().identify(openFile, protocol);
+ } catch (FileNotFoundException e0)
+ {
+ addError((protocol == DataSourceType.URL ? "File at URL" : "File")
+ + " '" + openFile + "' not found");
} catch (FileFormatException e1)
{
addError("Unknown file format for '" + openFile + "'");
private void colourAlignFrame(AlignFrame af, ColourSchemeI cs)
{
- try {
- SwingUtilities.invokeAndWait(new Runnable()
+ try
{
- @Override
- public void run()
+ SwingUtilities.invokeAndWait(new Runnable()
{
- // Note that cs == null removes colour scheme from af
- af.changeColour(cs);
- }
- }); } catch (Exception x) {
- Console.trace("Interrupted whilst waiting for colorAlignFrame action",x);
-
+ @Override
+ public void run()
+ {
+ // Note that cs == null removes colour scheme from af
+ af.changeColour(cs);
+ }
+ });
+ } catch (Exception x)
+ {
+ Console.trace("Interrupted whilst waiting for colorAlignFrame action",
+ x);
+
}
}
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
try
{
format = new IdentifyFile().identify(file, protocol);
- } catch (FileFormatException e1)
+ } catch (FileNotFoundException e)
{
- // TODO ?
+ Console.error("File at '" + file + "' not found", e);
+ } catch (FileFormatException e)
+ {
+ Console.error("File '" + file + "' format not recognised", e);
}
AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
try
{
format = new IdentifyFile().identify(file, protocol);
+ } catch (FileNotFoundException e)
+ {
+ Console.error("File at '" + file + "' not found", e);
} catch (FileFormatException e)
{
- // TODO what?
+ Console.error("File '" + file + "' format not recognised", e);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
+import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
try
{
format = new IdentifyFile().identify(text, DataSourceType.PASTE);
+ } catch (FileNotFoundException e0)
+ {
+ // this won't happen
} catch (FileFormatException e1)
{
// leave as null
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
try
{
format = new IdentifyFile().identify(url, DataSourceType.URL);
+ } catch (FileNotFoundException e)
+ {
+ jalview.bin.Console.error("URL '" + url + "' not found", e);
} catch (FileFormatException e)
{
- // TODO revise error handling, distinguish between
- // URL not found and response not valid
+ jalview.bin.Console.error(
+ "File at URL '" + url + "' format not recognised", e);
}
if (format == null)
* @throws IOException
*/
public FileParse(Object file, DataSourceType sourceType)
- throws MalformedURLException, IOException
+ throws MalformedURLException, FileNotFoundException, IOException
{
if (file instanceof File)
{
}
private void parse(File file, String fileStr, DataSourceType sourceType,
- boolean isFileObject) throws IOException
+ boolean isFileObject) throws FileNotFoundException, IOException
{
bytes = Platform.getFileBytes(file);
dataSourceType = sourceType;
error = false;
+ boolean filenotfound = false;
if (sourceType == DataSourceType.FILE)
{
String suffixLess = extractSuffix(fileStr);
if (suffixLess == null)
{
+ if (e instanceof FileNotFoundException)
+ {
+ errormessage = "File at URL '" + fileStr + "' not found";
+ filenotfound = true;
+ }
throw (e);
}
else
checkURLSource(suffixLess);
} catch (IOException e2)
{
- errormessage = "BAD URL WITH OR WITHOUT SUFFIX";
+ errormessage = "BAD URL WITH OR WITHOUT SUFFIX '" + fileStr
+ + "'";
+ if (e instanceof FileNotFoundException)
+ {
+ filenotfound = true;
+ }
throw (e); // just pass back original - everything was wrong.
}
}
if (dataIn == null || error)
{
// pass up the reason why we have no source to read from
+ if (filenotfound)
+ {
+ throw new FileNotFoundException(MessageManager
+ .formatMessage("label.url_not_found", new String[]
+ { errormessage }));
+ }
throw new IOException(MessageManager.formatMessage(
"exception.failed_to_read_data_from_source", new String[]
{ errormessage }));
package jalview.io;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Locale;
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);
{
throw new FileFormatException(parser.errormessage);
}
+ if (fnf != null)
+ {
+ throw (fnf);
+ }
throw new FileFormatException(emessage);
}
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(
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
+import java.io.FileNotFoundException;
+
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@Test(groups = { "Functional" }, dataProvider = "identifyFiles")
public void testIdentify(String data, FileFormatI expectedFileType)
- throws FileFormatException
+ throws FileFormatException, FileNotFoundException
{
DataSourceType protocol = DataSourceType.FILE;
IdentifyFile ider = new IdentifyFile();
* @throws FileFormatException
*/
@Test(groups = "Functional")
- public void testIdentify_featureFile() throws FileFormatException
+ public void testIdentify_featureFile()
+ throws FileFormatException, FileNotFoundException
{
IdentifyFile ider = new IdentifyFile();