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.richfaces.request.FileUploadDiscResource.java

public void complete() {
    Closeables.closeQuietly(fos);
    fos = null;
}

From source file:org.sonar.plugins.android.lint.AndroidLintRuleParser.java

/**
 * Warning : the input stream is closed in this method
 *///from   w ww .  j  a va 2  s .  c  om
public List<Rule> parse(InputStream input) {
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input, CharEncoding.UTF_8));
        return parse(reader);

    } catch (IOException e) {
        throw new SonarException("Fail to load the xml stream", e);

    } finally {
        Closeables.closeQuietly(reader);
    }
}

From source file:org.jclouds.compute.domain.ExecChannel.java

/**
 * closes resources associated with this channel.
 *//*from  ww w .j ava  2s  .c  o m*/
@Override
public void close() throws IOException {
    Closeables.closeQuietly(input);
    Closeables.closeQuietly(output);
    Closeables.closeQuietly(error);
    closer.close();
}

From source file:net.sourceforge.docfetcher.model.index.IndexWriterAdapter.java

private void reopenWriterAndThrow(@NotNull OutOfMemoryError e) throws IOException, CheckedOutOfMemoryError {
    /*//from w  w  w  .  java2 s . co m
     * According to the IndexWriter javadoc, we're supposed to immediately
     * close the IndexWriter if IndexWriter.addDocument(...) or
     * IndexWriter.updateDocument(...) hit OutOfMemoryErrors.
     */
    Directory indexDir = writer.getDirectory();
    Closeables.closeQuietly(writer);
    writer = new IndexWriter(indexDir, IndexRegistry.analyzer, MaxFieldLength.UNLIMITED);
    throw new CheckedOutOfMemoryError(e);
}

From source file:com.eviware.loadui.impl.reporting.LReportTemplate.java

private String readTemplateFile() {
    StringBuilder result = new StringBuilder();
    File reportFile = new File(path);
    this.lastModified = reportFile.lastModified();
    BufferedReader reader = null;
    try {/*w  w w  .  j  a  v a 2 s  .c  om*/
        reader = new BufferedReader(new FileReader(reportFile));
        String line = null;
        while ((line = reader.readLine()) != null) {
            result.append(line);
        }
    } catch (FileNotFoundException e) {
        log.error("Report template file not found " + path, e);
    } catch (IOException e) {
        log.error("Error reading report template file " + path, e);
    } finally {
        Closeables.closeQuietly(reader);
    }
    return result.toString();
}

From source file:cff.bench.convert.csv.ConvertUtils.java

public static void convertCsvToParquet(File csvFile, File schemaFile, File outputParquetFile,
        final String delimiter, boolean enableDictionary) throws IOException {
    String rawSchema = getSchema(schemaFile);
    if (outputParquetFile.exists()) {
        throw new IOException("Output file " + outputParquetFile.getAbsolutePath() + " already exists");
    }/*from  ww  w.j  a  v a  2  s  .c o m*/

    Path path = new Path(outputParquetFile.toURI());

    MessageType schema = MessageTypeParser.parseMessageType(rawSchema);
    CsvParquetWriter writer = new CsvParquetWriter(path, schema, enableDictionary);

    BufferedReader br = new BufferedReader(new FileReader(csvFile));
    String line;
    try {
        while ((line = br.readLine()) != null) {
            String[] fields = line.split(Pattern.quote(delimiter));
            writer.write(Arrays.asList(fields));
        }

        writer.close();
    } finally {
        Closeables.closeQuietly(br);
    }
}

From source file:com.metamx.druid.utils.CompressionUtils.java

public static void unzip(File pulledFile, File outDir) throws IOException {
    if (!(outDir.exists() && outDir.isDirectory())) {
        throw new ISE("outDir[%s] must exist and be a directory", outDir);
    }//from   w  w  w.  j  a v a2  s .  c  o  m

    log.info("Unzipping file[%s] to [%s]", pulledFile, outDir);
    InputStream in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(pulledFile));
        unzip(in, outDir);
    } finally {
        Closeables.closeQuietly(in);
    }
}

From source file:ch.ledcom.log4jtools.Log4JXMLCategorizer.java

private static List<CategorizationFilter> readConfig(File configFile)
        throws InvalidFormatException, IOException {

    ConfigReader configReader = new ConfigReader();

    InputStream in = new FileInputStream(configFile);
    List<CategorizationFilter> filters;
    try {//from   ww  w  . j a v a 2  s . c o  m
        filters = configReader.loadConfig(in);
    } finally {
        Closeables.closeQuietly(in);
    }
    for (CategorizationFilter filter : filters) {
        System.out.println(filter);
    }

    return filters;
}

From source file:org.renyan.leveldb.impl.MMapLogWriter.java

public synchronized void close() throws IOException {
    closed.set(true);/*ww  w  .j a va2  s. c  o  m*/

    destroyMappedByteBuffer();

    if (fileChannel.isOpen()) {
        fileChannel.truncate(fileOffset);
    }

    // close the channel
    Closeables.closeQuietly(fileChannel);
}

From source file:tv.floe.metronome.classification.logisticregression.POLRModelParameters.java

/**
 * Reads a model from a file.//from w w w .  j a va 2 s  .  c  o m
 * 
 * @throws IOException
 *           If there is an error opening or closing the file.
 */
public static POLRModelParameters loadFrom(File in) throws IOException {
    InputStream input = new FileInputStream(in);
    try {
        return loadFrom(input);
    } finally {
        Closeables.closeQuietly(input);
    }
}