commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Watters <>
Subject [vfs] vsf2.2.0: non-ascii chars in file name are not handled by createFolder()
Date Mon, 16 Mar 2015 11:07:33 GMT

I am using*commons-vfs2-2.0.jar* and am running into problems when file 
names contain non-ascii characters. According to this has been 
fixed/shipped in 2.0. In my environment I am able to create such file 
names when using ftp on the command-line (Red Hat Enterprise Linux 
Server release 5.8 (Tikanga)).

When I execute the following sample code, I get the output shown below.

public class FtpTest {
     public static void main(String[] args) throws FileSystemException
         String host="hhh";
         String user = "uuu";
         String password = "ppp";
         String destDir = "/tmp";
         FileSystemOptions opts = new FileSystemOptions();
FtpFileSystemConfigBuilder.getInstance().setControlEncoding(opts, "UTF-8");

         DefaultFileSystemManager manager = new DefaultFileSystemManager();
         manager.addProvider("ftp", new FtpFileProvider());

         String root="ftp://"+user+":"+password+"@"+host+destDir;
         // Specify a number of directories that should be created under 
         String[] lRoots = new String[4];
         lRoots[0]= root+"/ftpDebug";
         lRoots[1]= root+"/ftp\u7684Debug";  // insert a non-ascii char
         lRoots[2]= root+"/ftp\u7685Debug";  // insert a different 
non-ascii char
         lRoots[3]= root+"/ftp\u7684Debug";  // insert the same 
non-ascii char

         // Verify the ControlEncoding
         System.out.println("ControlEncoding is 

         int dirCount=0;
         for (String lRoot: lRoots) {
             System.out.println(dirCount+") Process directory ["+lRoot+"]");
             FileObject newDir = manager.resolveFile(lRoot, opts);
             if (!newDir.exists()) {
                 try {
                     System.out.println(dirCount+") "+lRoot+" ::Dir Does 
Not Exist so Create It ");
                     if (newDir.exists())
                         System.out.println(dirCount+") "+lRoot+" 
::Creation Successful ");
                         System.out.println(dirCount+") "+lRoot+" 
::Creation Fails ");
                 catch (Exception ex) {
                     System.out.println(dirCount+") "+lRoot + " raised 
                 System.out.println(dirCount+") "+lRoot+" ::Dir Already 
Exists ");

The output from running the above is:-

ControlEncoding is UTF-8
0) Process directory [ftp://uuu:ppp@hhh/tmp/ftpDebug]
0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Dir Does Not Exist so Create It
0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Creation Successful
1) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Creation Successful
2) Process directory [ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug]
2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug ::Dir Does Not Exist so Create It
2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug raised 
org.apache.commons.vfs2.FileSystemException: Could not create folder 
3) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
3) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
3) ftp://uuu:ppp@hhh/tmp/ftpªDebug raised 
org.apache.commons.vfs2.FileSystemException: Could not create folder 

After step 1) I see a directory called*/tmp/ftp?Debug*.
I think this is causing the subsequent creation problem in step 2) and 
step 3).
When a directory such as "*ftp\u7684Debug*" does exist, then *exists*() 
returns the correct result of true, but *createFolder*() creates a 
directory with name "*ftp?Debug*".

Thanks in advance

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message