use of javax.tools.FileObject in project druid by druid-io.
the class S3DataSegmentPuller method buildFileObject.
public static FileObject buildFileObject(final URI uri, final RestS3Service s3Client) throws ServiceException {
final S3Coords coords = new S3Coords(checkURI(uri));
final StorageObject s3Obj = s3Client.getObjectDetails(coords.bucket, coords.path);
final String path = uri.getPath();
return new FileObject() {
final Object inputStreamOpener = new Object();
volatile boolean streamAcquired = false;
volatile StorageObject storageObject = s3Obj;
@Override
public URI toUri() {
return uri;
}
@Override
public String getName() {
final String ext = Files.getFileExtension(path);
return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext));
}
@Override
public InputStream openInputStream() throws IOException {
try {
synchronized (inputStreamOpener) {
if (streamAcquired) {
return storageObject.getDataInputStream();
}
// lazily promote to full GET
storageObject = s3Client.getObject(s3Obj.getBucketName(), s3Obj.getKey());
final InputStream stream = storageObject.getDataInputStream();
streamAcquired = true;
return stream;
}
} catch (ServiceException e) {
throw new IOException(StringUtils.safeFormat("Could not load S3 URI [%s]", uri), e);
}
}
@Override
public OutputStream openOutputStream() throws IOException {
throw new UOE("Cannot stream S3 output");
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
throw new UOE("Cannot open reader");
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
throw new UOE("Cannot open character sequence");
}
@Override
public Writer openWriter() throws IOException {
throw new UOE("Cannot open writer");
}
@Override
public long getLastModified() {
return s3Obj.getLastModifiedDate().getTime();
}
@Override
public boolean delete() {
throw new UOE("Cannot delete S3 items anonymously. jetS3t doesn't support authenticated deletes easily.");
}
};
}
use of javax.tools.FileObject in project buck by facebook.
the class ClassUsageTrackerTest method readingNonJavaFileFromGetFileForInputShouldBeTracked.
@Test
public void readingNonJavaFileFromGetFileForInputShouldBeTracked() throws IOException {
final FileObject fileObject = fileManager.getFileForInput(null, null, SINGLE_NON_JAVA_FILE_NAME);
fileObject.openInputStream();
assertTrue(fileWasRead(TEST_JAR_PATH, SINGLE_NON_JAVA_FILE_NAME));
}
use of javax.tools.FileObject in project buck by facebook.
the class ClassUsageTrackerTest method readingJavaFileFromGetFileForOutputShouldBeTracked.
@Test
public void readingJavaFileFromGetFileForOutputShouldBeTracked() throws IOException {
final FileObject fileObject = fileManager.getFileForOutput(null, null, SINGLE_FILE_NAME, null);
fileObject.openInputStream();
assertFilesRead(TEST_JAR_PATH, SINGLE_FILE_NAME);
}
use of javax.tools.FileObject in project buck by facebook.
the class ClassUsageTrackerTest method readingJavaFileFromGetFileForInputShouldBeTracked.
@Test
public void readingJavaFileFromGetFileForInputShouldBeTracked() throws IOException {
final FileObject fileObject = fileManager.getFileForInput(null, null, SINGLE_FILE_NAME);
fileObject.openInputStream();
assertFilesRead(TEST_JAR_PATH, SINGLE_FILE_NAME);
}
use of javax.tools.FileObject in project buck by facebook.
the class AnnotationProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_PATH, "", "read_file.txt");
InputStream stream = resource.openInputStream();
stream.read();
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not open read_file.txt");
}
return false;
}
Aggregations