當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。