jdk/test/tools/launcher/CreatePlatformFile.java
changeset 11865 8dc106e1925e
parent 11864 116173ff7d77
parent 11746 6c805d8ed4e5
child 11866 dc9c7a2df80e
equal deleted inserted replaced
11864:116173ff7d77 11865:8dc106e1925e
     1 /*
       
     2  * Copyright (c) 2002, 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 /*
       
    25  *
       
    26  *
       
    27  * This class is used by test i18nTest.sh
       
    28  *
       
    29  * Class to create various i18n Hello World Java source files using
       
    30  * the platform's default encoding of a non-ASCII name; create plain
       
    31  * ASCII Hello World if the platform's default is charset is US-ASCII.
       
    32  */
       
    33 
       
    34 import java.io.PrintWriter;
       
    35 import java.io.FileOutputStream;
       
    36 
       
    37 public class CreatePlatformFile {
       
    38     public static void main(String argv[])  {
       
    39         String fileSep = System.getProperty("file.separator");
       
    40         String defaultEncoding = System.getProperty("file.encoding");
       
    41 
       
    42         if(defaultEncoding == null) {
       
    43             System.err.println("Default encoding not found; Error.");
       
    44             return;
       
    45         }
       
    46 
       
    47         if (defaultEncoding.equals("Cp1252") ) {
       
    48             // "HelloWorld" with an accented e
       
    49             String fileName = "i18nH\u00e9lloWorld.java";
       
    50             try {
       
    51                 PrintWriter pw = new PrintWriter(new FileOutputStream("."+fileSep+fileName));
       
    52                 pw.println("public class i18nH\u00e9lloWorld {");
       
    53                 pw.println("    public static void main(String [] argv) {");
       
    54                 pw.println("        System.out.println(\"Hello Cp1252 World\");");
       
    55                 pw.println("    }");
       
    56                 pw.println("}");
       
    57                 pw.flush();
       
    58                 pw.close();
       
    59             }
       
    60             catch (java.io.FileNotFoundException e) {
       
    61                 System.err.println("Problem opening file; test fails");
       
    62             }
       
    63 
       
    64         } else {
       
    65             // ASCII "HelloWorld"
       
    66             String fileName = "i18nHelloWorld.java";
       
    67             try {
       
    68                 PrintWriter pw = new PrintWriter(new FileOutputStream("."+fileSep+fileName));
       
    69                 pw.println("public class i18nHelloWorld {");
       
    70                 pw.println("    public static void main(String [] argv) {");
       
    71                 pw.println("        System.out.println(\"Warning: US-ASCII assumed; filenames with\");");
       
    72                 pw.println("        System.out.println(\"non-ASCII characters will not be tested\");");
       
    73                 pw.println("    }");
       
    74                 pw.println("}");
       
    75                 pw.flush();
       
    76                 pw.close();
       
    77             }
       
    78             catch (java.io.FileNotFoundException e) {
       
    79                 System.err.println("Problem opening file; test fails");
       
    80             }
       
    81         }
       
    82     }
       
    83 }