1 import java.io.*; 2 import jcifs.smb.*; 3 import jcifs.util.*; 4 5 public class TestUnicode { 6 static SmbFile dir; 7 8 public static void mkobj( String name ) throws Exception { 9 int r = (int)(Math.random() * 100.0); 10 if( r < 50 ) { 11 SmbFile d = new SmbFile( dir.getParent(), dir.getName() + "/" + name ); 12 d.mkdir(); 13 if( r < 15 ) { 14 dir = d; 15 } 16 } else { 17 SmbFileOutputStream out = new SmbFileOutputStream( dir.getParent() + "/" + dir.getName() + "/" + name ); 18 out.close(); 19 } 20 } 21 22 public static void main( String argv[] ) throws Exception { 23 if( argv.length < 1 ) { 24 throw new IllegalArgumentException ( "Must provide path to directory in which to run test" ); 25 } 26 FileInputStream in = new FileInputStream( "data" ); 27 byte[] b = new byte[4096]; 28 int n = in.read( b ); 29 String data = new String ( b, 0, n, "UTF-8" ); 30 char[] d = data.toCharArray(); 31 32 dir = new SmbFile( argv[0] + "/TestUnicode" ); 33 try { 34 dir.delete(); 35 } catch( SmbException se ) { 36 se.printStackTrace(); 37 } 38 dir.mkdir(); 39 40 int i, s, max = 8; 41 for( i = s = 0; i < d.length; i++ ) { 42 switch (d[i]) { 43 case '"': case '/': case '\\': case '[': case ']': 44 case ':': case '|': case '<': case '>': case '=': 45 case ';': case ',': case '*': case '?': case '\n': 46 d[i] = '_'; 47 } 48 if(Character.isWhitespace( d[i] )) { 49 if( i == s ) { 50 s++; 51 } 52 if( i > (s + max)) { 53 String name = new String ( d, s, i - s ); 54 mkobj( name ); 55 s = i + 1; 56 } 57 } 58 } 59 } 60 } 61 | Popular Tags |