本文整理汇总了Java中javax.annotation.processing.Filer.createResource方法的典型用法代码示例。如果您正苦于以下问题:Java Filer.createResource方法的具体用法?Java Filer.createResource怎么用?Java Filer.createResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.annotation.processing.Filer
的用法示例。
在下文中一共展示了Filer.createResource方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeServices
import javax.annotation.processing.Filer; //导入方法依赖的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());
}
}
}
}
示例2: doWithOriAndPrintWriter
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
public static void doWithOriAndPrintWriter(Filer filer, JavaFileManager.Location location, String relativePath, String filename, BiConsumer<String, PrintWriter> consumer){
try {
FileObject resource = filer.getResource(location, relativePath, filename);
String data;
try{
CharSequence cs = resource.getCharContent(false);
data = cs.toString();
resource.delete();
}catch (FileNotFoundException ignored){
data = "";
}
resource = filer.createResource(location, relativePath, filename);
try(OutputStream outputStream = resource.openOutputStream()){
consumer.accept(data,new PrintWriter(outputStream));
}
} catch (IOException e) {
note("do with resource file failed"+relativePath+filename+" Exception: " + e.toString());
}
}
示例3: writeServiceNames
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
default void writeServiceNames(Class<?> serviceClass, Filer filer, List<String> generatedClassNames) throws IOException {
String resourceFile = "META-INF/services/" + serviceClass.getName();
FileObject existingFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
List<String> lines = new ArrayList<>();
try (Reader reader = existingFile.openReader(false)) {
try (BufferedReader bufferedReader = new BufferedReader(reader)) {
lines.addAll(bufferedReader.lines().collect(Collectors.toList()));
}
} catch (IOException e) {
// Just ignore because reading from a non-existing file and there is no way to detect its existence
// than open the input stream/reader.
}
lines.addAll(generatedClassNames);
FileObject newFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
try (Writer writer = newFile.openWriter()) {
try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
for (String line : lines) {
bufferedWriter.write(line);
bufferedWriter.newLine();
}
}
}
}
示例4: init
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv)
{
//Creating necesary objects for annotations procesing.
super.init(processingEnv);
Messager messager = processingEnv.getMessager();
try
{
Filer filer = processingEnv.getFiler();
//Creating output file
FileObject fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", CONTROLS_RESOURCE_FILE);
writer = fobj.openWriter();
}
catch (IOException e)
{
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
LOG.severe(e.getMessage());
}
}
示例5: init
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv)
{
//Creating necessary objects for annotations processing.
super.init(processingEnv);
Messager messager = processingEnv.getMessager();
try
{
Filer filer = processingEnv.getFiler();
//Creating output file
FileObject fobj = filer.createResource(StandardLocation.CLASS_OUTPUT, "", getFileName());
writer = fobj.openWriter();
}
catch (IOException e)
{
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
LOG.severe(e.getMessage());
}
}
示例6: writeResource
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
/**
* Write <query>.sql to resources folder
*
* @param queryDesc information on query
*/
private void writeResource(QueryDesc queryDesc) {
Filer filer = processingEnv.getFiler();
try {
FileObject o = filer.createResource(StandardLocation.CLASS_OUTPUT,
queryDesc.getPackageName() + ".sql", queryDesc.getMethodNameFirstUpper() + ".sql");
Writer w = o.openWriter();
w.append(queryDesc.getQuery());
w.flush();
w.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: findRootProjectHolder
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
/**
* We use a dirty trick to find the AndroidManifest.xml file, since it's not
* available in the classpath. The idea is quite simple : create a fake
* class file, retrieve its URI, and start going up in parent folders to
* find the AndroidManifest.xml file. Any better solution will be
* appreciated.
*/
public Option<FileHolder> findRootProjectHolder() {
Filer filer = processingEnv.getFiler();
FileObject dummySourceFile;
try {
dummySourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, "com", "dummy" + System.currentTimeMillis());
} catch (IOException ignored) {
return Option.absent();
}
String dummySourceFilePath = dummySourceFile.toUri().toString();
if (dummySourceFilePath.startsWith("file:")) {
if (!dummySourceFilePath.startsWith("file://")) {
dummySourceFilePath = "file://" + dummySourceFilePath.substring("file:".length());
}
} else {
dummySourceFilePath = "file://" + dummySourceFilePath;
}
URI cleanURI;
try {
cleanURI = new URI(dummySourceFilePath);
} catch (URISyntaxException e) {
return Option.absent();
}
try {
File dummyFile = new File(cleanURI);
File sourcesGenerationFolder = dummyFile.getParentFile();
File projectRoot = sourcesGenerationFolder.getParentFile();
return Option.of(new FileHolder(dummySourceFilePath, sourcesGenerationFolder, projectRoot));
}catch(IllegalArgumentException ex){
return Option.absent();
}
}
示例8: process
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
Filer filer = processingEnv.getFiler();
for (TypeElement typeElement : annotations) {
for (Element element : env.getElementsAnnotatedWith(typeElement)) {
Resourcecify resourcecify = element.getAnnotation(Resourcecify.class);
if (resourcecify == null) {
continue;
}
if (element instanceof Symbol.ClassSymbol) {
Symbol.ClassSymbol s = (Symbol.ClassSymbol) element;
try {
String packageName = getPackageName(s);
JavaFileObject source = s.sourcefile;
File sourceFile = new File(source.getName()).getAbsoluteFile();
String sourceFileName = sourceFile.getName();
FileObject target = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, sourceFileName, s);
IOUtils.copy(source, target);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return false;
}
示例9: createLogFile
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
private static FileObject createLogFile(ProcessingEnvironment pe) throws IOException {
final Filer filer = pe.getFiler();
return filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "aidl2.log");
}
示例10: createResource
import javax.annotation.processing.Filer; //导入方法依赖的package包/类
private FileObject createResource(final Filer filer, final String path) throws Exception {
return filer.createResource(CLASS_OUTPUT, StringUtils.EMPTY, path);
}