本文整理汇总了Java中javax.tools.StandardJavaFileManager.list方法的典型用法代码示例。如果您正苦于以下问题:Java StandardJavaFileManager.list方法的具体用法?Java StandardJavaFileManager.list怎么用?Java StandardJavaFileManager.list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.StandardJavaFileManager
的用法示例。
在下文中一共展示了StandardJavaFileManager.list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJavac
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public void testJavac() throws Exception {
final JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
final StandardJavaFileManager fm = jc.getStandardFileManager(
null,
Locale.ENGLISH,
Charset.forName("UTF-8")); //NOI18N
fm.setLocation(
StandardLocation.CLASS_PATH,
Collections.singleton(FileUtil.archiveOrDirForURL(mvCp.entries().get(0).getURL())));
Iterable<JavaFileObject> res = fm.list(
StandardLocation.CLASS_PATH,
"", //NOI18N
EnumSet.of(JavaFileObject.Kind.CLASS),
true);
assertEquals(3, StreamSupport.stream(res.spliterator(), false).count());
}
示例2: analyzeModule
import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
void analyzeModule(StandardJavaFileManager fm, String moduleName)
throws
IOException,
ConstantPoolException,
InvalidDescriptor {
JavaFileManager.Location location =
fm.getLocationForModule(StandardLocation.SYSTEM_MODULES, moduleName);
if (location == null)
throw new AssertionError("can't find module " + moduleName);
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
String className = fm.inferBinaryName(location, file);
int index = className.lastIndexOf('.');
String pckName = index == -1 ? "" : className.substring(0, index);
if (shouldAnalyzePackage(pckName)) {
analyzeClassFile(ClassFile.read(file.openInputStream()));
}
}
}
示例3: main
import javax.tools.StandardJavaFileManager; //导入方法依赖的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();
}
}