static JavaFileObject preprocessedFileObject(JavaFileObject fo, List<String> includeDirs) throws IOException { if (includeDirs != null) { StringWriter out = new StringWriter(); PCPP pcpp = new PCPP(includeDirs, out); BufferedReader reader = new BufferedReader(new InputStreamReader(fo.openInputStream(), StandardCharsets.UTF_8)); pcpp.run(reader, fo.getName()); return new StringInputBuffer(fo.getName(), out.toString()); } else { return fo; } }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (!testFiles.contains(name.split("[$]", 0)[0])) { return SingleBehaviorTester.class.getClassLoader().loadClass(name); } try { JavaFileObject classFile = fileManager.getJavaFileForInput( StandardLocation.CLASS_OUTPUT, name, CLASS); if (classFile == null) { throw new ClassNotFoundException(); } byte[] bytes = ByteStreams.toByteArray(classFile.openInputStream()); return super.defineClass(name, bytes, 0, bytes.length); } catch (IOException e) { throw new ClassNotFoundException(); } } }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (testFiles.contains(name.split("[$]", 0)[0])) { throw new ClassNotFoundException(); } try { JavaFileObject classFile = fileManager.getJavaFileForInput( StandardLocation.CLASS_OUTPUT, name, CLASS); if (classFile == null) { throw new ClassNotFoundException(); } byte[] bytes = ByteStreams.toByteArray(classFile.openInputStream()); return super.defineClass(name, bytes, 0, bytes.length); } catch (IOException e) { throw new ClassNotFoundException(); } } }
@Override public InputStream openStream() throws IOException { return javaFileObject.openInputStream(); } };
@Override public InputStream openStream() throws IOException { return javaFileObject.openInputStream(); } };
@Override public InputStream openStream() throws IOException { return javaFileObject.openInputStream(); } };
@Override public InputStream openStream() throws IOException { return javaFileObject.openInputStream(); } };
public InputStream openInputStream() throws IOException { return file.openInputStream(); }
public InputStream openInputStream() throws IOException { return core.openInputStream(); }
InputStream in = classes.get(0).openInputStream(); byte[] bytes = Utils.readAsBytes(in); assertTrue(bytes.length > 0);
/** Open an input stream for the file. */ public InputStream openInputStream() throws IOException { JavaFileObject fo = getJavaFileObjectForInput(file); return new BufferedInputStream(fo.openInputStream()); }
/** Open an input stream for the file. */ public InputStream openInputStream() throws IOException { JavaFileObject fo = getJavaFileObjectForInput(file); return new BufferedInputStream(fo.openInputStream()); }
static JavaFileObject preprocessedFileObject(JavaFileObject fo, List<String> includeDirs) throws IOException { if (includeDirs != null) { PCPP pcpp = new PCPP(includeDirs); StringWriter out = new StringWriter(); pcpp.setOut(out); BufferedReader reader = new BufferedReader(new InputStreamReader(fo.openInputStream())); pcpp.run(reader, fo.getName()); return new StringInputBuffer(fo.getName(), out.toString()); } else { return fo; } }
static JavaFileObject preprocessedFileObject(JavaFileObject fo, List<String> includeDirs) throws IOException { if (includeDirs != null) { PCPP pcpp = new PCPP(includeDirs); StringWriter out = new StringWriter(); pcpp.setOut(out); BufferedReader reader = new BufferedReader(new InputStreamReader(fo.openInputStream())); pcpp.run(reader, fo.getName()); return new StringInputBuffer(fo.getName(), out.toString()); } else { return fo; } }
public ClassFileInfo read(JavaFileObject fo) throws IOException, ConstantPoolException { InputStream in = fo.openInputStream(); try { SizeInputStream sizeIn = null; MessageDigest md = null; if (options.sysInfo || options.verbose) { try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException ignore) { } in = new DigestInputStream(in, md); in = sizeIn = new SizeInputStream(in); } ClassFile cf = ClassFile.read(in, attributeFactory); byte[] digest = (md == null) ? null : md.digest(); int size = (sizeIn == null) ? -1 : sizeIn.size(); return new ClassFileInfo(fo, cf, digest, size); } finally { in.close(); } }
/** * Returns an {@link InputStream} for reading the source code of the specified java class with the given name from * this project's output directory. * * @param classname * @return the input stream for reading the specified java class * @throws IOException */ public InputStream findGeneratedSource(String classname) throws IOException { JavaFileObject fileObject = fileManager.getJavaFileForInput(StandardLocation.CLASS_OUTPUT, classname, Kind.SOURCE); if (fileObject == null) { return null; } return fileObject.openInputStream(); }
return null; // most common case try (InputStream inputStream = jfo.openInputStream()) { ClassFileReader reader = ClassFileReader.read(inputStream, qualifiedBinaryFileName); if (reader != null) {
@Override protected Class<?> findClass(final String name) throws ClassNotFoundException { String path = name.replace(".", "/").concat(".class"); JavaFileObject generatedClass = compilation.generatedFile(CLASS_OUTPUT, path).orElse(null); if (generatedClass == null) { return super.findClass(name); } try (InputStream is = generatedClass.openInputStream()) { byte[] classBytes = ByteStreams.toByteArray(is); return defineClass(name, classBytes, 0, classBytes.length); } catch (IOException e) { throw new ClassNotFoundException(name, e); } }
/** * Do lazy initialization of "documentation" string. */ @Override protected String documentation() { if (documentation == null) { JavaFileObject overviewPath = getOverviewPath(); if (overviewPath == null) { // no doc file to be had documentation = ""; } else { // read from file try { documentation = readHTMLDocumentation( overviewPath.openInputStream(), overviewPath); } catch (IOException exc) { documentation = ""; env.error(null, "javadoc.File_Read_Error", overviewPath.getName()); } } } return documentation; }
@Override public JavaFileObject getJavaFileForOutput( final Location location, final String className, final Kind kind, final FileObject sibling) throws IOException { final String key = createKey(className, kind); if (fileObjects.containsKey(key)) { return fileObjects.get(key); } byte[] content = null; URI uri = null; try { final JavaFileObject originalFileObject = super.getJavaFileForOutput(location, className, kind, sibling); uri = originalFileObject.toUri(); content = IOUtils.readBytes(originalFileObject.openInputStream()); } catch (final FileNotFoundException ignore) { } final InMemoryJavaFileObject fileObject = new InMemoryJavaFileObject( uri != null ? uri : toURI(location, className), kind, charset, content); fileObjects.put(key, fileObject); return fileObject; }