当前位置: 首页>>代码示例>>Java>>正文


Java JavaFileObject.openInputStream方法代码示例

本文整理汇总了Java中javax.tools.JavaFileObject.openInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObject.openInputStream方法的具体用法?Java JavaFileObject.openInputStream怎么用?Java JavaFileObject.openInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.JavaFileObject的用法示例。


在下文中一共展示了JavaFileObject.openInputStream方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isMultiRelease

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public boolean isMultiRelease() {
    Boolean res = multiRelease;
    if (res == null) {
        res = Boolean.FALSE;
        final JavaFileObject jfo = getFile("META-INF/MANIFEST.MF"); //NOI18N
        if (jfo != null) {
            try {
                try(final InputStream in = new BufferedInputStream(jfo.openInputStream())) {
                    res = FileObjects.isMultiVersionArchive(in);
                }
            } catch (IOException ioe) {
                LOGGER.log(
                        Level.WARNING,
                        "Cannot read: {0} manifest",    //NOI18N
                        archiveFile.getAbsolutePath());
            }
        }
        multiRelease = res;
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CachingArchive.java

示例2: isMultiRelease

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public boolean isMultiRelease() {
    Boolean res = multiRelease;
    if (res == null) {
        res = Boolean.FALSE;
        if (FileObjects.JAR.equals(root.getFileSystem().provider().getScheme())) {
            try {
                final JavaFileObject jfo = getFile("META-INF/MANIFEST.MF"); //NOI18N
                if (jfo != null) {
                    try(final InputStream in = new BufferedInputStream(jfo.openInputStream())) {
                        res = FileObjects.isMultiVersionArchive(in);
                    }
                }
            } catch (IOException ioe) {
                LOG.log(
                        Level.WARNING,
                        "Cannot read: {0} manifest",    //NOI18N
                        rootURI.toString());
            }
        }
        multiRelease = res;
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AbstractPathArchive.java

示例3: findProfile

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@NonNull
private Object findProfile(@NonNull final String binaryName) {
    Object res = UNKNOWN;
    final StringBuilder sb = new StringBuilder(binaryName);
    sb.append('.'); //NOI18N
    sb.append(FileObjects.CLASS);
    try {
        final JavaFileObject jfo = ctSym.getFile(sb.toString());
        if (jfo != null) {
            try (InputStream in = jfo.openInputStream()) {
                final ClassFile cf = new ClassFile(in);
                final Annotation a = cf.getAnnotation(ClassName.getClassName(ANNOTATION_PROFILE));
                if (a == null) {
                    res = Profile.COMPACT1;
                } else {
                    final AnnotationComponent ac = a.getComponent(ANNOTATION_VALUE);
                    res = profileFromAnnotationComponent(ac);
                }
            }
        }
    } catch (IOException ioe) {
        LOG.log(
                Level.INFO,
                "Cannot read class: {0}, reason: {1}",  //NOI18N
                new Object[]{
                    sb,
                    ioe.getMessage()
                });
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ProfileSupport.java

示例4: moduleInfoClz

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@NonNull
private static Supplier<byte[]> moduleInfoClz(
        @NonNull final Supplier<Pair<Boolean,String>> moduleInfoJava) {
    return () -> {
        try {
            final JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
            final List<String> opts = new ArrayList<>();
            opts.add("-source");        //NOI18N
            opts.add("9");              //NOI18N
            opts.add("-target");        //NOI18N
            opts.add("9");              //NOI18N
            final Pair<Boolean,String> p = moduleInfoJava.get();
            final JavaFileObject moduleInfo = FileObjects.memoryFileObject(
                    "",                 //NOI18N
                    "module-info.java", //NOI18N
                    p.second());
            final JavaFileManager fm = new MemFM(p.first());
            final JavacTask task = (JavacTask) jc.getTask(null, fm, null, opts, null, Collections.singleton(moduleInfo));
            final Iterator<? extends JavaFileObject> res = task.generate().iterator();
            final JavaFileObject fo = res.hasNext() ?
                    res.next() :
                    null;
            if (fo != null) {
                try (InputStream in = fo.openInputStream()) {
                    final ByteArrayOutputStream out = new ByteArrayOutputStream();
                    FileUtil.copy(in, out);
                    out.close();
                    return out.toByteArray();
                }
            } else {
                return null;
            }
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ModuleNamesTest.java

示例5: main

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
    if (args.length != 1) {
        System.err.println("Not enough arguments.");
        System.err.println("Usage:");
        System.err.println("    java " + Probe.class.getName() + " <output-file>");
        return ;
    }

    File outFile = new File(args[0]);
    Charset cs = Charset.forName("UTF-8");
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
    OutputStream out = new FileOutputStream(outFile);

    try {
        Iterable<JavaFileObject> bcpFiles =
                fm.list(StandardLocation.PLATFORM_CLASS_PATH, "", EnumSet.of(Kind.CLASS), true);

        for (JavaFileObject jfo : bcpFiles) {
            InputStream in = new BufferedInputStream(jfo.openInputStream());
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                StringBuilder textual = new StringBuilder();
                int read;

                while ((read = in.read()) != (-1)) {
                    baos.write(read);
                    textual.append(String.format("%02x", read));
                }

                textual.append("\n");
                out.write(textual.toString().getBytes(cs));
            } finally {
                in.close();
            }
        }
    } finally {
        out.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:Probe.java

示例6: openInputStream

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Open an input stream for the file.
 *
 * @throws DocFileIOException if there is a problem while opening stream
 */
@Override
public InputStream openInputStream() throws DocFileIOException {
    try {
        JavaFileObject fo = getJavaFileObjectForInput(file);
        return new BufferedInputStream(fo.openInputStream());
    } catch (IOException e) {
        throw new DocFileIOException(this, DocFileIOException.Mode.READ, e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:StandardDocFileFactory.java

示例7: checkBridges

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Check that every bridge in the generated classfile has a matching bridge
 * annotation in the bridge map
 */
protected void checkBridges(JavaFileObject jfo) {
    try (InputStream is = jfo.openInputStream()) {
        ClassFile cf = ClassFile.read(is);
        System.err.println("checking: " + cf.getName());

        List<Bridge> bridgeList = bridgesMap.get(cf.getName());
        if (bridgeList == null) {
            //no bridges - nothing to check;
            bridgeList = List.nil();
        }

        for (Method m : cf.methods) {
            if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) {
                //this is a bridge - see if there's a match in the bridge list
                Bridge match = null;
                for (Bridge b : bridgeList) {
                    if (b.value().equals(descriptor(m, cf.constant_pool))) {
                        match = b;
                        break;
                    }
                }
                if (match == null) {
                    error("No annotation for bridge method: " + descriptor(m, cf.constant_pool));
                } else {
                    bridgeList = drop(bridgeList, match);
                }
            }
        }
        if (bridgeList.nonEmpty()) {
            error("Redundant bridge annotation found: " + bridgeList.head.value());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + jfo.toUri() +": " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:BridgeHarness.java

示例8: openInputStream

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Open an input stream for the file. */
public InputStream openInputStream() throws IOException {
    JavaFileObject fo = getJavaFileObjectForInput(file);
    return new BufferedInputStream(fo.openInputStream());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:PathDocFileFactory.java

示例9: readModuleName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public String readModuleName(JavaFileObject jfo) throws IOException, BadClassFile {
    try (InputStream in = jfo.openInputStream()) {
        return readModuleName(in);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:ModuleNameReader.java

示例10: testCanCompileAgainstExplodedImage

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
void testCanCompileAgainstExplodedImage(String loc) throws IOException {
    System.err.println("testCanCompileAgainstExplodedImage(" + loc + ")");
    Path javaHome = prepareJavaHome();
    Path targetPath = javaHome.resolve(loc.replace("*", "/java.base").replace("/", sep));
    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        for (String pack : REQUIRED_PACKAGES) {
            Iterable<JavaFileObject> content = fm.list(StandardLocation.PLATFORM_CLASS_PATH,
                                                       pack,
                                                       EnumSet.allOf(JavaFileObject.Kind.class),
                                                       false);

            for (JavaFileObject jfo : content) {
                String name = jfo.getName();
                int lastSlash = name.lastIndexOf('/');
                name = lastSlash >= 0 ? name.substring(lastSlash + 1) : name;
                Path target = targetPath.resolve(pack.replace(".", sep) + sep + name);
                Files.createDirectories(target.getParent());
                try (InputStream in = jfo.openInputStream()) {
                    Files.copy(in, target);
                }
            }
        }
    }

    System.setProperty("java.home", javaHome.toString());

    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        DiagnosticListener<JavaFileObject> noErrors = d -> {
            if (d.getKind() == Diagnostic.Kind.ERROR)
                throw new IllegalStateException("Unexpected error: " + d);
        };
        ToolBox.JavaSource inputFile =
                new ToolBox.JavaSource("import java.util.List; class Test { List l; }");
        List<JavaFileObject> inputFiles = Arrays.asList(inputFile);
        boolean result =
                javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles).call();
        if (!result) {
            throw new IllegalStateException("Could not compile correctly!");
        }
        JavacTask task =
                (JavacTask) javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles);
        task.parse();
        TypeElement juList = task.getElements().getTypeElement("java.util.List");
        if (juList == null)
            throw new IllegalStateException("Cannot resolve java.util.List!");
        URI listSource = ((ClassSymbol) juList).classfile.toUri();
        if (!listSource.toString().startsWith(javaHome.toUri().toString()))
            throw new IllegalStateException(  "Did not load java.util.List from correct place, " +
                                              "actual location: " + listSource.toString() +
                                            "; expected prefix: " + javaHome.toUri());
    }

    System.err.println("finished.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:ExplodedImage.java

示例11: readClassFile

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Returns class file that is read from {@code fileObject}.
 *
 * @param fileObject a file object
 * @return class file that is read from {@code fileObject}
 * @throws IOException if I/O error occurs
 * @throws ConstantPoolException if constant pool error occurs
 */
public ClassFile readClassFile(JavaFileObject fileObject) throws IOException, ConstantPoolException {
    try (InputStream is = fileObject.openInputStream()) {
        return readClassFile(is);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TestBase.java


注:本文中的javax.tools.JavaFileObject.openInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。