Search in sources :

Example 1 with IParserController

use of com.ibm.dtfj.javacore.parser.framework.parser.IParserController in project openj9 by eclipse.

the class JavaCoreReader method generateImage.

/**
 * @param input
 *
 * @throws UnsupportedSourceException
 * @throws ParserException
 * @throws IOException
 */
public Image generateImage(InputStream input) throws IOException {
    try {
        byte[] head = new byte[256];
        input.read(head);
        ByteArrayInputStream headByteStream = new ByteArrayInputStream(head);
        Charset cs = getJavaCoreCodePage(headByteStream);
        SequenceInputStream stream = new SequenceInputStream(headByteStream, input);
        // Use default charset if none found
        // Charset.defaultCharset is 5.0, so not usable for 1.4
        Reader reader = cs != null ? new InputStreamReader(stream, cs) : new InputStreamReader(stream);
        List frameworkSections = new DTFJComponentLoader().loadSections();
        IParserController parserController = new ParserController(frameworkSections, fImageBuilderFactory);
        parserController.addErrorListener(new IErrorListener() {

            private Logger logger = Logger.getLogger(ImageFactory.DTFJ_LOGGER_NAME);

            public void handleEvent(String msg) {
                // map errors onto Level.FINE so that DTFJ is silent unless explicitly changed
                logger.fine(msg);
            }
        });
        J9TagManager tagManager = J9TagManager.getCurrent();
        return parserController.parse(fComponents.getScannerManager(reader, tagManager));
    } catch (ParserException e) {
        IOException e1 = new IOException("Error parsing Javacore");
        e1.initCause(e);
        throw e1;
    }
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IParserController(com.ibm.dtfj.javacore.parser.framework.parser.IParserController) InputStreamReader(java.io.InputStreamReader) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Logger(java.util.logging.Logger) IParserController(com.ibm.dtfj.javacore.parser.framework.parser.IParserController) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IErrorListener(com.ibm.dtfj.javacore.parser.framework.parser.IErrorListener) List(java.util.List)

Aggregations

IErrorListener (com.ibm.dtfj.javacore.parser.framework.parser.IErrorListener)1 IParserController (com.ibm.dtfj.javacore.parser.framework.parser.IParserController)1 ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 SequenceInputStream (java.io.SequenceInputStream)1 Charset (java.nio.charset.Charset)1 List (java.util.List)1 Logger (java.util.logging.Logger)1