TAVERNA-988: Use Path instead of File
NOTE: The recent files are not actually loaded or saved, as
that (de)serialization code was commented out
(TAVERNA-65)
diff --git a/taverna-file-impl/src/main/java/org/apache/taverna/workbench/file/impl/menu/FileOpenRecentMenuAction.java b/taverna-file-impl/src/main/java/org/apache/taverna/workbench/file/impl/menu/FileOpenRecentMenuAction.java
index 73d5c34..8c2314b 100644
--- a/taverna-file-impl/src/main/java/org/apache/taverna/workbench/file/impl/menu/FileOpenRecentMenuAction.java
+++ b/taverna-file-impl/src/main/java/org/apache/taverna/workbench/file/impl/menu/FileOpenRecentMenuAction.java
@@ -30,17 +30,15 @@
import java.awt.Component;
import java.awt.event.ActionEvent;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -48,8 +46,11 @@
import javax.swing.JMenu;
import javax.swing.JMenuItem;
+import org.apache.log4j.Logger;
+import org.apache.taverna.configuration.app.ApplicationConfiguration;
import org.apache.taverna.lang.observer.Observable;
import org.apache.taverna.lang.observer.Observer;
+import org.apache.taverna.scufl2.api.container.WorkflowBundle;
import org.apache.taverna.ui.menu.AbstractMenuCustom;
import org.apache.taverna.workbench.file.FileManager;
import org.apache.taverna.workbench.file.FileType;
@@ -59,15 +60,10 @@
import org.apache.taverna.workbench.file.events.OpenedDataflowEvent;
import org.apache.taverna.workbench.file.events.SavedDataflowEvent;
import org.apache.taverna.workbench.file.exceptions.OpenException;
-
-import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
-import org.apache.taverna.configuration.app.ApplicationConfiguration;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-
public class FileOpenRecentMenuAction extends AbstractMenuCustom implements
Observer<FileManagerEvent> {
public static final URI RECENT_URI = URI
@@ -154,11 +150,10 @@
}
protected synchronized void loadRecent() {
- File confDir = new File(applicationConfiguration.getApplicationHomeDir(), CONF);
- confDir.mkdir();
- File recentFile = new File(confDir, RECENT_WORKFLOWS_XML);
- if (!recentFile.isFile())
+ Path recentFile = recentFilePath();
+ if (! Files.exists(recentFile)) {
return;
+ }
try {
loadRecent(recentFile);
} catch (JDOMException|IOException e) {
@@ -167,17 +162,21 @@
}
}
- private void loadRecent(File recentFile) throws FileNotFoundException,
+ private Path recentFilePath() {
+ return applicationConfiguration.getApplicationHomeDir().resolve(CONF).resolve(RECENT_WORKFLOWS_XML);
+ }
+
+ private void loadRecent(Path recentFile) throws FileNotFoundException,
IOException, JDOMException {
SAXBuilder builder = new SAXBuilder();
@SuppressWarnings("unused")
Document document;
- try (InputStream fileInputStream = new BufferedInputStream(
- new FileInputStream(recentFile))) {
+ try (InputStream fileInputStream = Files.newInputStream(recentFile)) {
document = builder.build(fileInputStream);
}
synchronized (recents) {
recents.clear();
+ // TAVERNA-65 - temporarily disabled
//RecentDeserializer deserialiser = new RecentDeserializer();
try {
// recents.addAll(deserialiser.deserializeRecent(document
@@ -190,11 +189,9 @@
}
protected synchronized void saveRecent() {
- File confDir = new File(applicationConfiguration.getApplicationHomeDir(), CONF);
- confDir.mkdir();
- File recentFile = new File(confDir, RECENT_WORKFLOWS_XML);
-
+ Path recentFile = recentFilePath();
try {
+ Files.createDirectories(recentFile.getParent());
saveRecent(recentFile);
// } catch (JDOMException e) {
// logger.warn("Could not generate XML for recent workflows to file "
@@ -205,7 +202,7 @@
}
}
- private void saveRecent(File recentFile) throws FileNotFoundException,
+ private void saveRecent(Path recentFile) throws FileNotFoundException,
IOException {
// RecentSerializer serializer = new RecentSerializer();
// XMLOutputter outputter = new XMLOutputter();
@@ -217,8 +214,7 @@
recents.subList(MAX_ITEMS, recents.size()).clear();
// serializedRecent = serializer.serializeRecent(recents);
}
- try (OutputStream outputStream = new BufferedOutputStream(
- new FileOutputStream(recentFile))) {
+ try (OutputStream outputStream = Files.newOutputStream(recentFile)) {
// outputter.output(serializedRecent, outputStream);
}
}