Example usage for org.eclipse.jdt.internal.compiler.util Util getInputStreamAsCharArray

List of usage examples for org.eclipse.jdt.internal.compiler.util Util getInputStreamAsCharArray

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.util Util getInputStreamAsCharArray.

Prototype

public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding)
        throws IOException 

Source Link

Document

Returns the given input stream's contents as a character array.

Usage

From source file:org.jboss.forge.parser.spi.JavaParserImpl.java

License:Open Source License

@Override
public JavaSource<?> parse(final InputStream data) {
    try {// w w w  . ja  v a  2 s. c  om
        char[] source = Util.getInputStreamAsCharArray(data, data.available(), "ISO8859_1");
        return parse(source);
    } catch (IOException e) {
        throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
    } finally {
        if (data != null) {
            try {
                data.close();
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}

From source file:org.jboss.forge.roaster.spi.JavaParserImpl.java

License:Open Source License

@Override
public JavaType<?> parse(final InputStream data) {
    try {//from   w  ww . j av a 2  s  .  com
        char[] source = Util.getInputStreamAsCharArray(data, data.available(), "ISO8859_1");
        return parse(new String(source));
    } catch (IOException e) {
        return null;
    } finally {
        Streams.closeQuietly(data);
    }
}

From source file:org.jboss.seam.forge.parser.java.impl.JavaClassImpl.java

License:Open Source License

/**
 * Parses and process the java source code as a compilation unit and the
 * result it abstract syntax tree (AST) representation and this action uses
 * the third edition of java Language Specification.
 * //from   w w w  . ja v a2s  .c om
 * @param source - the java source to be parsed (i.e. the char[] contains
 *           Java source).
 * @return CompilationUnit Abstract syntax tree representation of a java
 *         source file.
 */
public JavaClassImpl(final InputStream inputStream) {
    try {
        char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
        init(source);
    } catch (Exception e) {
        throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
    }
}

From source file:org.jboss.seam.forge.parser.JavaParser.java

License:Open Source License

/**
 * Read the given {@link InputStream} and parse the data into a new {@link JavaClass} instance.
 *///from  w ww  .j ava 2s .  co  m
public static JavaSource<?> parse(final InputStream data) {
    try {
        char[] source = Util.getInputStreamAsCharArray(data, data.available(), "ISO8859_1");
        return parse(source);
    } catch (Exception e) {
        throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
    } finally {
        if (data != null) {
            try {
                data.close();
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}

From source file:org.modeshape.sequencer.java.JavaMetadataUtil.java

License:Open Source License

/**
 * Gets Java source from the <code>InputStream</code>.
 * /*from  w ww. j  a v  a 2 s.c  o  m*/
 * @param inputStream - the <code>FileInputStream</code>.
 * @param length - the length of the java file.
 * @param encoding - the encoding of the source, if there is one.
 * @return the array character of the java source.
 * @throws IOException - exceptional error can be thrown during the reading of the file.
 */
public static char[] getJavaSourceFromTheInputStream(InputStream inputStream, long length, String encoding)
        throws IOException {
    char[] source = Util.getInputStreamAsCharArray(inputStream, (int) length, encoding);
    return source;
}

From source file:org.modeshape.sequencer.javafile.JavaMetadataUtil.java

License:Apache License

/**
 * Gets Java source from the <code>InputStream</code>.
 * /*from   ww w .jav  a  2 s  .co  m*/
 * @param inputStream - the <code>FileInputStream</code>.
 * @param length - the length of the java file.
 * @param encoding - the encoding of the source, if there is one.
 * @return the array character of the java source.
 * @throws java.io.IOException - exceptional error can be thrown during the reading of the file.
 */
public static char[] getJavaSourceFromTheInputStream(InputStream inputStream, long length, String encoding)
        throws IOException {
    return Util.getInputStreamAsCharArray(inputStream, (int) length, encoding);
}

From source file:spoon.support.builder.JDTCompiler.java

License:Open Source License

public CompilationUnit[] getCompilationUnits(List<CtFile> streams) throws Exception {
    CompilationUnit[] units = new CompilationUnit[streams.size()];
    int i = 0;/*from  w w w  . jav a 2s.  c  o m*/
    for (CtFile stream : streams) {
        InputStream in = stream.getContent();
        units[i] = new CompilationUnit(Util.getInputStreamAsCharArray(in, -1, null), stream.getPath(), null);
        in.close();
        i++;
    }
    return units;
}