List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:gaffer.data.elementdefinition.ElementDefinitions.java
public static <T extends ElementDefinitions> T fromJson(final Class<T> clazz, final InputStream... inputStreams) throws SchemaException { try {//from www .jav a2 s . com return fromJson(clazz, (Object[]) inputStreams); } finally { if (null != inputStreams) { for (final InputStream inputStream : inputStreams) { IOUtils.closeQuietly(inputStream); } } } }
From source file:blackboard.sonar.plugins.css.rules.BlackboardCssProfile.java
@Override public RulesProfile createProfile(ValidationMessages validation) { Reader reader = new InputStreamReader( BlackboardCssProfile.class.getClassLoader().getResourceAsStream(ALL_RULES), Charset.forName(CharEncoding.UTF_8)); try {/*from w w w . j a v a2 s.c o m*/ RulesProfile profile = profileParser.parse(reader, validation); profile.setDefaultProfile(true); return profile; } finally { IOUtils.closeQuietly(reader); } }
From source file:com.mtt.myapp.common.util.FileDownloadUtil.java
/** * Provide file download from the given file path. * @param response {@link javax.servlet.http.HttpServletResponse} * @param desFile file path//from w ww . j a v a2 s . c o m * @return true if succeeded */ public static boolean downloadFile(HttpServletResponse response, File desFile) { if (desFile == null || !desFile.exists()) { return false; } boolean result = true; response.reset(); response.addHeader("Content-Disposition", "attachment;filename=" + desFile.getName()); response.setContentType("application/octet-stream"); response.addHeader("Content-Length", "" + desFile.length()); InputStream fis = null; byte[] buffer = new byte[FILE_DOWNLOAD_BUFFER_SIZE]; OutputStream toClient = null; try { fis = new BufferedInputStream(new FileInputStream(desFile)); toClient = new BufferedOutputStream(response.getOutputStream()); int readLength; while (((readLength = fis.read(buffer)) != -1)) { toClient.write(buffer, 0, readLength); } toClient.flush(); } catch (FileNotFoundException e) { LOGGER.error("file not found:" + desFile.getAbsolutePath(), e); result = false; } catch (IOException e) { LOGGER.error("read file error:" + desFile.getAbsolutePath(), e); result = false; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(toClient); } return result; }
From source file:com.limegroup.gnutella.gui.init.IntentWindow.java
private boolean isCurrentVersionChecked() { if (properties == null) { properties = new Properties(); FileInputStream fis = null; try {//from w w w .j a va 2 s . c o m fis = new FileInputStream(getPropertiesFile()); properties.load(fis); } catch (IOException iox) { System.out.println("Could not load properties from property file."); return false; } finally { IOUtils.closeQuietly(fis); } } String exists = properties.getProperty("willnot"); return exists != null && exists.equals("true"); }
From source file:com.abstratt.graphviz.GraphViz.java
public static void generate(final InputStream input, String format, int dimensionX, int dimensionY, IPath outputLocation) throws CoreException { MultiStatus status = new MultiStatus(GraphVizActivator.ID, 0, "Errors occurred while running Graphviz", null);/*from ww w . ja v a 2 s.co m*/ File dotInput = null, dotOutput = outputLocation.toFile(); // we keep the input in memory so we can include it in error messages ByteArrayOutputStream dotContents = new ByteArrayOutputStream(); try { // determine the temp input location dotInput = File.createTempFile(TMP_FILE_PREFIX, DOT_EXTENSION); // dump the contents from the input stream into the temporary file // to be submitted to dot FileOutputStream tmpDotOutputStream = null; try { IOUtils.copy(input, dotContents); tmpDotOutputStream = new FileOutputStream(dotInput); IOUtils.copy(new ByteArrayInputStream(dotContents.toByteArray()), tmpDotOutputStream); } finally { IOUtils.closeQuietly(tmpDotOutputStream); } IStatus result = runDot(format, dimensionX, dimensionY, dotInput, dotOutput); if (dotOutput.isFile() && dotOutput.length() > 0) { if (!result.isOK() && Platform.inDebugMode()) LogUtils.log(status); // success! return; } } catch (IOException e) { status.add(new Status(IStatus.ERROR, GraphVizActivator.ID, "", e)); } finally { dotInput.delete(); IOUtils.closeQuietly(input); } throw new CoreException(status); }
From source file:com.hp.application.automation.tools.octane.tests.TestCustomJUnitArchiver.java
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.addAction(new TestResultAction()); InputStream is = build.getWorkspace().child(resultFile).read(); String junitResults = IOUtils.toString(is, "UTF-8"); junitResults = junitResults.replaceAll("%%%WORKSPACE%%%", build.getWorkspace().getRemote()) .replaceAll("%%%SEPARATOR%%%", File.separator.equals("\\") ? "\\\\" : File.separator); IOUtils.closeQuietly(is); new FilePath(build.getRootDir()).child("junitResult.xml").write(junitResults, "UTF-8"); return true;/*from w w w. java2s .c o m*/ }
From source file:cz.cas.lib.proarc.authentication.utils.AuthUtils.java
/** * Writes the authentication OK status to the HTTP response. * @param response response//from ww w . ja v a2s. com * @throws IOException failure * @see <a href='http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Relogin.html'>SmartGWT Relogin</a> */ public static void setLoginSuccesResponse(HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType(MediaType.TEXT_HTML); InputStream res = ProarcAuthFilter.class.getResourceAsStream("loginSuccessMarker.html"); try { IOUtils.copy(res, response.getOutputStream()); res.close(); } finally { IOUtils.closeQuietly(res); } }
From source file:com.brianjmelton.apcs.api.BasicCookieStoreSerializer.java
@Override public void persist(Map<URI, List<SerializableCookie>> cookies) throws PersistenceException { try {/*from w w w .j a v a 2s. c o m*/ OutputStream fout = new FileOutputStream(cookieFile); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(cookies); IOUtils.closeQuietly(oos); } catch (Throwable t) { throw new PersistenceException(t); } }
From source file:com.opengamma.web.server.push.rest.ReportMessageBodyWriter.java
/** * Writes from {@link Report#getInputStream()} to {@code entityStream}. *//*from w ww . j av a2 s . c o m*/ @Override public void writeTo(Report report, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { InputStream inputStream = null; try { inputStream = report.getInputStream(); IOUtils.copy(inputStream, entityStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:gov.nih.nci.cabig.caaers.web.rule.ContextListener.java
private RuleUi load(String fileName) { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); try {//w w w. j ava 2 s .c o m Unmarshaller unmarshaller = JAXBContext.newInstance("com.semanticbits.rules.ui").createUnmarshaller(); RuleUi ruleUi = (RuleUi) unmarshaller.unmarshal(inputStream); return ruleUi; } catch (JAXBException e) { throw new CaaersSystemException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } }