Search in sources :

Example 1 with FileObject

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.");
        }
    };
}
Also used : StorageObject(org.jets3t.service.model.StorageObject) ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) InputStream(java.io.InputStream) FileObject(javax.tools.FileObject) StorageObject(org.jets3t.service.model.StorageObject) UOE(io.druid.java.util.common.UOE) FileObject(javax.tools.FileObject) IOException(java.io.IOException)

Example 2 with FileObject

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));
}
Also used : FileObject(javax.tools.FileObject) JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 3 with FileObject

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);
}
Also used : FileObject(javax.tools.FileObject) JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 4 with FileObject

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);
}
Also used : FileObject(javax.tools.FileObject) JavaFileObject(javax.tools.JavaFileObject) Test(org.junit.Test)

Example 5 with FileObject

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;
}
Also used : InputStream(java.io.InputStream) FileObject(javax.tools.FileObject) IOException(java.io.IOException)

Aggregations

FileObject (javax.tools.FileObject)91 IOException (java.io.IOException)57 TypeElement (javax.lang.model.element.TypeElement)19 File (java.io.File)18 PrintWriter (java.io.PrintWriter)16 Element (javax.lang.model.element.Element)14 Writer (java.io.Writer)13 Filer (javax.annotation.processing.Filer)13 BufferedWriter (java.io.BufferedWriter)12 ArrayList (java.util.ArrayList)12 OutputStream (java.io.OutputStream)11 JavaFileObject (javax.tools.JavaFileObject)11 OutputStreamWriter (java.io.OutputStreamWriter)10 Properties (java.util.Properties)10 InputStream (java.io.InputStream)8 URI (java.net.URI)8 FilerException (javax.annotation.processing.FilerException)7 MainInfo (com.predic8.membrane.annot.model.MainInfo)6 BufferedReader (java.io.BufferedReader)6 FileWriter (java.io.FileWriter)6