langtools/make/src/classes/build/tools/symbolgenerator/Probe.java
changeset 31506 4e07f827a794
equal deleted inserted replaced
31505:98c52b994430 31506:4e07f827a794
       
     1 /*
       
     2  * Copyright (c) 2015, 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package build.tools.symbolgenerator;
       
    27 
       
    28 import java.io.BufferedInputStream;
       
    29 import java.io.ByteArrayOutputStream;
       
    30 import java.io.File;
       
    31 import java.io.FileOutputStream;
       
    32 import java.io.IOException;
       
    33 import java.io.InputStream;
       
    34 import java.io.OutputStream;
       
    35 import java.nio.charset.Charset;
       
    36 import java.util.EnumSet;
       
    37 
       
    38 import javax.tools.JavaCompiler;
       
    39 import javax.tools.JavaFileObject;
       
    40 import javax.tools.JavaFileObject.Kind;
       
    41 import javax.tools.StandardJavaFileManager;
       
    42 import javax.tools.StandardLocation;
       
    43 import javax.tools.ToolProvider;
       
    44 
       
    45 /**A tool to dump the content of the default javac's bootclasspath. This tool should not use any
       
    46  * features not available on the oldest supported target JDK, which is currently JDK 6.
       
    47  *
       
    48  * For more information on use of this site, please see CreateSymbols.
       
    49  */
       
    50 public class Probe {
       
    51 
       
    52     public static void main(String... args) throws IOException {
       
    53         if (args.length != 1) {
       
    54             System.err.println("Not enough arguments.");
       
    55             System.err.println("Usage:");
       
    56             System.err.println("    java " + Probe.class.getName() + " <output-file>");
       
    57             return ;
       
    58         }
       
    59 
       
    60         File outFile = new File(args[0]);
       
    61         Charset cs = Charset.forName("UTF-8");
       
    62         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       
    63         StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
       
    64         OutputStream out = new FileOutputStream(outFile);
       
    65 
       
    66         try {
       
    67             Iterable<JavaFileObject> bcpFiles =
       
    68                     fm.list(StandardLocation.PLATFORM_CLASS_PATH, "", EnumSet.of(Kind.CLASS), true);
       
    69 
       
    70             for (JavaFileObject jfo : bcpFiles) {
       
    71                 InputStream in = new BufferedInputStream(jfo.openInputStream());
       
    72                 try {
       
    73                     ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    74                     StringBuilder textual = new StringBuilder();
       
    75                     int read;
       
    76 
       
    77                     while ((read = in.read()) != (-1)) {
       
    78                         baos.write(read);
       
    79                         textual.append(String.format("%02x", read));
       
    80                     }
       
    81 
       
    82                     textual.append("\n");
       
    83                     out.write(textual.toString().getBytes(cs));
       
    84                 } finally {
       
    85                     in.close();
       
    86                 }
       
    87             }
       
    88         } finally {
       
    89             out.close();
       
    90         }
       
    91     }
       
    92 
       
    93 }