@Override public boolean exists(String remoteRelativePath) throws IOException { return fs.exists(new Path(getRemoteAbsolutePath(remoteRelativePath))); }
@Override public InputStream getInputStream(String remoteRelativePath) throws IOException { InputStream inputStream = fs.open(new Path(getRemoteAbsolutePath(remoteRelativePath))); if (compressionCodec == null) { return inputStream; } else { switch (compressionCodec) { case GZIP: return new GZIPInputStream(inputStream); default: throw new RuntimeException("Compression codec not supported: " + compressionCodec); } } }
@Override public OutputStream getOutputStream(String remoteRelativePath) throws IOException { OutputStream outputStream = fs.create(new Path(getRemoteAbsolutePath(remoteRelativePath)), false); if (compressionCodec == null) { return outputStream; } else { switch (compressionCodec) { case GZIP: return new GZIPOutputStream(outputStream); default: throw new RuntimeException("Compression codec not supported: " + compressionCodec); } } }
public static String getRemoteAbsolutePath(String remoteDomainRoot, int partitionNumber, String relativePath) throws IOException { return new HdfsPartitionRemoteFileOps(remoteDomainRoot, partitionNumber).getRemoteAbsolutePath(relativePath); }
public static String getRemoteAbsolutePath(String remoteDomainRoot, int partitionNumber, String relativePath, CompressionCodec compressionCodec) throws IOException { return new HdfsPartitionRemoteFileOps(remoteDomainRoot, partitionNumber, compressionCodec).getRemoteAbsolutePath(relativePath); }
@Override public boolean attemptDelete(String remoteRelativePath) throws IOException { if (exists(remoteRelativePath)) { Path pathToDelete = new Path(getRemoteAbsolutePath(remoteRelativePath)); if (useTrash) { TrashHelper.deleteUsingTrashIfEnabled(fs, pathToDelete); } else { fs.delete(pathToDelete, true); } } return true; }
@Override public void copyToLocalRoot(String remoteSourceRelativePath, String localDestinationRoot) throws IOException { Path source = new Path(getRemoteAbsolutePath(remoteSourceRelativePath)); File destination = new File(localDestinationRoot + "/" + new Path(remoteSourceRelativePath).getName()); LOG.info("Copying remote file " + source + " to local file " + destination); InputStream inputStream = getInputStream(remoteSourceRelativePath); FileOutputStream fileOutputStream = new FileOutputStream(destination); try { IOStreamUtils.copy(inputStream, fileOutputStream); fileOutputStream.flush(); } finally { inputStream.close(); fileOutputStream.close(); } }