List of usage examples for org.jfree.io IOUtils getInstance
public static IOUtils getInstance()
From source file:com.redhat.rhn.common.util.FileUtils.java
/** * Read a file off disk into a String and return it. * * Expect weird stuff if the file is not textual. * * @param path of file to read in//from w w w . ja v a 2s . c o m * @return String containing file. */ public static String readStringFromFile(String path) { log.debug("readStringFromFile: " + path); File f = new File(path); BufferedReader input; try { input = new BufferedReader(new FileReader(f)); StringWriter writer = new StringWriter(); IOUtils.getInstance().copyWriter(input, writer); String contents = writer.toString(); if (log.isDebugEnabled()) { log.debug("contents: " + contents); } return contents; } catch (FileNotFoundException e) { throw new RuntimeException("File not found: " + path); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.deegree.enterprise.servlet.ProxyServlet.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) { String url = req.getParameter("URL"); try {/*from w ww . j a va 2s. c o m*/ HttpMethod result = HttpUtils.performHttpPost(url, req.getInputStream(), 0, null, null, req.getContentType(), req.getCharacterEncoding(), null); InputStream in = result.getResponseBodyAsStream(); IOUtils.getInstance().copyStreams(in, resp.getOutputStream()); in.close(); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.pentaho.platform.plugin.action.jfreereport.outputs.AbstractGenerateContentComponent.java
@Override protected boolean executeAction() throws Throwable { MasterReport report = getReport();//from www . j a va 2 s .com if (report == null) { warn(Messages.getInstance() .getString("AbstractGenerateContentComponent.JFreeReport.ERROR_0043_NO_REPORT_FOR_ACTION")); //$NON-NLS-1$ return false; } applyThreadPriority(); final boolean privateCopy = getInputBooleanValue( AbstractJFreeReportComponent.REPORTPARAMCOMPONENT_PRIVATEREPORT_OUTPUT, false); if (privateCopy && isDefinedOutput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) { report = (MasterReport) report.clone(); } // this might be invalid in case the action is contained in a sub-directory. final String baseName = IOUtils.getInstance().stripFileExtension(getActionName()); final String path = getSolutionName() + File.separator + getSolutionPath(); final PentahoResourceBundleFactory bundleFactory = new PentahoResourceBundleFactory(path, baseName, getSession()); report.setResourceBundleFactory(bundleFactory); // set the default resourcebundle. This allows users to override the // resource-bundle in case they want to keep common strings in a common // collection. report.getReportConfiguration().setConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY, baseName); return performExport(report); }
From source file:org.pentaho.platform.web.servlet.GetContent.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding(LocaleHelper.getSystemEncoding()); PentahoSystem.systemEntryPoint();// w w w. j a v a 2 s .com try { IPentahoSession userSession = getPentahoSession(request); String id = request.getParameter("id"); //$NON-NLS-1$ if (id == null) { returnError(response, Messages.getErrorString("GetContent.ERROR_0001_ID_PARAMETER_EMPTY")); //$NON-NLS-1$ return; } IContentRepository contentRepos = PentahoSystem.get(IContentRepository.class, userSession); if (contentRepos == null) { returnError(response, Messages.getString("GetContent.ERROR_0002_CONTENT_REPOS_UNAVAILABLE")); //$NON-NLS-1$ return; } try { IContentItem contentItem = contentRepos.getContentItemById(id); if (contentItem == null) { returnError(response, Messages.getString("GetContent.ERROR_0005_CONTENT_NOT_FOUND", id)); //$NON-NLS-1$ return; } String mimetype = contentItem.getMimeType(); if ((mimetype == null) || (mimetype.length() < 1)) { mimetype = request.getParameter("mimetype"); //$NON-NLS-1$ } // Set it if we know what it is if ((mimetype != null) && (mimetype.length() > 0)) { response.setContentType(mimetype); } if (!(mimetype.equalsIgnoreCase("text/html"))) { //$NON-NLS-1$ response.setHeader("Content-Disposition", //$NON-NLS-1$ "inline; filename=\"" + contentItem.getTitle() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } // Send it back InputStream inStr = contentItem.getInputStream(); ServletOutputStream outStr = response.getOutputStream(); try { IOUtils.getInstance().copyStreams(inStr, outStr); } finally { inStr.close(); // You are not allowed to close this output stream // outStr.close(); } } catch (Exception ex) { error(Messages.getErrorString("GetContent.ERROR_0003_CONTENT_READ_ERROR"), ex); //$NON-NLS-1$ } } finally { PentahoSystem.systemExitPoint(); } }