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.apache.mahout.graph.preprocessing.GraphUtils.java

public static void persistVector(Configuration conf, Path path, Vector vector) throws IOException {
    FileSystem fs = FileSystem.get(path.toUri(), conf);
    DataOutputStream out = fs.create(path, true);
    try {//from w  w  w.  j  a va 2s .co  m
        VectorWritable.writeVector(out, vector);
    } finally {
        Closeables.closeQuietly(out);
    }
}

From source file:com.metamx.druid.index.column.SimpleColumn.java

@Override
public int getLength() {
    GenericColumn column = null;// w w w . j  av  a  2  s.  co m
    try {
        column = genericColumn.get();
        return column.length();
    } finally {
        Closeables.closeQuietly(column);
    }
}

From source file:co.cask.cdap.common.http.AbstractBodyConsumer.java

@Override
public final void handleError(Throwable cause) {
    try {//from   w ww .  jav  a 2  s.  c  om
        LOG.error("Failed to handle upload", cause);
        if (output != null) {
            Closeables.closeQuietly(output);
        }
        onError(cause);
        // The netty-http framework will response with 500, no need to response in here.
    } finally {
        cleanup();
    }
}

From source file:org.apache.provisionr.cloudstack.commands.CommandSupport.java

@Override
protected Object doExecute() throws Exception {
    RestContext<CloudStackClient, CloudStackAsyncClient> context = null;
    try {/*from  w  w  w .  ja va2  s .  c o  m*/
        context = newCloudStackContext(provider);
        return doExecuteWithContext(context.getApi(), System.out);

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

From source file:org.messic.server.facade.controllers.pages.LoginController.java

/**
 * Obtain a timestamp based on maven. This timestamp allow to the .css and .js files to force to be updated by the
 * navigator. If a new version of messic is released, this number will change and the navigator will update those
 * files./*  ww w  . j av  a2s . c  om*/
 * 
 * @return {@link String} the timestamp
 */
private String getTimestamp() {

    ClassPathResource resource = new ClassPathResource(
            "/org/messic/server/facade/controllers/pages/timestamp.properties");
    Properties p = new Properties();
    InputStream inputStream = null;
    try {
        inputStream = resource.getInputStream();
        p.load(inputStream);
    } catch (IOException e) {
        return "12345";
    } finally {
        Closeables.closeQuietly(inputStream);
    }

    return p.getProperty("messic.timestamp");
}

From source file:org.codehaus.httpcache4j.cache.MemoryCacheStorage.java

private HTTPResponse rewriteResponse(Key key, HTTPResponse response) {
    if (response.hasPayload()) {
        Payload payload = response.getPayload();
        InputStream stream = null;
        try {/*from w w  w  .j a  va 2 s . c  o m*/
            stream = payload.getInputStream();
            return response.withPayload(createPayload(key, payload, stream));
        } catch (IOException ignore) {
        } finally {
            Closeables.closeQuietly(stream);
        }
    } else {
        return response;
    }
    throw new IllegalArgumentException("Unable to cache response");
}

From source file:uk.me.fommil.sbscharts.HoleStatsParser.java

/**
 * @return//w w  w. j a  v  a  2 s .  c o  m
 * @throws IOException
 */
public static List<HoleStats> readFromFile() throws IOException {
    try {
        List<HoleStats> holes = Lists.newArrayList();
        File file = new File(DATA_FILE);
        ZipFile zip = new ZipFile(file);
        try {
            Enumeration<? extends ZipEntry> en = zip.entries();
            while (en.hasMoreElements()) {
                ZipEntry e = en.nextElement();
                log.info(e.getName());
                InputStream in = zip.getInputStream(e);
                try {
                    InputStreamReader reader = new InputStreamReader(in);
                    CSVReader csv = new CSVReader(reader);
                    String[] line = null;
                    while ((line = csv.readNext()) != null) {
                        try {
                            HoleStats hole = parse(line);
                            holes.add(hole);
                        } catch (ParseException ex) {
                            log.info("skipping line " + ex.getMessage());
                        }
                    }
                } finally {
                    Closeables.closeQuietly(in);
                }
            }
            return holes;
        } finally {
            try {
                zip.close();
            } catch (IOException e) {
                log.warning("couldn't close the zipfile");
            }
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
}

From source file:org.sonar.api.rules.XMLRuleParser.java

public List<Rule> parse(File file) {
    Reader reader = null;/*from   w  w  w .j a  v  a2 s .co m*/
    try {
        reader = new InputStreamReader(FileUtils.openInputStream(file), CharEncoding.UTF_8);
        return parse(reader);

    } catch (IOException e) {
        throw new SonarException("Fail to load the file: " + file, e);

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

From source file:co.cask.cdap.data.file.PartitionedFileWriter.java

@Override
public void append(T event) throws IOException {
    if (closed) {
        throw new IOException("Attempts to write to a closed FileWriter.");
    }//from w  w w. j a v  a2s.  com

    try {
        getWriter(event).append(event);
    } catch (Throwable t) {
        LOG.error("Exception on append.", t);
        Closeables.closeQuietly(this);
        Throwables.propagateIfInstanceOf(t, IOException.class);
        throw Throwables.propagate(t);
    }
}

From source file:com.enonic.cms.core.xslt.base.XsltProcessorImpl.java

/**
 * Process the xml with stylesheet./*  w ww.j a  v a 2  s  .  c  o m*/
 */
public String process(Source xml) throws XsltProcessorException {
    StringWriter writer = new StringWriter();

    try {
        process(xml, writer);
    } finally {
        Closeables.closeQuietly(writer);
    }

    return writer.toString();
}