portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r927983 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java
Date Fri, 26 Mar 2010 17:43:09 GMT
Author: woonsan
Date: Fri Mar 26 17:43:09 2010
New Revision: 927983

URL: http://svn.apache.org/viewvc?rev=927983&view=rev
Log:
JS2-1162: Closing stream resources

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java?rev=927983&r1=927982&r2=927983&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/site/PortalSiteManager.java
Fri Mar 26 17:43:09 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jetspeed.portlets.site;
 
-import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -40,6 +39,7 @@ import javax.swing.tree.DefaultMutableTr
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreeModel;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
@@ -1273,9 +1273,6 @@ public class PortalSiteManager extends A
                         final FileUpload upload = fileUpload;
                         final String userName = getPortletRequest()
                                 .getUserPrincipal().getName();
-                        String usrFolder;
-                        String fileType;
-                        String fileName;
                         String pathSeparator = System
                                 .getProperty("file.separator");
                         boolean copyIds = getCopyIdsOnImport();
@@ -1286,11 +1283,10 @@ public class PortalSiteManager extends A
                             {
                                 PageManager pageManager = getServiceLocator()
                                         .getPageManager();
-                                InputStream docStream = upload.getInputStream();
-                                fileName = upload.getClientFileName();
-                                fileType = fileExt(upload.getClientFileName());
+                                String fileName = upload.getClientFileName();
+                                String fileType = fileExt(upload.getClientFileName());
                                 cleanUserFolder(userName);
-                                usrFolder = getTempFolder(userName);
+                                String usrFolder = getTempFolder(userName);
                                 String destPath = node.getNodePath();
                                 upload.writeTo(new File(usrFolder
                                         + pathSeparator
@@ -1403,8 +1399,7 @@ public class PortalSiteManager extends A
                                         success = true;
                                     } else if (fileType.equalsIgnoreCase("zip"))
                                     {
-                                        unzipfile(fileName, usrFolder
-                                                + userName, pathSeparator);
+                                        unzipfile(fileName, StringUtils.removeEnd(usrFolder,
"/"), pathSeparator);
                                         folder = getServiceLocator()
                                                 .getCastorPageManager()
                                                 .getFolder(userName);
@@ -3633,20 +3628,33 @@ public class PortalSiteManager extends A
     {
         Enumeration entries;
         String filePath = "";
+        ZipFile zipFile = null;
+        
         try
         {
-            ZipFile zipFile = new ZipFile(destination + sepreator + file);
+            zipFile = new ZipFile(destination + sepreator + file);
             entries = zipFile.entries();
             while (entries.hasMoreElements())
             {
                 ZipEntry entry = (ZipEntry) entries.nextElement();
                 filePath = destination + sepreator + entry.getName();
                 createPath(filePath);
-                copyInputStream(
-                        zipFile.getInputStream(entry),
-                        new BufferedOutputStream(new FileOutputStream(filePath)));
+                
+                InputStream input = null;
+                OutputStream output = null;
+                
+                try
+                {
+                    input = zipFile.getInputStream(entry);
+                    output = new FileOutputStream(filePath);
+                    IOUtils.copy(input, output);
+                }
+                finally
+                {
+                    IOUtils.closeQuietly(output);
+                    IOUtils.closeQuietly(input);
+                }
             }
-            zipFile.close();
             return true;
         }
         catch (IOException ioe)
@@ -3654,6 +3662,19 @@ public class PortalSiteManager extends A
             log.error("Unexpected IO exception.", ioe);
             return false;
         }
+        finally
+        {
+            if (zipFile != null)
+            {
+                try
+                {
+                    zipFile.close();
+                }
+                catch (IOException ignore)
+                {
+                }
+            }
+        }
     }
 
     private void createPath(String filePath)



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message