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


Java FileObject.openInputStream方法代码示例

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


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

示例1: findClass

import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    int n = name.lastIndexOf('.');
    String pkg = n == -1 ? "" : name.substring(0, n);
    String cls = name.substring(n + 1) + ".class";
    byte[] b;
    try {
        FileObject obj = jfm.getFileForInput(jloc, pkg, cls);
        try (InputStream is = obj.openInputStream()) {
            b = is.readAllBytes();
        }
    } catch (IOException x) {
        throw new ClassNotFoundException(x.getMessage(), x);
    }
    return defineClass(name, b, 0, b.length);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:MultiReleaseJarAwareSJFM.java

示例2: writeFileObjects

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeFileObjects(JarOutputStream jos) throws IOException {
    for (FileObject fo : fileObjects) {
        String p = guessPath(fo);
        JarEntry e = new JarEntry(p);
        jos.putNextEntry(e);
        try {
            byte[] buf = new byte[1024];
            try (BufferedInputStream in = new BufferedInputStream(fo.openInputStream())) {
                int n;
                while ((n = in.read(buf)) > 0)
                    jos.write(buf, 0, n);
            } catch (IOException ex) {
                error("Exception while adding " + fo.getName() + " to jar file", ex);
            }
    } finally {
            jos.closeEntry();
    }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:JarTask.java

示例3: generateInstanceResolver

import javax.tools.FileObject; //导入方法依赖的package包/类
private byte[] generateInstanceResolver(FileObject fo, Element e, File f,
        Registration r) throws LayerGenerationException {
    try {
        InputStream is = fo.openInputStream();
        org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
        OutputStream os = tmp.getOutputStream();
        for (;;) {
            int ch = is.read();
            if (ch == -1) {
                break;
            }
            os.write(ch);
        }
        os.close();
        is.close();
        MIMEResolver resolver = MIMEResolverImpl.forDescriptor(tmp, false);
        setFileChooserRelatedAttributes(r, resolver, f);
        final byte[] almostResult = MIMEResolverImpl.toStream(resolver);
        // XXX: it would be slightly shorter to return the array directly,
        // but the XMLFileSystem insist on deserializing the value, it does
        // not support returning plain byte[]
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(almostResult);
        oos.close();
        return out.toByteArray();
    } catch (IOException ex) {
        final LayerGenerationException le = new LayerGenerationException("Cannot process " + fo, e);
        le.initCause(ex);
        throw le;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:MIMEResolverProcessor.java

示例4: writeIfChanged

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
    boolean mustWrite = false;
    String event = "[No need to update file ";

    if (force) {
        mustWrite = true;
        event = "[Forcefully writing file ";
    } else {
        InputStream in;
        byte[] a;
        try {
            // regrettably, there's no API to get the length in bytes
            // for a FileObject, so we can't short-circuit reading the
            // file here
            in = file.openInputStream();
            a = readBytes(in);
            if (!Arrays.equals(a, b)) {
                mustWrite = true;
                event = "[Overwriting file ";

            }
        } catch (FileNotFoundException e) {
            mustWrite = true;
            event = "[Creating file ";
        }
    }

    if (util.verbose)
        util.log(event + file + "]");

    if (mustWrite) {
        OutputStream out = file.openOutputStream();
        out.write(b); /* No buffering, just one big write! */
        out.close();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Gen.java

示例5: writeIfChanged

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
    boolean mustWrite = false;
    String event = "[No need to update file ";

    if (force) {
        mustWrite = true;
        event = "[Forcefully writing file ";
    } else {
        InputStream in;
        byte[] a;
        try {
            // regrettably, there's no API to get the length in bytes
            // for a FileObject, so we can't short-circuit reading the
            // file here
            in = file.openInputStream();
            a = readBytes(in);
            if (!Arrays.equals(a, b)) {
                mustWrite = true;
                event = "[Overwriting file ";

            }
        } catch (FileNotFoundException | NoSuchFileException e) {
            mustWrite = true;
            event = "[Creating file ";
        }
    }

    if (util.verbose)
        util.log(event + file + "]");

    if (mustWrite) {
        OutputStream out = file.openOutputStream();
        out.write(b); /* No buffering, just one big write! */
        out.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:Gen.java


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