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.envirocar.server.rest.encoding.rdf.linker.DBPediaPhenomenonLinker.java

public DBPediaPhenomenonLinker() {
    this.properties = new Properties();
    InputStream in = null;//w ww.  j  a  v  a2  s. c om
    try {
        in = EEAPhenomenonLinker.class.getResourceAsStream(PROPERTIES);
        if (in != null) {
            properties.load(in);
        } else {
            log.warn("No {} found!", PROPERTIES);
        }

    } catch (IOException ex) {
        log.error("Error reading " + PROPERTIES, ex);
    } finally {
        Closeables.closeQuietly(in);
    }
}

From source file:org.envirocar.server.rest.encoding.rdf.linker.EEAPhenomenonLinker.java

public EEAPhenomenonLinker() {
    this.properties = new Properties();
    InputStream in = null;//from  w w  w.  ja v a  2s.  c o  m
    try {
        in = EEAPhenomenonLinker.class.getResourceAsStream(PROPERTIES);
        if (in != null) {
            properties.load(in);
        } else {
            log.warn("No {} found!", PROPERTIES);
        }

    } catch (IOException ex) {
        log.error("Error reading " + PROPERTIES, ex);
    } finally {
        Closeables.closeQuietly(in);
    }
}

From source file:org.sonar.plugins.objectivec.violations.fauxpas.FauxPasProfile.java

@Override
public RulesProfile createProfile(ValidationMessages messages) {
    LOGGER.info("Creating FauxPas Profile");
    Reader config = null;// w  w  w . jav a  2  s  . c o  m

    try {
        config = new InputStreamReader(getClass().getResourceAsStream(PROFILE_PATH));
        final RulesProfile profile = profileImporter.importProfile(config, messages);
        profile.setName(FauxPasRulesDefinition.REPOSITORY_KEY);
        profile.setLanguage(ObjectiveC.KEY);

        return profile;
    } finally {
        Closeables.closeQuietly(config);
    }
}

From source file:ru.runa.report.web.action.GetReportResourceAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from   ww  w . j  a  v a  2 s . c  o  m
    try {
        String uid = request.getParameter("uid");
        String id = request.getParameter("id");
        String fileName = System.getProperty("jboss.server.temp.dir") + "/reports/" + uid + "/" + id;

        response.setContentType("application");
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(fileName);
            IOUtils.copy(inputStream, response.getOutputStream());
            response.getOutputStream().flush();
        } finally {
            Closeables.closeQuietly(inputStream);
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.backelite.sonarqube.objectivec.issues.oclint.OCLintProfile.java

@Override
public RulesProfile createProfile(final ValidationMessages messages) {
    LOGGER.info("Creating OCLint Profile");
    Reader config = null;/*from  w  ww  . ja v a2 s  . c  o m*/

    try {
        config = new InputStreamReader(getClass().getResourceAsStream(PROFILE_PATH));
        final RulesProfile profile = profileImporter.importProfile(config, messages);
        profile.setName(OCLintRulesDefinition.REPOSITORY_KEY);
        profile.setLanguage(ObjectiveC.KEY);

        return profile;
    } finally {
        Closeables.closeQuietly(config);
    }
}

From source file:com.griddynamics.jagger.util.SerializationUtils.java

public static <T extends Serializable> T fromString(String s) {
    if (s.isEmpty()) {
        log.info("fromString({}, '{}')", fromStringCount.getAndIncrement(), s);
    }/*from  w  w  w  .j av  a 2 s. c om*/
    ObjectInputStream ois = null;
    try {
        byte[] data = Base64Coder.decode(s);
        try {
            //TODO fixes for support old reports
            ois = new JBossObjectInputStream(new ByteArrayInputStream(data));
        } catch (IOException e) {
            // /data stored not with JBoss
            ois = new ObjectInputStream(new ByteArrayInputStream(data));
        }
        T obj = (T) ois.readObject();
        return obj;
    } catch (IOException e) {
        log.error("Deserialization exception ", e);
        log.error("fromString('{}')", s);
        throw new TechnicalException(e);
    } catch (ClassNotFoundException e) {
        log.error("Deserialization exception ", e);
        throw new TechnicalException(e);
    } finally {
        Closeables.closeQuietly(ois);
    }
}

From source file:org.sonar.plugins.swift.issues.tailor.TailorProfile.java

@Override
public RulesProfile createProfile(final ValidationMessages messages) {
    LOGGER.info("Creating Tailor Profile");
    Reader config = null;/*from  w w w.ja  v  a2 s .  co m*/

    try {
        config = new InputStreamReader(getClass().getResourceAsStream(PROFILE_PATH));
        final RulesProfile profile = this.profileImporter.importProfile(config, messages);
        profile.setName(TailorRulesDefinition.REPOSITORY_KEY);
        profile.setLanguage(Swift.KEY);

        return profile;
    } finally {
        Closeables.closeQuietly(config);
    }
}

From source file:com.axemblr.provisionr.core.templates.xml.XmlTemplate.java

/**
 * @return an XmlTemplate instance resulted from parsing a file
 *///from  w  w w . j a  va  2s. com
public static XmlTemplate newXmlTemplate(File file) {
    FileReader reader = null;
    try {
        reader = new FileReader(file);
        return newXmlTemplate(CharStreams.toString(reader));

    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        Closeables.closeQuietly(reader);
    }
}

From source file:com.mucommander.ui.viewer.text.TextFactory.java

private boolean doGenericChecks(AbstractFile file) throws WarnUserException {
    // Do not allow directories
    if (file.isDirectory())
        return false;

    // Warn the user if the file looks like a binary file
    InputStream in = null;//from   w w w.java 2  s .c o m
    try {
        in = file.getInputStream();
        if (BinaryDetector.guessBinary(in))
            return false;
    } catch (IOException e) {
        // Not much too do
    } finally {
        Closeables.closeQuietly(in);
    }

    return true;
}

From source file:com.axemblr.provisionr.cloudstack.commands.CommandSupport.java

@Override
protected Object doExecute() throws Exception {
    try {/*from  www. j  a va 2  s.  co  m*/
        context = newCloudStackContext(provider);
        return doExecuteWithContext(context.getApi(), System.out);
    } finally {
        Closeables.closeQuietly(context);
    }
}