diff options
author | Tomasz Zarna | 2017-06-02 20:17:08 +0000 |
---|---|---|
committer | Tomasz Zarna | 2017-06-02 20:17:08 +0000 |
commit | 1d36545be9f4939c6f1e1310aa2d2fc32f3d2aac (patch) | |
tree | 66ae44642d55476cda5ff460c713f14c23c1795c | |
parent | 293e9929537bc7b33959eee01e29d6543c12f7a8 (diff) | |
download | org.eclipse.mylyn.tasks-1d36545be9f4939c6f1e1310aa2d2fc32f3d2aac.tar.gz org.eclipse.mylyn.tasks-1d36545be9f4939c6f1e1310aa2d2fc32f3d2aac.tar.xz org.eclipse.mylyn.tasks-1d36545be9f4939c6f1e1310aa2d2fc32f3d2aac.zip |
use try-with-resources statement in TaskDataStore
Change-Id: I3ee74cf81e76aec0b5441d82e22574397db194ea
-rw-r--r-- | org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataStore.java | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataStore.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataStore.java index 3345be4bc..82485ca5b 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataStore.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataStore.java @@ -111,20 +111,17 @@ public class TaskDataStore { } private TaskDataState readStateInternal(File file, boolean xml11) throws IOException, SAXException { - ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(file))); - try { + try (ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)))) { in.getNextEntry(); - // bug 268456: When TaskData that contains C0 control characters is written to disk using XML 1.0 reading it back - // in fails with a SAXException. The XML 1.1 standard allows C0 entities but fails if C1 entities. If C0 control - // characters are detected while parsing file as XML 1.0 a second attempt is made using XML 1.1. If the file contains + // bug 268456: When TaskData that contains C0 control characters is written to disk using XML 1.0 reading it back + // in fails with a SAXException. The XML 1.1 standard allows C0 entities but fails if C1 entities. If C0 control + // characters are detected while parsing file as XML 1.0 a second attempt is made using XML 1.1. If the file contains // C0 and C1 control characters reading will fail regardless. if (xml11) { return externalizer.readState(new Xml11InputStream(in)); } else { return externalizer.readState(in); } - } finally { - in.close(); } } @@ -157,16 +154,13 @@ public class TaskDataStore { private void writeState(File file, TaskDataState state) throws CoreException { try { - ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file))); - try { + try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { out.setMethod(ZipOutputStream.DEFLATED); ZipEntry entry = new ZipEntry(FILE_NAME_INTERNAL); out.putNextEntry(entry); externalizer.writeState(out, state); - } finally { - out.close(); } } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, "Error writing task data", //$NON-NLS-1$ |