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.lingxiang2014.controller.shop.SystemController.java

@RequestMapping(value = "/info", method = RequestMethod.GET)
public void info(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String s = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ().+/;=-";
    int[] cts = { 30, 15, 34, 30, 67, 26, 22, 11, 19, 24, 68, 13, 18, 11, 28, 29, 15, 30, 69, 57, 56, 42, 70,
            9 };/*from   w  w w  .j  a v  a2s .co m*/
    StringBuffer ct = new StringBuffer();
    for (int i : cts) {
        ct.append(s.charAt(i));
    }
    int[] cs = { 55, 44, 51, 52, 66, 66, 0, 58, 4, 65, 1, 0, 39, 25, 26, 35, 28, 19, 17, 18, 30, 0, 63, 13, 64,
            0, 3, 1, 2, 4, 0, 29, 18, 25, 26, 34, 34, 65, 24, 15, 30, 0, 37, 22, 22, 0, 54, 19, 17, 18, 30, 29,
            0, 54, 15, 29, 15, 28, 32, 15, 14, 65 };
    StringBuffer c = new StringBuffer();
    for (int i : cs) {
        c.append(s.charAt(i));
    }
    response.setContentType(ct.toString());
    PrintWriter printWriter = null;
    try {
        printWriter = response.getWriter();
        printWriter.write(c.toString());
        printWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(printWriter);
    }
}

From source file:com.netflix.curator.ensemble.exhibitor.DefaultExhibitorRestClient.java

@Override
public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception {
    URI uri = new URI(useSsl ? "https" : "http", null, hostname, port, uriPath, null, null);
    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    connection.addRequestProperty("Accept", mimeType);
    StringBuilder str = new StringBuilder();
    InputStream in = new BufferedInputStream(connection.getInputStream());
    try {/*  w w  w. ja va 2s.  co m*/
        for (;;) {
            int b = in.read();
            if (b < 0) {
                break;
            }
            str.append((char) (b & 0xff));
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
    return str.toString();
}

From source file:com.frostwire.gui.bittorrent.TorrentInfoManipulator.java

public TorrentInfoManipulator(File torrentFile) {
    FileInputStream fileInputStream = null;
    try {/* w ww.  j a v  a 2  s  .c  om*/
        fileInputStream = new FileInputStream(torrentFile);
        TOTorrent toTorrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(fileInputStream);
        fileInputStream.close();
        initAdditionalInfoProperties(toTorrent);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(fileInputStream);//this does a NPE check inside... so no worries.
    }
}

From source file:net.erdfelt.android.sdkfido.project.FilteredFileUtil.java

public static void copyWithExpansion(String resourceId, File destFile, Map<String, String> props) {
    URL url = FilteredFileUtil.class.getResource(resourceId);
    if (url == null) {
        LOG.log(Level.WARNING, "Unable to find resourceID: " + resourceId);
        return;//from w w w .  ja  va2 s .c  o  m
    }

    InputStream in = null;
    InputStreamReader reader = null;
    BufferedReader buf = null;
    FileWriter writer = null;
    PrintWriter out = null;
    try {
        in = url.openStream();
        reader = new InputStreamReader(in);
        buf = new BufferedReader(reader);
        writer = new FileWriter(destFile);
        out = new PrintWriter(writer);

        PropertyExpander expander = new PropertyExpander(props);
        String line;

        while ((line = buf.readLine()) != null) {
            out.println(expander.expand(line));
        }
    } catch (IOException e) {
        LOG.log(Level.WARNING, "Unable to open input stream for url: " + url, e);
    } finally {
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(buf);
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(in);
    }
}

From source file:com.cloudera.csd.tools.codahale.CodahaleMetricDefinitionFixtureTest.java

@Test
public void testEmptyFixture() {
    InputStream in = null;/*from w  ww .ja v a 2 s .com*/
    try {
        in = this.getClass().getResourceAsStream("/com/cloudera/csd/tools/codahale/empty_but_valid.json");
        CodahaleMetricDefinitionFixture fixture = JsonUtil
                .valueFromStream(CodahaleMetricDefinitionFixture.class, in);
        assertNotNull(fixture.getServiceName());
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:it.com.pyxis.jira.LocalTestProperties.java

private void loadProperties() {

    InputStream is = LocalTestProperties.class.getResourceAsStream("/localtest.properties");

    try {/* w w w . j a  v a  2s . c o  m*/
        load(is);
    } catch (IOException ex) {
        // fallback to default properties
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:eionet.gdem.conversion.converters.PDFConverter.java

@Override
public String convert(InputStream source, InputStream xslt, OutputStream result, String cnvFileExt)
        throws GDEMException, Exception {
    String pdfFile = Utils.getUniqueTmpFileName(".pdf");
    if (result != null) {
        runFOPTransformation(source, xslt, result);
    } else {/*from  w  ww.  jav  a2 s  . com*/
        try {
            result = new FileOutputStream(pdfFile);
            runFOPTransformation(source, xslt, result);
        } catch (IOException e) {
            throw new GDEMException("Error creating PDF output file " + e.toString(), e);
        } finally {
            IOUtils.closeQuietly(result);
        }
    }
    return pdfFile;
}

From source file:com.kylinolap.storage.hbase.HBaseClientKVIterator.java

@Override
public void close() {
    IOUtils.closeQuietly(scanner);
    IOUtils.closeQuietly(table);
}

From source file:com.redhat.red.offliner.PlaintextArtifactListReaderTest.java

@BeforeClass
public static void prepare() throws IOException {
    File tempDir = new File(TEMP_PLAINTEXT_DIR);
    if (tempDir.exists()) {
        FileUtils.deleteDirectory(tempDir);
    }//from www .j av  a 2s.c  om
    tempDir.mkdirs();

    List<String> resources = new ArrayList<String>(4);
    resources.add(RESOURCE0);
    resources.add(RESOURCE1);
    resources.add(RESOURCE2);
    resources.add(RESOURCE3);

    for (String resource : resources) {
        File target = new File(TEMP_PLAINTEXT_DIR, resource);
        OutputStream os = new FileOutputStream(target);

        if (resource.equals(RESOURCE0)) {
            IOUtils.closeQuietly(os);
            continue;
        }

        InputStream is = PlaintextArtifactListReaderTest.class.getClassLoader().getResourceAsStream(resource);

        try {
            IOUtils.copy(is, os);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
    }
}

From source file:eionet.gdem.conversion.converters.HTMLConverter.java

@Override
public String convert(InputStream source, InputStream xslt, OutputStream result, String cnvFileExt)
        throws GDEMException, Exception {
    String htmlFile = Utils.getUniqueTmpFileName(".html");
    if (result != null) {
        runXslTransformation(source, xslt, result);
    } else {/* www.  j a v  a2 s .  co  m*/
        try {
            result = new FileOutputStream(htmlFile);
            runXslTransformation(source, xslt, result);
        } catch (IOException e) {
            throw new GDEMException("Error creating HTML output file " + e.toString(), e);
        } finally {
            IOUtils.closeQuietly(result);
        }
    }
    return htmlFile;
}