List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.discursive.jccook.net.POPExample.java
public void start() throws SocketException, IOException { POP3Client client = new POP3Client(); client.connect("www.discursive.com"); client.login("tobrien@discursive.com", "******"); POP3MessageInfo[] messages = client.listMessages(); for (int i = 0; i < 5; i++) { int messageNum = messages[i].number; System.out.println("Message number: " + messageNum); Reader reader = client.retrieveMessageTop(messageNum, 10); System.out.println("Message:\n" + IOUtils.toString(reader)); IOUtils.closeQuietly(reader); }/*from w w w.j av a2 s . c o m*/ client.logout(); client.disconnect(); }
From source file:android.databinding.tool.writer.AnnotationJavaFileWriter.java
@Override public void writeToFile(String canonicalName, String contents) { Writer writer = null;// w w w.j a va 2s . com try { L.d("writing file %s", canonicalName); JavaFileObject javaFileObject = mProcessingEnvironment.getFiler().createSourceFile(canonicalName); writer = javaFileObject.openWriter(); writer.write(contents); } catch (IOException e) { L.e(e, "Could not write to %s", canonicalName); } finally { if (writer != null) { IOUtils.closeQuietly(writer); } } }
From source file:net.ion.radon.cload.stores.FileResourceStore.java
public byte[] read(final String pResourceName) { InputStream is = null;//from w ww .ja va2s .com try { is = new FileInputStream(getFile(pResourceName)); final byte[] data = IOUtils.toByteArray(is); return data; } catch (Exception e) { return null; } finally { IOUtils.closeQuietly(is); } }
From source file:io.apiman.servers.gateway_es.Starter.java
/** * Loads properties from a file and puts them into system properties. *///from ww w. j a va 2 s . co m @SuppressWarnings({ "nls", "unchecked" }) protected static void loadProperties() { URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties"); if (configUrl == null) { throw new RuntimeException( "Failed to find properties file (see README.md): gateway_es-apiman.properties"); } InputStream is = null; try { is = configUrl.openStream(); Properties props = new Properties(); props.load(is); Enumeration<String> names = (Enumeration<String>) props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = props.getProperty(name); System.setProperty(name, value); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:net.firejack.platform.web.security.x509.KeyUtils.java
public static KeyPair generate(File keystore) { if (keystore == null) { throw new IllegalArgumentException("Key Store file should not be null."); }/*w w w . java 2 s . co m*/ try { KeyStore ks = KeyStore.getInstance("JKS", "SUN"); if (keystore.exists()) { FileInputStream stream = new FileInputStream(keystore); ks.load(stream, SECRET); IOUtils.closeQuietly(stream); } else { ks.load(null, SECRET); } if (ks.containsAlias(ALIAS)) { PrivateKey privateKey = (PrivateKey) ks.getKey(ALIAS, SECRET); PublicKey publicKey = ks.getCertificate(ALIAS).getPublicKey(); return new KeyPair(publicKey, privateKey); } else { KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(KEYSIZE, new SecureRandom()); return generator.generateKeyPair(); } } catch (Throwable th) { logger.error("Failed to initialize key store"); throw new OpenFlameRuntimeException(th.getMessage(), th); } }
From source file:net.orpiske.ssps.common.digest.Sha1Digest.java
public String calculate(final File file) throws IOException { InputStream fileInputStream = null; try {/*from w w w . ja v a 2 s .co m*/ fileInputStream = new FileInputStream(file); return calculate(fileInputStream); } finally { IOUtils.closeQuietly(fileInputStream); } }
From source file:com.tc.license.TCLicenseDetails.java
/** * Construct a TC license details. License file will be verified. LicenseException will be thrown if license check * fails//from w w w .java 2 s . com */ public TCLicenseDetails(File licenseFile) { InputStream input = null; try { input = new FileInputStream(licenseFile); license = AbstractLicenseResolverFactory.getFactory().resolveLicense(input); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(input); } }
From source file:com.lithium.flow.util.HashEncoder.java
@Nonnull public String process(@Nonnull InputStream in) throws IOException { checkNotNull(in);/*from w w w. j a v a2 s . co m*/ try { HashingInputStream hashIn = new HashingInputStream(function, in); IOUtils.copy(hashIn, ByteStreams.nullOutputStream()); return encoding.encode(hashIn.hash().asBytes()); } finally { IOUtils.closeQuietly(in); } }
From source file:jp.igapyon.diary.v3.util.IgapyonV3Util.java
/** * Read string from text file./*from w w w. j a v a 2 s . c om*/ * * @param file * @return * @throws IOException */ public static String readTextFile(final File file) throws IOException { final FileInputStream inStream = new FileInputStream(file); try { return IOUtils.toString(inStream, "UTF-8"); } finally { IOUtils.closeQuietly(inStream); } }
From source file:com.lmco.ddf.webconsole.branding.DDFBrandingPlugin.java
public void init() { Properties props;/*from w ww. ja va 2s . c om*/ props = new Properties(); java.io.InputStream ins = getClass().getResourceAsStream(BRANDING_PROPERTIES); if (ins != null) { try { props.load(ins); } catch (IOException ignore) { IOUtils.closeQuietly(ins); } finally { IOUtils.closeQuietly(ins); } } IOUtils.closeQuietly(ins); brandName = props.getProperty("webconsole.brand.name", "DDF Web Console"); productName = props.getProperty("webconsole.product.name", "DDF"); productURL = props.getProperty("webconsole.product.url", "http://felix.apache.org"); productImage = props.getProperty("webconsole.product.image", "/res/ddf/ddf.jpg"); vendorName = props.getProperty("webconsole.vendor.name", "Lockheed Martin"); vendorURL = props.getProperty("webconsole.vendor.url", "http://www.lockheedmartin.com"); vendorImage = props.getProperty("webconsole.vendor.image", "/res/ddf/logo.png"); favIcon = props.getProperty("webconsole.favicon", "/res/ddf/favicon.ico"); mainStyleSheet = props.getProperty("webconsole.stylesheet", "/res/ddf/webconsole.css"); }