Author: imario
Date: Fri Mar 25 11:43:39 2005
New Revision: 159052

URL: http://svn.apache.org/viewcvs?view=rev&rev=159052
Log:
refactored filename parsing
tests passed, though manual testing needet

Now every FileProvider can handle its own set of reserved characters through 
the *FileNameParser.
This encoding is immediatley reflected in the FileName.


Modified:
    
jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java

Modified: 
jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java?view=diff&r1=159051&r2=159052
==============================================================================
--- 
jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
 (original)
+++ 
jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
 Fri Mar 25 11:43:39 2005
@@ -22,8 +22,11 @@
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.RandomAccessContent;
 import org.apache.commons.vfs.provider.AbstractFileObject;
+import org.apache.commons.vfs.provider.UriParser;
 import org.apache.commons.vfs.util.MonitorOutputStream;
+import org.apache.commons.vfs.util.RandomAccessMode;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -39,7 +42,7 @@
  * An SFTP file.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision$ $Date$
+ * @version $Revision: 1.12 $ $Date$
  */
 public class SftpFileObject
     extends AbstractFileObject
@@ -101,7 +104,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            attrs = channel.stat(getName().getPath());
+            attrs = channel.stat(getName().getPathDecoded());
         }
         catch (final SftpException e)
         {
@@ -129,7 +132,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            channel.mkdir(getName().getPath());
+            channel.mkdir(getName().getPathDecoded());
         }
         finally
         {
@@ -164,7 +167,7 @@
             int newMTime = (int) (modtime / 1000L);
 
             attrs.setACMODTIME(attrs.getATime(), newMTime);
-            channel.setStat(getName().getPath(), attrs);
+            channel.setStat(getName().getPathDecoded(), attrs);
         }
         finally
         {
@@ -183,11 +186,11 @@
         {
             if (getType() == FileType.FILE)
             {
-                channel.rm(getName().getPath());
+                channel.rm(getName().getPathDecoded());
             }
             else
             {
-                channel.rmdir(getName().getPath());
+                channel.rmdir(getName().getPathDecoded());
             }
         }
         finally
@@ -204,7 +207,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            channel.rename(getName().getPath(), newfile.getName().getPath());
+            channel.rename(getName().getPathDecoded(), 
newfile.getName().getPathDecoded());
         }
         finally
         {
@@ -223,7 +226,7 @@
         final ChannelSftp channel = fileSystem.getChannel();
         try
         {
-            vector = channel.ls(getName().getPath());
+            vector = channel.ls(getName().getPathDecoded());
         }
         finally
         {
@@ -253,7 +256,7 @@
             }
             children.add(name);
         }
-        return (String[]) children.toArray(new String[children.size()]);
+        return UriParser.encode((String[]) children.toArray(new 
String[children.size()]));
     }
 
     /**
@@ -269,6 +272,46 @@
         return attrs.getSize();
     }
 
+    protected RandomAccessContent doGetRandomAccessContent(final 
RandomAccessMode mode) throws Exception
+    {
+        return new SftpRandomAccessContent(this, mode);
+    }
+    
+    /**
+     * Creates an input stream to read the file content from.
+     */
+    InputStream getInputStream(long filePointer) throws IOException
+    {
+        throw new UnsupportedOperationException("Implemented. Yes. But have to 
wait for jsch release :-)");
+        /*
+        final ChannelSftp channel = fileSystem.getChannel();
+        try
+        {
+            // return channel.get(getName().getPath());
+            // 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 ByteArrayOutputStream outstr = new ByteArrayOutputStream();
+            try
+            {
+                channel.get(getName().getPathDecoded(), outstr, null, 
ChannelSftp.RESUME, filePointer);
+            }
+            catch (SftpException e)
+            {
+                throw new FileSystemException(e);
+            }
+            outstr.close();
+            return new ByteArrayInputStream(outstr.toByteArray());
+
+        }
+        finally
+        {
+            fileSystem.putChannel(channel);
+        }
+        */
+    }
+
     /**
      * Creates an input stream to read the file content from.
      */
@@ -284,7 +327,7 @@
             // 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(getName().getPath(), outstr);
+            channel.get(getName().getPathDecoded(), outstr);
             outstr.close();
             return new ByteArrayInputStream(outstr.toByteArray());
 
@@ -332,7 +375,7 @@
             {
                 final ByteArrayOutputStream outstr = (ByteArrayOutputStream) 
out;
                 channel.put(new ByteArrayInputStream(outstr.toByteArray()),
-                    getName().getPath());
+                    getName().getPathDecoded());
             }
             catch (final SftpException e)
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to