Search in sources :

Example 51 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.

the class UfsJournalLogWriter method close.

@Override
public synchronized void close() throws IOException {
    Closer closer = Closer.create();
    if (mJournalOutputStream != null) {
        closer.register(mJournalOutputStream);
    }
    closer.register(mGarbageCollector);
    closer.close();
    mClosed = true;
}
Also used : Closer(com.google.common.io.Closer)

Example 52 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.

the class CachingInodeStore method close.

@Override
public void close() {
    Closer closer = Closer.create();
    // Close the backing store last so that cache eviction threads don't hit errors.
    closer.register(mBackingStore);
    closer.register(mInodeCache);
    closer.register(mEdgeCache);
    try {
        closer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Closer(com.google.common.io.Closer) IOException(java.io.IOException)

Example 53 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project commons by twitter.

the class FileEchoer method echo.

@Override
public String echo() throws IOException {
    Closer closer = Closer.create();
    try {
        FileReader fileReader = closer.register(new FileReader("/etc/hosts"));
        BufferedReader bufferedReader = closer.register(new BufferedReader(fileReader));
        return bufferedReader.readLine();
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 54 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project atlas by alibaba.

the class AtlasDataBindingMergeArtifactsTransform method extractBinFilesFromJar.

private void extractBinFilesFromJar(File jarFile) throws IOException {
    File jarOutFolder = getOutFolderForJarFile(jarFile);
    FileUtils.deleteQuietly(jarOutFolder);
    FileUtils.forceMkdir(jarOutFolder);
    try (Closer localCloser = Closer.create()) {
        FileInputStream fis = localCloser.register(new FileInputStream(jarFile));
        ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                continue;
            }
            String name = entry.getName();
            if (!isResource(name)) {
                continue;
            }
            // get rid of the path. We don't need it since the file name includes the domain
            name = new File(name).getName();
            File out = new File(jarOutFolder, name);
            // noinspection ResultOfMethodCallIgnored
            FileOutputStream fos = localCloser.register(new FileOutputStream(out));
            ByteStreams.copy(zis, fos);
            zis.closeEntry();
        }
    }
}
Also used : Closer(com.google.common.io.Closer) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 55 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project atlas by alibaba.

the class AwbDataBindingMergeArtifactsTask method extractBinFilesFromJar.

private void extractBinFilesFromJar(File outFolder, File jarFile) throws IOException {
    File jarOutFolder = getOutFolderForJarFile(outFolder, jarFile);
    if (jarOutFolder.exists()) {
        FileUtils.deleteDirectoryContents(jarOutFolder);
    } else {
        FileUtils.mkdirs(jarOutFolder);
    }
    try (Closer localCloser = Closer.create()) {
        FileInputStream fis = localCloser.register(new FileInputStream(jarFile));
        ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                continue;
            }
            String name = entry.getName();
            if (!isResource(name)) {
                continue;
            }
            // get rid of the path. We don't need it since the file name includes the domain
            name = new File(name).getName();
            File out = new File(jarOutFolder, name);
            // noinspection ResultOfMethodCallIgnored
            FileOutputStream fos = localCloser.register(new FileOutputStream(out));
            ByteStreams.copy(zis, fos);
            zis.closeEntry();
        }
    }
}
Also used : Closer(com.google.common.io.Closer) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

Closer (com.google.common.io.Closer)213 IOException (java.io.IOException)95 File (java.io.File)26 Test (org.testng.annotations.Test)21 Path (org.apache.hadoop.fs.Path)18 Test (org.junit.Test)18 Properties (java.util.Properties)16 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)16 FileOutputStream (java.io.FileOutputStream)15 ArrayList (java.util.ArrayList)15 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)13 FileInputStream (java.io.FileInputStream)12 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)12 Map (java.util.Map)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 DataInputStream (java.io.DataInputStream)10 UncheckedIOException (java.io.UncheckedIOException)10 Configuration (org.apache.hadoop.conf.Configuration)10 Text (org.apache.hadoop.io.Text)9