use of javax.tools.FileObject in project druid by druid-io.
the class OssDataSegmentPuller method buildFileObject.
private FileObject buildFileObject(final URI uri) throws OSSException {
final CloudObjectLocation coords = new CloudObjectLocation(OssUtils.checkURI(uri));
final OSSObjectSummary objectSummary = OssUtils.getSingleObjectSummary(client, coords.getBucket(), coords.getPath());
final String path = uri.getPath();
return new FileObject() {
OSSObject ossObject = null;
@Override
public URI toUri() {
return uri;
}
@Override
public String getName() {
final String ext = Files.getFileExtension(path);
return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext));
}
/**
* Returns an input stream for an OSS object. The returned input stream is not thread-safe.
*/
@Override
public InputStream openInputStream() throws IOException {
try {
if (ossObject == null) {
// lazily promote to full GET
ossObject = client.getObject(objectSummary.getBucketName(), objectSummary.getKey());
}
final InputStream in = ossObject.getObjectContent();
final Closer closer = Closer.create();
closer.register(in);
closer.register(ossObject);
return new FilterInputStream(in) {
@Override
public void close() throws IOException {
closer.close();
}
};
} catch (OSSException e) {
throw new IOE(e, "Could not load OSS URI [%s]", uri);
}
}
@Override
public OutputStream openOutputStream() {
throw new UOE("Cannot stream OSS output");
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) {
throw new UOE("Cannot open reader");
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
throw new UOE("Cannot open character sequence");
}
@Override
public Writer openWriter() {
throw new UOE("Cannot open writer");
}
@Override
public long getLastModified() {
return objectSummary.getLastModified().getTime();
}
@Override
public boolean delete() {
throw new UOE("Cannot delete OSS items anonymously. jetS3t doesn't support authenticated deletes easily.");
}
};
}
use of javax.tools.FileObject in project dubbo by alibaba.
the class TypeUtils method getResource.
static URL getResource(ProcessingEnvironment processingEnv, CharSequence type) {
String relativeName = getResourceName(type);
URL resource = null;
try {
if (relativeName != null) {
FileObject fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", relativeName);
resource = fileObject.toUri().toURL();
// try to open it
resource.getContent();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return resource;
}
use of javax.tools.FileObject in project androidannotations by androidannotations.
the class FileHelper method findRootProjectHolder.
/**
* 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 static FileHolder findRootProjectHolder(ProcessingEnvironment processingEnv) throws FileNotFoundException {
FileHolder rootProjectHolder = findKaptRootProjectHolder(processingEnv);
if (rootProjectHolder != null) {
return rootProjectHolder;
}
Filer filer = processingEnv.getFiler();
FileObject dummySourceFile;
try {
dummySourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "dummy" + System.currentTimeMillis());
} catch (IOException ignored) {
throw new FileNotFoundException();
}
return createFileHolder(dummySourceFile.toUri().toString());
}
use of javax.tools.FileObject in project Payara by payara.
the class RestModelExtensionProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> elements, RoundEnvironment env) {
Messager messager = processingEnv.getMessager();
BufferedWriter bw = null;
try {
Map<String, List<String>> classes = new HashMap<String, List<String>>();
for (TypeElement te : elements) {
for (Element e : env.getElementsAnnotatedWith(te)) {
final RestModelExtension annotation = e.getAnnotation(RestModelExtension.class);
final String parent = annotation.parent();
List<String> list = classes.get(parent);
if (list == null) {
list = new ArrayList<String>();
classes.put(parent, list);
}
list.add(e.toString());
}
}
if (!classes.isEmpty()) {
final Filer filer = processingEnv.getFiler();
FileObject fo = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/restmodelextensions");
bw = new BufferedWriter(fo.openWriter());
// parent model:model extension
for (Map.Entry<String, List<String>> entry : classes.entrySet()) {
final String key = entry.getKey();
for (String ext : entry.getValue()) {
bw.write(key + ":" + ext + "\n");
}
}
bw.close();
}
} catch (IOException ex) {
messager.printMessage(Kind.ERROR, ex.getLocalizedMessage());
if (bw != null) {
try {
bw.close();
} catch (Exception e) {
}
}
}
return true;
}
use of javax.tools.FileObject in project gradle by gradle.
the class IncrementalFiler method createResource.
@Override
public final FileObject createResource(JavaFileManager.Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException {
// Prefer having javac validate the location over us, by calling it first.
FileObject resource = delegate.createResource(location, pkg, relativeName, originatingElements);
strategy.recordGeneratedResource(location, pkg, relativeName, originatingElements);
return resource;
}
Aggregations