Example usage for com.google.common.io Closeables closeQuietly

List of usage examples for com.google.common.io Closeables closeQuietly

Introduction

In this page you can find the example usage for com.google.common.io Closeables closeQuietly.

Prototype

public static void closeQuietly(@Nullable Reader reader) 

Source Link

Document

Closes the given Reader , logging any IOException that's thrown rather than propagating it.

Usage

From source file:org.kitesdk.apps.test.apps.AltScheduledInputOutputJob.java

public void run(@DataIn(name = "source_users") View<GenericRecord> input,
        @DataOut(name = "target_users") View<GenericRecord> output) {

    DatasetReader<GenericRecord> reader = input.newReader();
    DatasetWriter<GenericRecord> writer = output.newWriter();

    try {//w ww .j  a v a  2 s  . c  om
        while (reader.hasNext()) {

            writer.write(reader.next());
        }
    } finally {

        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(writer);
    }
}

From source file:org.cretz.sbnstat.scrape.Cache.java

public Cache(File directory) throws IOException {
    this.directory = directory;
    //directory doesn't exist? create it then...
    if (!directory.exists()) {
        directory.mkdirs();/*from   w  ww .j a  va  2  s . c  om*/
    }
    urls = new Properties();
    //load the file if it's there
    urlsFile = new File(directory, "urls.properties");
    if (urlsFile.exists()) {
        Reader reader = new FileReader(urlsFile);
        try {
            urls.load(reader);
        } finally {
            Closeables.closeQuietly(reader);
        }
    }
}

From source file:co.cask.cdap.filetailer.config.ConfigurationLoaderImpl.java

@Override
public Configuration load(File file) throws ConfigurationLoadingException {
    LOG.debug("Start initializing loader with file: {}", file.getAbsolutePath());
    Properties properties = new Properties();
    try {//w ww  .  java  2s .c o  m
        InputStream is = new FileInputStream(file);
        try {
            properties.load(is);
            LOG.debug("Loader successfully initialized with file: {}", file.getAbsolutePath());
        } finally {
            Closeables.closeQuietly(is);
        }
    } catch (IOException e) {
        LOG.error("Cannot load properties", e);
        throw new ConfigurationLoadingException("Cannot load properties: " + e.getMessage());
    }
    return new ConfigurationImpl(properties);
}

From source file:com.eviware.loadui.impl.Init.java

public void initJIDE() {
    InputStream licenseStream = null;
    try {//from www  .j av  a 2s . c  o m
        Properties jidedata = new Properties();
        licenseStream = Init.class.getResourceAsStream("/properties/jide.properties");
        jidedata.load(licenseStream);
        String company = jidedata.getProperty("company");
        log.debug("Initializing JIDE for {}", company);
        Lm.verifyLicense(company, jidedata.getProperty("product"), jidedata.getProperty("license"));
    } catch (Exception e) {
        log.error("Failed to initialize JIDE:", e);
    } finally {
        Closeables.closeQuietly(licenseStream);
    }
}

From source file:eu.redzoo.reactive.sse.SSEInputStream.java

public void close() {
    Closeables.closeQuietly(is);
}

From source file:org.kitesdk.apps.test.apps.WriteConfigOutputJob.java

public void run(@DataOut(name = "kv-output", type = KeyValues.class) View<KeyValues> output) {

    DatasetWriter<KeyValues> writer = output.newWriter();

    try {// www  . j av a2 s  .co m

        JobContext context = getJobContext();

        KeyValues kv = KeyValues.newBuilder().setJobsettings(context.getSettings())
                .setOutputsettings(context.getOutputSettings("kv-output")).build();

        writer.write(kv);

    } finally {

        Closeables.closeQuietly(writer);
    }
}

From source file:org.sonatype.nexus.common.io.TempStreamSupplier.java

public TempStreamSupplier(final InputStream inputStream) throws IOException {
    tempFile = Files.createTempFile("", "");
    try (OutputStream outputStream = Files.newOutputStream(tempFile)) {
        ByteStreams.copy(inputStream, outputStream);
    } finally {/*from   w ww.  ja v  a  2 s .  com*/
        Closeables.closeQuietly(inputStream);
    }
}

From source file:interactivespaces.util.data.resource.MessageDigestResourceSignature.java

@Override
public String getBundleSignature(File bundleFile) {
    FileInputStream fis = null;/* ww w.j a va2 s .c om*/

    try {
        fis = new FileInputStream(bundleFile);
        return getBundleSignature(fis);
    } catch (Exception e) {
        throw new SimpleInteractiveSpacesException(
                String.format("Could not create signature for file %s", bundleFile.getAbsolutePath()), e);
    } finally {
        Closeables.closeQuietly(fis);
    }
}

From source file:com.netflix.exhibitor.core.backup.TempCompressedFile.java

void compress() throws IOException {
    byte[] buffer = new byte[BUFFER_SIZE];

    InputStream in = null;/*www.ja v  a 2 s  .  c  o  m*/
    OutputStream out = null;
    try {
        in = new FileInputStream(source);
        out = new GZIPOutputStream(new FileOutputStream(tempFile));

        for (;;) {
            int bytesRead = in.read(buffer);
            if (bytesRead < 0) {
                break;
            }
            out.write(buffer, 0, bytesRead);
        }
    } finally {
        Closeables.closeQuietly(in);
        Closeables.closeQuietly(out);
    }
}

From source file:org.jooby.internal.BodyReaderImpl.java

@SuppressWarnings("unchecked")
@Override/*from  w  w w .  jav a 2s.com*/
public <T> T text(final Text text) throws Exception {
    Reader reader = null;
    try {
        reader = new InputStreamReader(this.stream.get(), charset);
        return (T) text.read(reader);
    } finally {
        Closeables.closeQuietly(reader);
    }
}