List of usage examples for org.eclipse.jdt.internal.compiler.util Util getInputStreamAsByteArray
public static byte[] getInputStreamAsByteArray(InputStream stream, int length) throws IOException
From source file:org.eclipse.che.jdt.core.ToolFactory.java
License:Open Source License
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the input stream contents cannot be retrieved * <p/>/* ww w . j ava 2 s .c o m*/ * The decoding flags are described in IClassFileReader. * * @param stream * the given input stream to read * @param decodingFlag * the flag used to decode the class file reader. * @return a default classfile reader * @see org.eclipse.jdt.core.util.IClassFileReader * @since 3.2 */ public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) { try { return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag); } catch (ClassFormatException e) { return null; } catch (IOException e) { return null; } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected static byte[] readByteTable(String filename) throws java.io.IOException { //files are located at Parser.class directory InputStream stream = Parser.class.getResourceAsStream(filename); if (stream == null) { throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename)); }/*from ww w.j a v a 2s .com*/ byte[] bytes = null; try { stream = new BufferedInputStream(stream); bytes = Util.getInputStreamAsByteArray(stream, -1); } finally { try { stream.close(); } catch (IOException e) { // ignore } } return bytes; }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected static long[] readLongTable(String filename) throws java.io.IOException { //files are located at Parser.class directory InputStream stream = Parser.class.getResourceAsStream(filename); if (stream == null) { throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename)); }//from ww w . jav a2 s . c om byte[] bytes = null; try { stream = new BufferedInputStream(stream); bytes = Util.getInputStreamAsByteArray(stream, -1); } finally { try { stream.close(); } catch (IOException e) { // ignore } } //minimal integrity check (even size expected) int length = bytes.length; if (length % 8 != 0) throw new java.io.IOException(Messages.bind(Messages.parser_corruptedFile, filename)); // convert bytes into longs long[] longs = new long[length / 8]; int i = 0; int longIndex = 0; while (true) { longs[longIndex++] = (((long) (bytes[i++] & 0xFF)) << 56) + (((long) (bytes[i++] & 0xFF)) << 48) + (((long) (bytes[i++] & 0xFF)) << 40) + (((long) (bytes[i++] & 0xFF)) << 32) + (((long) (bytes[i++] & 0xFF)) << 24) + (((long) (bytes[i++] & 0xFF)) << 16) + (((long) (bytes[i++] & 0xFF)) << 8) + (bytes[i++] & 0xFF); if (i == length) break; } return longs; }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected static char[] readTable(String filename) throws java.io.IOException { //files are located at Parser.class directory InputStream stream = Parser.class.getResourceAsStream(filename); if (stream == null) { throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename)); }// w w w .j ava 2 s. c o m byte[] bytes = null; try { stream = new BufferedInputStream(stream); bytes = Util.getInputStreamAsByteArray(stream, -1); } finally { try { stream.close(); } catch (IOException e) { // ignore } } //minimal integrity check (even size expected) int length = bytes.length; if ((length & 1) != 0) throw new java.io.IOException(Messages.bind(Messages.parser_corruptedFile, filename)); // convert bytes into chars char[] chars = new char[length / 2]; int i = 0; int charIndex = 0; while (true) { chars[charIndex++] = (char) (((bytes[i++] & 0xFF) << 8) + (bytes[i++] & 0xFF)); if (i == length) break; } return chars; }