List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.hs.mail.util.FileUtils.java
public static void compress(File srcFile, File destFile) throws IOException { InputStream input = null;// w ww . j a va 2s . c o m OutputStream output = null; try { input = new BufferedInputStream(new FileInputStream(srcFile)); output = new GZIPOutputStream(new FileOutputStream(destFile)); IOUtils.copyLarge(input, output); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } }
From source file:com.groupon.jenkins.dynamic.buildconfiguration.EffectiveBuildConfigurationCalculator.java
private static String readFile(String ymlResource) { InputStream base = null;/*www.j a v a 2 s . c om*/ try { base = EffectiveBuildConfigurationCalculator.class.getResourceAsStream(ymlResource); return IOUtils.toString(base); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(base); } }
From source file:gate.CorpusExporter.java
/** * Equivalent to {@link #export(Corpus,OutputStream,FeatureMap)} using a * FileOutputStream instance constructed from the File param. *///from w ww. j av a 2 s . c o m public void export(Corpus corpus, File file, FeatureMap options) throws IOException { FileOutputStream out = null; try { out = new FileOutputStream(file); export(corpus, new FileOutputStream(file), options); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:com.frostwire.android.gui.dialogs.TermsUseDialog.java
private static String readText(Context context) { InputStream in = context.getResources().openRawResource(R.raw.tos); try {//from ww w. j ava2 s. com return IOUtils.toString(in); } catch (IOException e) { throw new RuntimeException("Missing TOS resource", e); } finally { IOUtils.closeQuietly(in); } }
From source file:com.jaspersoft.android.jaspermobile.qa.ProfilesFileHolder.java
public String getJson() throws IOException { InputStream inputStream = new FileInputStream(mParcelDescriptor.getFileDescriptor()); String json = IOUtils.toString(inputStream); IOUtils.closeQuietly(inputStream); return json;/* w ww. ja v a 2s .c o m*/ }
From source file:com.googlecode.dex2jar.reader.CCZipExtractor.java
@Override public byte[] extract(byte[] data, String name) throws IOException { ZipArchiveInputStream zis = null;//from w ww .j a v a 2 s. co m try { zis = new ZipArchiveInputStream(new ByteArrayInputStream(data)); for (ZipArchiveEntry e = zis.getNextZipEntry(); e != null; e = zis.getNextZipEntry()) { e.getGeneralPurposeBit().useEncryption(false); if (e.getName().equals(name)) { data = IOUtils.toByteArray(zis); zis.close(); return data; } } } finally { IOUtils.closeQuietly(zis); } throw new IOException("can't find classes.dex in the zip"); }
From source file:hudson.maven.settings.SettingsProviderUtils.java
/** * //from w ww . j a v a 2 s . c om * @param config * @param workspace */ public static FilePath copyConfigContentToFilePath(Config config, FilePath workspace) throws IOException, InterruptedException { File tmpContentFile = null; ByteArrayInputStream bs = null; try { tmpContentFile = File.createTempFile("config", "tmp"); FilePath filePath = new FilePath(workspace, tmpContentFile.getName()); bs = new ByteArrayInputStream(config.content.getBytes()); filePath.copyFrom(bs); return filePath; } finally { FileUtils.deleteQuietly(tmpContentFile); IOUtils.closeQuietly(bs); } }
From source file:com.athena.peacock.common.core.util.SshExecUtil.java
/** * <pre>//from www. ja v a 2 s . c om * * </pre> * @param targetHost * @param commandList * @throws IOException */ public static void executeCommand(TargetHost targetHost, List<String> commandList) throws IOException { fstream = new FileWriter(output, false); out = new BufferedWriter(fstream); for (String command : commandList) { out.write("[" + targetHost.getUsername() + "@" + targetHost.getHost() + " ~]$ " + command + "\n"); out.write(executeCommand(targetHost, command)); } IOUtils.closeQuietly(out); }
From source file:be.roots.taconic.pricingguide.util.HttpUtil.java
public static byte[] readByteArray(String urlAsString, String userName, String password) { try {/*from w w w .j av a2s . c o m*/ final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password); final BufferedInputStream in = new BufferedInputStream(con.getInputStream()); final byte[] response = IOUtils.toByteArray(in); IOUtils.closeQuietly(in); return response; } catch (IOException e) { LOGGER.error(e.getLocalizedMessage(), e); } return null; }
From source file:com.adaptris.security.password.PasswordImpl.java
byte[] seed(String plainText, String charset) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {// w w w. j a v a 2 s . c om out.write(SecurityUtil.getSecureRandom().generateSeed(SEED)); out.write(plainText.getBytes(getEncodingToUse(charset))); } finally { IOUtils.closeQuietly(out); } return out.toByteArray(); }