You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/02/14 08:37:17 UTC

svn commit: r507426 - in /incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core: services/deployment/ContributionRepositoryImpl.java util/IOUtils.java

Author: rfeng
Date: Tue Feb 13 23:37:16 2007
New Revision: 507426

URL: http://svn.apache.org/viewvc?view=rev&rev=507426
Log:
Remove IOUtils and add the copy method in ContrbiutionRepositoryImpl

Removed:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/util/IOUtils.java
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java?view=diff&rev=507426&r1=507425&r2=507426
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java Tue Feb 13 23:37:16 2007
@@ -19,7 +19,10 @@
 
 package org.apache.tuscany.core.services.deployment;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -31,7 +34,7 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
-import org.apache.tuscany.core.util.IOUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.tuscany.spi.deployer.ContributionRepository;
 import org.osoa.sca.annotations.Property;
 
@@ -42,13 +45,13 @@
     /**
      * Constructor with repository root
      * 
-     * @param root
+     * @param repository
      */
-    public ContributionRepositoryImpl(@Property String root) throws IOException {
-        this.rootFile = new File(root);
+    public ContributionRepositoryImpl(@Property(name = "repository") String repository) throws IOException {
+        this.rootFile = new File(repository);
         FileUtils.forceMkdir(rootFile);
         if (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead()) {
-            throw new IOException("The root is not a directory: " + root);
+            throw new IOException("The root is not a directory: " + repository);
         }
     }
 
@@ -64,15 +67,32 @@
         return new File(rootFile, FilenameUtils.getName(contribution.toString()));
     }
 
-    public URL store(URI contribution, InputStream contributionStream) throws IOException {
-        // where the file should be stored in the repository
-        File location = mapToFile(contribution);
+    /**
+     * Write a specific source inputstream to a file on disk
+     * 
+     * @param source contents of the file to be written to disk
+     * @param target file to be written
+     * @throws IOException
+     */
+    public static void copy(InputStream source, File target) throws IOException {
+        BufferedOutputStream out = null;
+        BufferedInputStream in = null;
 
         try {
-            IOUtils.write(contributionStream, location);
+            out = new BufferedOutputStream(new FileOutputStream(target));
+            in = new BufferedInputStream(source);
+            IOUtils.copy(in, out);
         } finally {
-            IOUtils.closeQuietly(contributionStream);
+            IOUtils.closeQuietly(out);
+            IOUtils.closeQuietly(in);
         }
+    }
+
+    public URL store(URI contribution, InputStream contributionStream) throws IOException {
+        // where the file should be stored in the repository
+        File location = mapToFile(contribution);
+
+        copy(contributionStream, location);
 
         // add contribution to repositoryContent
         URL contributionURL = location.toURL();



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org