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


Java FileObject类代码示例

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


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

示例1: write

import javax.tools.FileObject; //导入依赖的package包/类
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public FileObject write(ClassSymbol c)
    throws IOException
{
    String className = c.flatName().toString();
    FileObject outFile
        = fileManager.getFileForOutput(StandardLocation.NATIVE_HEADER_OUTPUT,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    Writer out = outFile.openWriter();
    try {
        write(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propogating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:JNIWriter.java

示例2: readHTMLDocumentation

import javax.tools.FileObject; //导入依赖的package包/类
/**
 * Utility for subclasses which read HTML documentation files.
 */
String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException {
    byte[] filecontents = new byte[input.available()];
    try {
        DataInputStream dataIn = new DataInputStream(input);
        dataIn.readFully(filecontents);
    } finally {
        input.close();
    }
    String encoding = env.getEncoding();
    String rawDoc = (encoding!=null)
        ? new String(filecontents, encoding)
        : new String(filecontents);
    Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*");
    Matcher m = bodyPat.matcher(rawDoc);
    if (m.matches()) {
        return m.group(1);
    } else {
        String key = rawDoc.matches("(?is).*<body\\b.*")
                ? "javadoc.End_body_missing_from_html_file"
                : "javadoc.Body_missing_from_html_file";
        env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key);
        return "";
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:DocImpl.java

示例3: getJavaFileForOutput

import javax.tools.FileObject; //导入依赖的package包/类
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
    final Pair<Location,URL> p = baseLocation(location);
    if (!hasLocation(p.first())) {
        throw new IllegalArgumentException(String.valueOf(p.first()));
    }
    final File root = new File (outputRoot);
    assert p.second() == null || p.second().equals(BaseUtilities.toURI(root).toURL()) :
            String.format("Expected: %s, Current %s", p.second(), root);
    final String nameStr = FileObjects.convertPackage2Folder(className, File.separatorChar)  + '.' + FileObjects.SIG;
    final File file = new File (root, nameStr);
    if (FileObjects.isValidFileName(className)) {
        return tx.createFileObject(location, file, root, null, null);
    } else {
        LOG.log(
            Level.WARNING,
            "Invalid class name: {0} sibling: {1}", //NOI18N
            new Object[]{
                className,
                sibling
            });
        return FileObjects.nullWriteFileObject(FileObjects.fileFileObject(file, root, null, null));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TreeLoaderOutputFileManager.java

示例4: findResources

import javax.tools.FileObject; //导入依赖的package包/类
@Override
protected Enumeration<URL> findResources(final String name) throws IOException {
    try {
        return readAction(new Callable<Enumeration<URL>>(){
            @Override
            public Enumeration<URL> call() throws Exception {
                @SuppressWarnings("UseOfObsoleteCollectionType")
                final Vector<URL> v = new Vector<URL>();
                for (final Pair<URL,Archive> p : archives) {
                    final Archive archive = p.second();
                    final FileObject file = archive.getFile(name);
                    if (file != null) {
                        v.add(file.toUri().toURL());
                        usedRoots
                                .map((c) -> RES_PROCESSORS.equals(name) ? null : c)
                                .ifPresent((c) -> c.accept(p.first()));
                    }
                }
                return v.elements();
            }
        });
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CachingArchiveClassLoader.java

示例5: readJavaFileObject

import javax.tools.FileObject; //导入依赖的package包/类
private int readJavaFileObject(final FileObject jfo) throws IOException {
    assert LOCK.getReadLockCount() > 0;
    if (buffer == null) {
        buffer = new byte[INI_SIZE];
    }
    int len = 0;
    final InputStream in = jfo.openInputStream();
    try {
        while (true) {
            if (buffer.length == len) {
                byte[] nb = new byte[2*buffer.length];
                System.arraycopy(buffer, 0, nb, 0, len);
                buffer = nb;
            }
            int l = in.read(buffer,len,buffer.length-len);
            if (l<=0) {
                break;
            }
            len+=l;
        }

    } finally {
        in.close();
    }
    return len;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CachingArchiveClassLoader.java

示例6: getFileForInput

import javax.tools.FileObject; //导入依赖的package包/类
@Override
@CheckForNull
public FileObject getFileForInput(
        @NonNull final Location l,
        @NonNull final String packageName,
        @NonNull final String relativeName) throws IOException {
    checkSingleOwnerThread();
    try {
        JavaFileManager[] fms = cfg.getFileManagers(l, null);
        for (JavaFileManager fm : fms) {
            FileObject result = fm.getFileForInput(l, packageName, relativeName);
            if (result != null) {
                return result;
            }
        }
        return null;
    } finally {
        clearOwnerThread();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ProxyFileManager.java

示例7: checkContains

import javax.tools.FileObject; //导入依赖的package包/类
void checkContains(StandardJavaFileManager fm, Location l, FileObject fo, boolean expect) throws IOException {
    boolean found = fm.contains(l, fo);
    if (found) {
        if (expect) {
            out.println("file found, as expected: " + l + " " + fo.getName());
        } else {
            error("file not found: " + l + " " + fo.getName());
        }
    } else {
        if (expect) {
            error("file found unexpectedly: " + l + " " + fo.getName());
        } else {
            out.println("file not found, as expected: " + l + " " + fo.getName());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ContainsTest.java

示例8: getJavaFileForOutput

import javax.tools.FileObject; //导入依赖的package包/类
@Override
@CheckForNull
public JavaFileObject getJavaFileForOutput(
        @NonNull final Location l,
        @NonNull final String className,
        @NonNull final JavaFileObject.Kind kind,
        @NonNull final FileObject sibling)
    throws IOException, UnsupportedOperationException, IllegalArgumentException {
    checkSingleOwnerThread();
    try {
        final JavaFileManager[] fms = cfg.getFileManagers (l, null);
        if (fms.length == 0) {
            throw new UnsupportedOperationException("No JavaFileManager for location: " + l);  //NOI18N
        } else {
            return mark (
                    fms[0].getJavaFileForOutput (l, className, kind, sibling),
                    l);
        }
    } finally {
        clearOwnerThread();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ProxyFileManager.java

示例9: 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

示例10: writeServices

import javax.tools.FileObject; //导入依赖的package包/类
private void writeServices() {
    for (Map.Entry<Filer,Map<String,SortedSet<ServiceLoaderLine>>> outputFiles : outputFilesByProcessor.entrySet()) {
        Filer filer = outputFiles.getKey();
        for (Map.Entry<String,SortedSet<ServiceLoaderLine>> entry : outputFiles.getValue().entrySet()) {
            try {
                FileObject out = filer.createResource(StandardLocation.CLASS_OUTPUT, "", entry.getKey(),
                        originatingElementsByProcessor.get(filer).get(entry.getKey()).toArray(new Element[0]));
                OutputStream os = out.openOutputStream();
                try {
                    PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
                    for (ServiceLoaderLine line : entry.getValue()) {
                        line.write(w);
                    }
                    w.flush();
                    w.close();
                } finally {
                    os.close();
                }
            } catch (IOException x) {
                processingEnv.getMessager().printMessage(Kind.ERROR, "Failed to write to " + entry.getKey() + ": " + x.toString());
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AbstractServiceProviderProcessor.java

示例11: generateConverterDoc

import javax.tools.FileObject; //导入依赖的package包/类
private static void generateConverterDoc(ModelContext ctx, ConverterModel converter) throws TransformerFactoryConfigurationError, IOException {
	String bundleName = converter.getBundleName();
	int dot = bundleName.lastIndexOf('.');
	String packageName = bundleName.substring(0, dot);
	String fileName = bundleName.substring(dot + 1) + ".xml";
	FileObject fo;
	try {
		fo = ctx.getFiler().getResource(StandardLocation.SOURCE_PATH, packageName, fileName);
	} catch (IOException ioe) {
		fo = ctx.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName);
		ctx.note("generating " + fo.getName());
		PrintWriter out = new PrintWriter(fo.openOutputStream());
		XMLUtils.writeDOMToFile(converter.generateDoc(), null, out);
		out.close();
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:ConverterFactoryModel.java

示例12: createResource

import javax.tools.FileObject; //导入依赖的package包/类
public FileObject createResource(Location location,
                                 CharSequence pkg,
                                 CharSequence relativeName,
                                 Element... originatingElements) throws IOException {
    locationCheck(location);

    String strPkg = pkg.toString();
    if (strPkg.length() > 0)
        checkName(strPkg);

    FileObject fileObject =
        fileManager.getFileForOutput(location, strPkg,
                                     relativeName.toString(), null);
    checkFileReopening(fileObject, true);

    if (fileObject instanceof JavaFileObject)
        return new FilerOutputJavaFileObject(null, (JavaFileObject)fileObject);
    else
        return new FilerOutputFileObject(null, fileObject);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:JavacFiler.java

示例13: getFileObjectForOutput

import javax.tools.FileObject; //导入依赖的package包/类
private FileObject getFileObjectForOutput(DocPath path) throws IOException {
    // break the path into a package-part and the rest, by finding
    // the position of the last '/' before an invalid character for a
    // package name, such as the "." before an extension or the "-"
    // in filenames like package-summary.html, doc-files or src-html.
    String p = path.getPath();
    int lastSep = -1;
    for (int i = 0; i < p.length(); i++) {
        char ch = p.charAt(i);
        if (ch == '/') {
            lastSep = i;
        } else if (i == lastSep + 1 && !Character.isJavaIdentifierStart(ch)
                || !Character.isJavaIdentifierPart(ch)) {
            break;
        }
    }
    String pkg = (lastSep == -1) ? "" : p.substring(0, lastSep);
    String rest = p.substring(lastSep + 1);
    return fileManager.getFileForOutput(location, pkg, rest, null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:PathDocFileFactory.java

示例14: getJavaFileForOutput

import javax.tools.FileObject; //导入依赖的package包/类
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException
{
	if (kind != Kind.CLASS)
	{
		return _wrapped.getJavaFileForOutput(location, className, kind, sibling);
	}
	
	if (className.contains("/"))
	{
		className = className.replace('/', '.');
	}
	
	ScriptingOutputFileObject fileObject;
	if (sibling != null)
	{
		fileObject = new ScriptingOutputFileObject(Paths.get(sibling.getName()), className, className.substring(className.lastIndexOf('.') + 1));
	}
	else
	{
		fileObject = new ScriptingOutputFileObject(null, className, className.substring(className.lastIndexOf('.') + 1));
	}
	
	_classOutputs.add(fileObject);
	return fileObject;
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:27,代码来源:ScriptingFileManager.java

示例15: listenForNewClassFile

import javax.tools.FileObject; //导入依赖的package包/类
private void listenForNewClassFile(OutputMemoryJavaFileObject jfo, JavaFileManager.Location location,
        String className, JavaFileObject.Kind kind, FileObject sibling) {
    //debug("listenForNewClassFile %s loc=%s kind=%s\n", className, location, kind);
    if (location == CLASS_OUTPUT) {
        state.debug(DBG_GEN, "Compiler generating class %s\n", className);
        OuterWrap w = ((sibling instanceof SourceMemoryJavaFileObject)
                && (((SourceMemoryJavaFileObject) sibling).getOrigin() instanceof OuterWrap))
                ? (OuterWrap) ((SourceMemoryJavaFileObject) sibling).getOrigin()
                : null;
        classObjs.compute(w, (k, v) -> (v == null)? new ArrayList<>() : v)
                .add(jfo);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TaskFactory.java


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