List of usage examples for javax.tools FileObject FileObject
FileObject
From source file:io.druid.storage.s3.S3DataSegmentPuller.java
public static FileObject buildFileObject(final URI uri, final RestS3Service s3Client) throws S3ServiceException { final S3Coords coords = new S3Coords(checkURI(uri)); final S3Object s3Obj = s3Client.getObject(coords.bucket, coords.path); final String path = uri.getPath(); return new FileObject() { volatile boolean streamAcquired = false; @Override//ww w. java2 s. c o m 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 { streamAcquired = true; return s3Obj.getDataInputStream(); } catch (ServiceException e) { throw new IOException(String.format("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."); } @Override public void finalize() throws Throwable { try { if (!streamAcquired) { s3Obj.closeDataInputStream(); } } finally { super.finalize(); } } }; }
From source file:io.druid.storage.hdfs.HdfsDataSegmentPuller.java
public static FileObject buildFileObject(final URI uri, final Configuration config, final Boolean overwrite) { return new FileObject() { final Path path = new Path(uri); @Override/* w w w .j a v a2 s .c om*/ public URI toUri() { return uri; } @Override public String getName() { return path.getName(); } @Override public InputStream openInputStream() throws IOException { final FileSystem fs = path.getFileSystem(config); return fs.open(path); } @Override public OutputStream openOutputStream() throws IOException { final FileSystem fs = path.getFileSystem(config); return fs.create(path, overwrite); } @Override public Reader openReader(boolean ignoreEncodingErrors) { throw new UOE("HDFS Reader not supported"); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { throw new UOE("HDFS CharSequence not supported"); } @Override public Writer openWriter() { throw new UOE("HDFS Writer not supported"); } @Override public long getLastModified() { try { final FileSystem fs = path.getFileSystem(config); return fs.getFileStatus(path).getModificationTime(); } catch (IOException ex) { throw new HdfsIOException(ex); } } @Override public boolean delete() { try { final FileSystem fs = path.getFileSystem(config); return fs.delete(path, false); } catch (IOException ex) { throw new HdfsIOException(ex); } } }; }
From source file:io.druid.storage.oss.OssDataSegmentPuller.java
private FileObject buildFileObjects(final URI uri, final OSSClient ossClient) { // get index data from oss final OSSObject ossObject = ossClient.getObject(getBucket(uri), getKey(uri)); return new FileObject() { final Object inputStreamOpener = new Object(); volatile boolean streamAcquired = false; volatile OSSObject storageObject = ossObject; @Override//w w w . ja v a 2s. c o m public URI toUri() { return uri; } @Override public String getName() { return Files.getNameWithoutExtension(uri.getPath()) + "." + Files.getFileExtension(uri.getPath()); } @Override public InputStream openInputStream() throws IOException { synchronized (inputStreamOpener) { if (streamAcquired) { return storageObject.getObjectContent(); } // lazily promote to full GET storageObject = ossClient.getObject(storageObject.getBucketName(), storageObject.getKey()); final InputStream stream = storageObject.getObjectContent(); streamAcquired = true; return stream; } } @Override public OutputStream openOutputStream() throws IOException { throw new UOE("cannot stream oss 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 ossObject.getObjectMetadata().getLastModified().getTime(); } @Override public boolean delete() { throw new UOE("cannot delete oss items anonymously"); } }; }
From source file:org.apache.druid.storage.s3.S3DataSegmentPuller.java
private FileObject buildFileObject(final URI uri) throws AmazonServiceException { final S3Coords coords = new S3Coords(checkURI(uri)); final S3ObjectSummary objectSummary = S3Utils.getSingleObjectSummary(s3Client, coords.bucket, coords.path); final String path = uri.getPath(); return new FileObject() { S3Object s3Object = null; @Override/*w w w . java 2 s . com*/ 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 a s3 object. The returned input stream is not thread-safe. */ @Override public InputStream openInputStream() throws IOException { try { if (s3Object == null) { // lazily promote to full GET s3Object = s3Client.getObject(objectSummary.getBucketName(), objectSummary.getKey()); } final InputStream in = s3Object.getObjectContent(); final Closer closer = Closer.create(); closer.register(in); closer.register(s3Object); return new FilterInputStream(in) { @Override public void close() throws IOException { closer.close(); } }; } catch (AmazonServiceException e) { throw new IOE(e, "Could not load S3 URI [%s]", uri); } } @Override public OutputStream openOutputStream() { throw new UOE("Cannot stream S3 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 S3 items anonymously. jetS3t doesn't support authenticated deletes easily."); } }; }