1/* 2 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* @test 25 @bug 4039597 26 @summary Check that pathnames containing double-byte characters are not 27 corrupted by win32 path processing 28 @author Mark Reinhold 29*/ 30 31import java.io.*; 32 33 34public class SJIS { 35 36 private static void rm(File f) { 37 if (!f.delete()) throw new RuntimeException("Can't delete " + f); 38 } 39 40 private static void touch(File f) throws IOException { 41 OutputStream o = new FileOutputStream(f); 42 o.close(); 43 } 44 45 public static void main(String[] args) throws Exception { 46 47 /* This test is only valid on win32 systems 48 that use the SJIS encoding */ 49 if (File.separatorChar != '\\') return; 50 String enc = System.getProperty("file.encoding"); 51 if ((enc == null) || !enc.equals("SJIS")) return; 52 53 File f = new File("\u30BD"); 54 if (f.exists()) rm(f); 55 56 System.err.println(f.getCanonicalPath()); 57 touch(f); 58 System.err.println(f.getCanonicalPath()); 59 60 rm(f); 61 62 if (!f.mkdir()) { 63 throw new Exception("Can't create directory " + f); 64 } 65 File f2 = new File(f, "\u30BD"); 66 System.err.println(f2.getCanonicalPath()); 67 touch(f2); 68 String cfn = f2.getCanonicalPath(); 69 if (!(new File(cfn)).exists()) { 70 throw new Exception(cfn + " not found"); 71 } 72 73 File d = new File("."); 74 String[] fs = d.list(); 75 if (fs == null) System.err.println("No files listed"); 76 for (int i = 0; i < fs.length; i++) { 77 System.err.println(fs[i]); 78 } 79 80 } 81 82} 83