diff options
author | Michael Valenta | 2003-07-15 18:08:19 +0000 |
---|---|---|
committer | Michael Valenta | 2003-07-15 18:08:19 +0000 |
commit | 108804c75833c16ef9ff8a7da4000e0e841bef3a (patch) | |
tree | c04e4b4018e9f7bce546d37ded49a93e82db2283 | |
parent | 1629fbe4629e4344791534cf6b13d0434b10b6e4 (diff) | |
download | eclipse.platform.team-108804c75833c16ef9ff8a7da4000e0e841bef3a.tar.gz eclipse.platform.team-108804c75833c16ef9ff8a7da4000e0e841bef3a.tar.xz eclipse.platform.team-108804c75833c16ef9ff8a7da4000e0e841bef3a.zip |
Streams were left open in some cases but now are not
-rw-r--r-- | bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/ContentComparisonCriteria.java | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/ContentComparisonCriteria.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/ContentComparisonCriteria.java index 6f081bff2..2ffa825b5 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/ContentComparisonCriteria.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/ContentComparisonCriteria.java @@ -65,10 +65,27 @@ public class ContentComparisonCriteria extends ComparisonCriteria { return true; } - return contentsEqual( - getContents(e1, Policy.subMonitorFor(monitor, 45)), - getContents(e2, Policy.subMonitorFor(monitor, 45)), - shouldIgnoreWhitespace()); + InputStream is1 = null; + InputStream is2 = null; + try { + is1 = getContents(e1, Policy.subMonitorFor(monitor, 45)); + is2 = getContents(e2, Policy.subMonitorFor(monitor, 45)); + return contentsEqual(is1, is2, shouldIgnoreWhitespace()); + } finally { + try { + try { + if (is1 != null) { + is1.close(); + } + } finally { + if (is2 != null) { + is2.close(); + } + } + } catch (IOException e) { + // Ignore + } + } } finally { monitor.done(); } @@ -86,13 +103,13 @@ public class ContentComparisonCriteria extends ComparisonCriteria { * @return <code>true</code> if content is equal */ private boolean contentsEqual(InputStream is1, InputStream is2, boolean ignoreWhitespace) { - if (is1 == is2) - return true; - - if (is1 == null && is2 == null) // no byte contents - return true; - try { + if (is1 == is2) + return true; + + if (is1 == null && is2 == null) // no byte contents + return true; + if (is1 == null || is2 == null) // only one has contents return false; @@ -109,17 +126,18 @@ public class ContentComparisonCriteria extends ComparisonCriteria { } } catch (IOException ex) { } finally { - if (is1 != null) { - try { - is1.close(); - } catch (IOException ex) { - } - } - if (is2 != null) { + try { try { - is2.close(); - } catch (IOException ex) { + if (is1 != null) { + is1.close(); + } + } finally { + if (is2 != null) { + is2.close(); + } } + } catch (IOException e) { + // Ignore } } return false; @@ -131,18 +149,18 @@ public class ContentComparisonCriteria extends ComparisonCriteria { } private InputStream getContents(Object resource, IProgressMonitor monitor) throws TeamException { - try { - if (resource instanceof IStorage) { - return new BufferedInputStream(((IStorage) resource).getContents()); - } else if(resource instanceof IRemoteResource) { - IRemoteResource remote = (IRemoteResource)resource; - if (!remote.isContainer()) { - return new BufferedInputStream(remote.getContents(monitor)); - } + try { + if (resource instanceof IStorage) { + return new BufferedInputStream(((IStorage) resource).getContents()); + } else if(resource instanceof IRemoteResource) { + IRemoteResource remote = (IRemoteResource)resource; + if (!remote.isContainer()) { + return new BufferedInputStream(remote.getContents(monitor)); } - return null; - } catch (CoreException e) { - throw TeamException.asTeamException(e); } + return null; + } catch (CoreException e) { + throw TeamException.asTeamException(e); } + } } |