commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r520079 - in /jakarta/commons/proper/vfs/trunk/core: pom.xml src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java src/test/java/org/apache/commons/vfs/RunTest.java
Date Mon, 19 Mar 2007 20:17:43 GMT
Author: imario
Date: Mon Mar 19 13:17:42 2007
New Revision: 520079

URL: http://svn.apache.org/viewvc?view=rev&rev=520079
Log:
VFS-107: finally avoid reading jsch/sftp files into the memory, looks good with jsch 0.1.31

Modified:
    jakarta/commons/proper/vfs/trunk/core/pom.xml
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
    jakarta/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java

Modified: jakarta/commons/proper/vfs/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/pom.xml?view=diff&rev=520079&r1=520078&r2=520079
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/pom.xml (original)
+++ jakarta/commons/proper/vfs/trunk/core/pom.xml Mon Mar 19 13:17:42 2007
@@ -94,7 +94,7 @@
 		<dependency>
 			<groupId>com.jcraft</groupId>
 			<artifactId>jsch</artifactId>
-			<version>0.1.23</version>
+			<version>0.1.31</version>
 			<optional>true</optional>
 		</dependency>
 		<dependency>

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java?view=diff&rev=520079&r1=520078&r2=520079
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
Mon Mar 19 13:17:42 2007
@@ -29,9 +29,10 @@
 import org.apache.commons.vfs.VFS;
 import org.apache.commons.vfs.provider.AbstractFileObject;
 import org.apache.commons.vfs.provider.UriParser;
+import org.apache.commons.vfs.util.FileObjectUtils;
+import org.apache.commons.vfs.util.MonitorInputStream;
 import org.apache.commons.vfs.util.MonitorOutputStream;
 import org.apache.commons.vfs.util.RandomAccessMode;
-import org.apache.commons.vfs.util.FileObjectUtils;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -348,6 +349,7 @@
 			// hmmm - using the in memory method is soooo much faster ...
 			// TODO - Don't read the entire file into memory. Use the
 			// stream-based methods on ChannelSftp once they work properly final
+			// .... no stream based method with resume???
 			ByteArrayOutputStream outstr = new ByteArrayOutputStream();
 			try
 			{
@@ -383,15 +385,19 @@
 
 				// TODO - Don't read the entire file into memory. Use the
 				// stream-based methods on ChannelSftp once they work properly
+
+				/*
 				final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
 				channel.get(relPath, outstr);
 				outstr.close();
 				return new ByteArrayInputStream(outstr.toByteArray());
+				*/
+				return new SftpInputStream(channel, channel.get(relPath));
 
 			}
 			finally
 			{
-				fileSystem.putChannel(channel);
+//				fileSystem.putChannel(channel);
 			}
 		}
 	}
@@ -403,8 +409,35 @@
 	{
 		// TODO - Don't write the entire file into memory. Use the stream-based
 		// methods on ChannelSftp once the work properly
+		/*
 		final ChannelSftp channel = fileSystem.getChannel();
 		return new SftpOutputStream(channel);
+		*/
+
+		final ChannelSftp channel = fileSystem.getChannel();
+		return new SftpOutputStream(channel, channel.put(relPath));
+	}
+
+	/**
+	 * An InputStream that monitors for end-of-file.
+	 */
+	private class SftpInputStream extends MonitorInputStream
+	{
+		private final ChannelSftp channel;
+
+		public SftpInputStream(final ChannelSftp channel, final InputStream in)
+		{
+			super(in);
+			this.channel = channel;
+		}
+
+		/**
+		 * Called after the stream has been closed.
+		 */
+		protected void onClose() throws IOException
+		{
+			fileSystem.putChannel(channel);
+		}
 	}
 
 	/**
@@ -415,9 +448,9 @@
 	{
 		private final ChannelSftp channel;
 
-		public SftpOutputStream(final ChannelSftp channel)
+		public SftpOutputStream(final ChannelSftp channel, OutputStream out)
 		{
-			super(new ByteArrayOutputStream());
+			super(out);
 			this.channel = channel;
 		}
 
@@ -426,6 +459,7 @@
 		 */
 		protected void onClose() throws IOException
 		{
+			/*
 			try
 			{
 				final ByteArrayOutputStream outstr = (ByteArrayOutputStream) out;
@@ -437,9 +471,11 @@
 				throw new FileSystemException(e);
 			}
 			finally
+			*/
 			{
 				fileSystem.putChannel(channel);
 			}
 		}
 	}
+
 }

Modified: jakarta/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java?view=diff&rev=520079&r1=520078&r2=520079
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java
Mon Mar 19 13:17:42 2007
@@ -19,27 +19,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestResult;
-import org.apache.commons.vfs.provider.http.test.HttpProviderTestCase;
-import org.apache.commons.vfs.provider.jar.test.JarProviderTestCase;
-import org.apache.commons.vfs.provider.jar.test.NestedJarTestCase;
 import org.apache.commons.vfs.provider.sftp.test.SftpProviderTestCase;
-import org.apache.commons.vfs.provider.tar.test.NestedTarTestCase;
-import org.apache.commons.vfs.provider.tar.test.NestedTbz2TestCase;
-import org.apache.commons.vfs.provider.tar.test.NestedTgzTestCase;
-import org.apache.commons.vfs.provider.tar.test.TarProviderTestCase;
-import org.apache.commons.vfs.provider.tar.test.Tbz2ProviderTestCase;
-import org.apache.commons.vfs.provider.tar.test.TgzProviderTestCase;
-import org.apache.commons.vfs.provider.zip.test.NestedZipTestCase;
-import org.apache.commons.vfs.provider.zip.test.ZipProviderTestCase;
-import org.apache.commons.vfs.provider.ftp.test.FtpProviderTestCase;
-import org.apache.commons.vfs.provider.local.test.LocalProviderTestCase;
-import org.apache.commons.vfs.provider.res.test.ResourceProviderTestCase;
-import org.apache.commons.vfs.provider.temp.test.TemporaryProviderTestCase;
-import org.apache.commons.vfs.provider.url.test.UrlProviderTestCase;
-import org.apache.commons.vfs.provider.url.test.UrlProviderHttpTestCase;
-import org.apache.commons.vfs.provider.test.VirtualProviderTestCase;
-import org.apache.commons.vfs.provider.test.GenericFileNameTestCase;
-import org.apache.commons.vfs.provider.ram.test.RamProviderTestCase;
 
 import java.util.Properties;
 
@@ -61,11 +41,11 @@
 		props.setProperty("test.webdav.uri",
 				"webdav://vfsusr:vfs%2f%25\\te:st@172.16.110.129/vfstest");
 		props.setProperty("test.sftp.uri",
-				"sftp://vfsusr:vfs%2f%25\\te:st@172.16.110.129/vfstest");
+				"sftp://vfsusr:vfs%2f%25\\te:st@192.168.72.128/vfstest");
 
 		Test tests[] = new Test[]
 		{
-			RamProviderTestCase.suite(),
+			// RamProviderTestCase.suite(),
 
 			// SmbProviderTestCase.suite(),
 
@@ -84,7 +64,7 @@
 
 		// WebdavProviderTestCase.suite(),
 
-		// SftpProviderTestCase.suite(),
+		SftpProviderTestCase.suite(),
 
 		// JarProviderTestCase.suite(),
 //		NestedJarTestCase.suite(),



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


Mime
View raw message