use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class UnderFileSystemBlockReader method close.
/**
* Closes the block reader. After this, this block reader should not be used anymore.
* This is recommended to be called after the client finishes reading the block. It is usually
* triggered when the client unlocks the block.
*
* @throws IOException if any I/O errors occur
*/
@Override
public void close() throws IOException {
if (mClosed) {
return;
}
try {
// This aborts the block if the block is not fully read.
updateBlockWriter(mBlockMeta.getBlockSize());
Closer closer = Closer.create();
if (mBlockWriter != null) {
closer.register(mBlockWriter);
}
if (mUnderFileSystemInputStream != null) {
closer.register(mUnderFileSystemInputStream);
}
closer.close();
} finally {
mClosed = true;
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class CpCommand method copyFile.
/**
* Copies a file in the Alluxio filesystem.
*
* @param srcPath the source {@link AlluxioURI} (has to be a file)
* @param dstPath the destination path in the Alluxio filesystem
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void copyFile(AlluxioURI srcPath, AlluxioURI dstPath) throws AlluxioException, IOException {
try (Closer closer = Closer.create()) {
OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
FileInStream is = closer.register(mFileSystem.openFile(srcPath, openFileOptions));
CreateFileOptions createFileOptions = CreateFileOptions.defaults();
FileOutStream os = closer.register(mFileSystem.createFile(dstPath, createFileOptions));
IOUtils.copy(is, os);
System.out.println("Copied " + srcPath + " to " + dstPath);
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class LoadCommand method load.
/**
* Loads a file or directory in Alluxio space, makes it resident in memory.
*
* @param filePath The {@link AlluxioURI} path to load into Alluxio memory
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void load(AlluxioURI filePath) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(filePath);
if (status.isFolder()) {
List<URIStatus> statuses = mFileSystem.listStatus(filePath);
for (URIStatus uriStatus : statuses) {
AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
load(newPath);
}
} else {
if (status.getInMemoryPercentage() == 100) {
// The file has already been fully loaded into Alluxio memory.
return;
}
Closer closer = Closer.create();
try {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
FileInStream in = closer.register(mFileSystem.openFile(filePath, options));
byte[] buf = new byte[8 * Constants.MB];
while (in.read(buf) != -1) {
}
} catch (Exception e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
System.out.println(filePath + " loaded");
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project beam by apache.
the class ZipFiles method zipDirectory.
/**
* Zips an entire directory specified by the path.
*
* @param sourceDirectory the directory to read from. This directory and all
* subdirectories will be added to the zip-file. The path within the zip
* file is relative to the directory given as parameter, not absolute.
* @param zipFile the zip-file to write to.
* @throws IOException the zipping failed, e.g. because the input was not
* readable.
*/
static void zipDirectory(File sourceDirectory, File zipFile) throws IOException {
checkNotNull(sourceDirectory);
checkNotNull(zipFile);
checkArgument(sourceDirectory.isDirectory(), "%s is not a valid directory", sourceDirectory.getAbsolutePath());
checkArgument(!zipFile.exists(), "%s does already exist, files are not being overwritten", zipFile.getAbsolutePath());
Closer closer = Closer.create();
try {
OutputStream outputStream = closer.register(new BufferedOutputStream(new FileOutputStream(zipFile)));
zipDirectory(sourceDirectory, outputStream);
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project jackrabbit-oak by apache.
the class ReadOnlyFileStore method close.
@Override
public void close() {
Closer closer = Closer.create();
closer.register(tarFiles);
closer.register(revisions);
closeAndLogOnFail(closer);
// for any memory-mappings that are no longer used
System.gc();
log.info("TarMK closed: {}", directory);
}
Aggregations