Example usage for org.apache.commons.io IOUtils closeQuietly

List of usage examples for org.apache.commons.io IOUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils closeQuietly.

Prototype

public static void closeQuietly(OutputStream output) 

Source Link

Document

Unconditionally close an OutputStream.

Usage

From source file:com.basistech.problem.Trouble.java

public void close(InputStream stream) {
    IOUtils.closeQuietly(stream);
}

From source file:com.lyricaloriginal.picturediaryapp.OssActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_oss);
    InputStream is = null;//from w w  w .  j av a2  s. c  o m
    try {
        is = getAssets().open("apache_license.txt");
        List<String> lines = IOUtils.readLines(is, "UTF-8");
        TextView v = (TextView) findViewById(R.id.apacheLicTextView);
        for (String l : lines) {
            v.append(l + "\n");
        }
    } catch (IOException ex) {
        Log.e("DIARY", ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:cd.go.authentication.passwordfile.PasswordFileReader.java

public Properties read(String passwordFilePath) throws IOException {
    final Properties properties = new Properties();
    InputStream inputStream = null;
    try {//  ww w . j a v a2  s.co m
        inputStream = new FileInputStream(passwordFilePath);
        properties.load(inputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    return properties;
}

From source file:de.dfki.asr.compass.web.util.ResourceLoader.java

public String getResourceAsString(String resourceName) throws IOException {
    InputStream resourceStream = getResourceAsStream(resourceName);
    try {/*from  w  ww.jav a  2 s  .c  om*/
        return IOUtils.toString(resourceStream);
    } catch (IOException e) {
        throw e;
    } finally {
        IOUtils.closeQuietly(resourceStream);
    }
}

From source file:be.roots.taconic.pricingguide.util.HttpUtil.java

public static String readString(String urlAsString, String userName, String password) {

    try {/*  w  w  w  .ja  v  a2s.  c o m*/
        final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password);
        final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        final String response = IOUtils.toString(in);
        IOUtils.closeQuietly(in);
        return response;
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return null;

}

From source file:com.ettrema.http.fs.SimpleFileContentService.java

@Override
public void setFileContent(File file, InputStream in) throws FileNotFoundException, IOException {
    FileOutputStream out = null;/*w ww .j  a v a  2s.  c o m*/
    try {
        out = new FileOutputStream(file);
        IOUtils.copy(in, out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:hudson.plugins.sonar.utils.SonarUtils.java

/**
 * Read logs of the build to find URL of the project dashboard in Sonar
 *///from   ww  w . ja va 2s. co m
public static String extractSonarProjectURLFromLogs(AbstractBuild<?, ?> build) throws IOException {
    BufferedReader br = null;
    String url = null;
    try {
        br = new BufferedReader(build.getLogReader());
        String strLine;
        while ((strLine = br.readLine()) != null) {
            Pattern p = Pattern.compile(URL_PATTERN_IN_LOGS);
            Matcher match = p.matcher(strLine);
            if (match.matches()) {
                url = match.group(1);
            }
        }
    } finally {
        IOUtils.closeQuietly(br);
    }
    return url;
}

From source file:com.oprisnik.semdroid.utils.FileUtils.java

public static void writeObjectToStream(Object object, OutputStream output) throws IOException {
    ObjectOutputStream out = null;
    try {//from www.  j  ava2 s  .  c  om
        out = new ObjectOutputStream(new BufferedOutputStream(output));
        out.writeObject(object);
        out.flush();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.asual.summer.onejar.OneJarServer.java

private static String getCurrentWarFile() throws IOException {
    JarFile jarFile = new JarFile(System.getProperty("java.class.path"));
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        String name = entries.nextElement().getName();
        if (name.endsWith(".war")) {
            File war = new File(new File(System.getProperty("java.io.tmpdir")),
                    "summer-onejar-" + System.currentTimeMillis() + ".war");
            InputStream input = jarFile.getInputStream(new ZipEntry(name));
            FileOutputStream output = new FileOutputStream(war);
            IOUtils.copy(input, output);
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
            war.deleteOnExit();//from   ww  w . j  a  v  a  2s  .co  m
            return war.getAbsolutePath();
        }
    }
    return null;
}

From source file:net.erdfelt.android.sdkfido.Build.java

public static String getVersion() {
    if (version == null) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        String resource = String.format("META-INF/maven/%s/%s/pom.properties", GROUP_ID, ARTIFACT_ID);
        URL url = cl.getResource(resource);
        if (url == null) {
            version = "[DEV]";
        } else {/*from ww w  . j a va 2 s .  c  om*/
            InputStream in = null;
            try {
                in = url.openStream();
                Properties props = new Properties();
                props.load(in);
                version = props.getProperty("version");
            } catch (IOException e) {
                LOG.log(Level.WARNING, "Unable to read: " + url, e);
                version = "[UNKNOWN]";
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    }
    return version;
}