test/java/lang/instrument/BootClassPath/Setup.java

Print this page
rev 3509 : 7021209: convert lang, math, util to use try-with-resources
Reviewed-by: XXX


  45         }
  46         String workDir = args[0];
  47         String premainClass = args[1];
  48 
  49         String manifestFile = workDir + fileSeparator + "MANIFEST.MF";
  50         String bootClassPath = "boot" + suffix();
  51 
  52         String bootDir = workDir + fileSeparator + bootClassPath;
  53 
  54 
  55         /*
  56          * Create sub-directory
  57          */
  58         File f = new File(bootDir);
  59         f.mkdir();
  60 
  61         /*
  62          * Create manifest file with Boot-Class-Path encoding the
  63          * sub-directory name.
  64          */
  65         FileOutputStream out = new FileOutputStream(manifestFile);
  66         out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
  67 
  68         byte[] premainBytes = ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");

  69         out.write(premainBytes);
  70 
  71         out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
  72 
  73         byte[] value = bootClassPath.getBytes("UTF-8");
  74         for (int i=0; i<value.length; i++) {
  75             int v = (int)value[i];
  76             if (v < 0) v += 256;
  77             byte[] escaped =  ("%" + Integer.toHexString(v)).getBytes("UTF-8");

  78             out.write(escaped);
  79         }
  80         out.write( "\n\n".getBytes("UTF-8") );
  81         out.close();
  82 
  83         /*
  84          * Write the name of the boot dir to "boot.dir"
  85          */
  86         f = new File(workDir + fileSeparator + "boot.dir");
  87         out = new FileOutputStream(f);
  88         out.write(bootDir.getBytes(defaultEncoding));
  89         out.close();
  90     }
  91 
  92     /* ported from test/sun/tools/launcher/UnicodeTest.java */
  93 
  94     private static final String fileSeparator = System.getProperty("file.separator");
  95     private static final String osName = System.getProperty("os.name");
  96     private static final String defaultEncoding = Charset.defaultCharset().name();
  97 
  98     // language names taken from java.util.Locale.getDisplayLanguage for the respective language
  99     private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";
 100     private static final String s_chinese = "\u4e2d\u6587";
 101     private static final String t_chinese = "\u4e2d\u6587";
 102     private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";
 103     private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";
 104     private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";
 105     private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
 106     private static final String japanese = "\u65e5\u672c\u8a9e";
 107     private static final String korean = "\ud55c\uad6d\uc5b4";
 108     private static final String lithuanian = "Lietuvi\u0173";
 109     private static final String czech = "\u010de\u0161tina";




  45         }
  46         String workDir = args[0];
  47         String premainClass = args[1];
  48 
  49         String manifestFile = workDir + fileSeparator + "MANIFEST.MF";
  50         String bootClassPath = "boot" + suffix();
  51 
  52         String bootDir = workDir + fileSeparator + bootClassPath;
  53 
  54 
  55         /*
  56          * Create sub-directory
  57          */
  58         File f = new File(bootDir);
  59         f.mkdir();
  60 
  61         /*
  62          * Create manifest file with Boot-Class-Path encoding the
  63          * sub-directory name.
  64          */
  65         try (FileOutputStream out = new FileOutputStream(manifestFile)) {
  66             out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
  67 
  68             byte[] premainBytes =
  69                 ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");
  70             out.write(premainBytes);
  71 
  72             out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
  73 
  74             byte[] value = bootClassPath.getBytes("UTF-8");
  75             for (int i=0; i<value.length; i++) {
  76                 int v = (int)value[i];
  77                 if (v < 0) v += 256;
  78                 byte[] escaped =
  79                     ("%" + Integer.toHexString(v)).getBytes("UTF-8");
  80                 out.write(escaped);
  81             }
  82             out.write( "\n\n".getBytes("UTF-8") );
  83         }
  84 
  85         /*
  86          * Write the name of the boot dir to "boot.dir"
  87          */
  88         f = new File(workDir + fileSeparator + "boot.dir");
  89         try (FileOutputStream out = new FileOutputStream(f)) {
  90             out.write(bootDir.getBytes(defaultEncoding));
  91         }
  92     }
  93 
  94     /* ported from test/sun/tools/launcher/UnicodeTest.java */
  95 
  96     private static final String fileSeparator = System.getProperty("file.separator");
  97     private static final String osName = System.getProperty("os.name");
  98     private static final String defaultEncoding = Charset.defaultCharset().name();
  99 
 100     // language names taken from java.util.Locale.getDisplayLanguage for the respective language
 101     private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";
 102     private static final String s_chinese = "\u4e2d\u6587";
 103     private static final String t_chinese = "\u4e2d\u6587";
 104     private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";
 105     private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";
 106     private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";
 107     private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
 108     private static final String japanese = "\u65e5\u672c\u8a9e";
 109     private static final String korean = "\ud55c\uad6d\uc5b4";
 110     private static final String lithuanian = "Lietuvi\u0173";
 111     private static final String czech = "\u010de\u0161tina";