Rework file close.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32662 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2011-12-09 11:01:33 +00:00
parent 0245b34542
commit 117b29439e

View File

@@ -69,11 +69,15 @@ public class CIFSContentComparator implements ContentComparator
return false; return false;
} }
InputStream rightIs = null;
InputStream leftIs = null;
try try
{ {
InputStream rightIs = new BufferedInputStream(new FileInputStream(newFile)); rightIs = new BufferedInputStream(new FileInputStream(newFile));
InputStream leftIs = existingContent.getContentInputStream(); leftIs = existingContent.getContentInputStream();
boolean retVal = EqualsHelper.binaryStreamEquals(leftIs, rightIs); boolean retVal = EqualsHelper.binaryStreamEquals(leftIs, rightIs);
rightIs = null;
leftIs = null;
if(logger.isDebugEnabled()) if(logger.isDebugEnabled())
{ {
@@ -83,9 +87,35 @@ public class CIFSContentComparator implements ContentComparator
} }
catch (IOException e) catch (IOException e)
{ {
logger.debug("Unable to compare contents", e); logger.debug("Unable to compare contents", e);
return false; return false;
} }
finally
{
if(leftIs != null)
{
try
{
leftIs.close();
}
catch (IOException e)
{
// Do nothing this is cleanup code
}
}
if(rightIs != null)
{
try
{
rightIs.close();
}
catch (IOException e)
{
// Do nothing this is cleanup code
}
}
}
} }
else else
{ {
@@ -109,18 +139,17 @@ public class CIFSContentComparator implements ContentComparator
logger.debug("comparing two project files size:" + existingContent.getSize() + ", and " + newFile.length()); logger.debug("comparing two project files size:" + existingContent.getSize() + ", and " + newFile.length());
} }
// if(existingContent.getSize() != newSize) if(existingContent.getSize() != newSize)
// { {
// logger.debug("project files are different size"); logger.debug("project files are different size");
// // Different size // Different size
// return false; return false;
// } }
ArrayList<InputStream> openStreams = new ArrayList<InputStream>();
/** /**
* Use POI to compare the content of the MPP file, exluding certain properties * Use POI to compare the content of the MPP file, exluding certain properties
*/ */
InputStream leftIs = null;
try try
{ {
Collection<String> excludes = new HashSet<String>(); Collection<String> excludes = new HashSet<String>();
@@ -128,11 +157,8 @@ public class CIFSContentComparator implements ContentComparator
excludes.add("Props12"); excludes.add("Props12");
excludes.add("Props9"); excludes.add("Props9");
InputStream leftIs = existingContent.getContentInputStream(); leftIs = existingContent.getContentInputStream();
openStreams.add(leftIs);
NPOIFSFileSystem fs2 = new NPOIFSFileSystem(leftIs); NPOIFSFileSystem fs2 = new NPOIFSFileSystem(leftIs);
openStreams.remove(0);
NPOIFSFileSystem fs1 = new NPOIFSFileSystem(newFile); NPOIFSFileSystem fs1 = new NPOIFSFileSystem(newFile);
DirectoryEntry de1 = fs1.getRoot(); DirectoryEntry de1 = fs1.getRoot();
@@ -161,15 +187,15 @@ public class CIFSContentComparator implements ContentComparator
} }
finally finally
{ {
for(InputStream stream : openStreams) if(leftIs != null)
{ {
try try
{ {
stream.close(); leftIs.close();
} }
catch (IOException e) catch (IOException e)
{ {
// Do nothing // Ignore
} }
} }
} }