List of usage examples for org.apache.commons.io FileUtils openInputStream
public static FileInputStream openInputStream(File file) throws IOException
new FileInputStream(file)
. From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterChannelIntegrationTest.java
/** * This test calls out acceptSource(..) operation on SematicAdapter WS. * and expects the service to return an Exception * * @throws Exception exception/*from w w w. j a v a2 s .com*/ */ //ToDo Remove ignore after CDO-1257 @Ignore @Test(expected = AcceptSourceFault.class) public void failure() throws Exception { //NOPMD final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(AcceptSourcePortType.class); factory.setAddress(ADDRESS); final AcceptSourcePortType client = (AcceptSourcePortType) factory.create(); final InputStream sampleMessageIS = FileUtils .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI())); final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final CaCISRequest request = (CaCISRequest) jc.createUnmarshaller().unmarshal(sampleMessageIS); client.acceptSource(request); }
From source file:com.haulmont.cuba.core.controllers.FileDownloadController.java
@RequestMapping(value = "/download", method = RequestMethod.GET) public void download(HttpServletRequest request, HttpServletResponse response) throws IOException { UserSession userSession = getSession(request, response); if (userSession == null) return;/*from ww w . jav a2 s . c o m*/ AppContext.setSecurityContext(new SecurityContext(userSession)); try { File file = null; FileDescriptor fd = null; if (request.getParameter("p") != null) file = getFile(request, response); else fd = getFileDescriptor(request, response); if (fd == null && file == null) return; response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setIntHeader("Expires", -1); response.setHeader("Content-Type", FileTypesHelper.DEFAULT_MIME_TYPE); InputStream is = null; ServletOutputStream os = null; try { is = fd != null ? fileStorage.openStream(fd) : FileUtils.openInputStream(file); os = response.getOutputStream(); IOUtils.copy(is, os); os.flush(); } catch (FileStorageException e) { log.error("Unable to download file", e); response.sendError(e.getType().getHttpStatus()); } catch (Exception ex) { log.error("Unable to download file", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } } finally { AppContext.setSecurityContext(null); } }
From source file:com.cognifide.qa.bb.junit5.allure.ScreenshotExtension.java
private void takeScreenshot(WebDriver webDriver) throws IOException { File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); Allure.addAttachment("Screenshot", FileUtils.openInputStream(screenshotAs)); }
From source file:eu.apenet.dpt.standalone.gui.eag2012.Eag2012Frame.java
public void createFrame(File eagFile, boolean isNew) { try {//w ww . ja va 2s .c o m createFrame(FileUtils.openInputStream(eagFile), isNew); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.silverpeas.gallery.ImageHelper.java
/** * Open an output stream of an image according to given details of a photo. * * @param photo//from w w w. j a v a 2s . c om * @param isOriginalRequired * @return * @throws IOException */ public static InputStream openInputStream(final PhotoDetail photo, final boolean isOriginalRequired) { final String photoId = photo.getPhotoPK().getId(); final String instanceId = photo.getPhotoPK().getInstanceId(); if (StringUtil.isDefined(photoId) && StringUtil.isDefined(instanceId)) { final String subDirectory = gallerySettings.getString("imagesSubDirectory"); String fileName = photoId + previewSuffix; if (isOriginalRequired) { fileName = photo.getImageName(); } try { return FileUtils.openInputStream(FileUtils.getFile(new File(BASE_PATH.getPath()), instanceId, subDirectory + photoId, fileName)); } catch (IOException e) { SilverTrace.error("gallery", "ImageHelper.getBytes", "gallery.ERR_CANT_GET_IMAGE_BYTES", "image = " + photo.getTitle() + " (#" + photo.getId() + ")"); return null; } } return null; }
From source file:com.thoughtworks.go.plugin.infra.FelixGoPluginOSGiFrameworkIntegrationTest.java
@Before public void setUp() throws Exception { registry = new DefaultPluginRegistry(); systemEnvironment = new SystemEnvironment(); pluginOSGiFramework = new FelixGoPluginOSGiFramework(registry, systemEnvironment) { @Override/*from w w w. ja v a 2s . c o m*/ protected HashMap<String, String> generateOSGiFrameworkConfig() { HashMap<String, String> config = super.generateOSGiFrameworkConfig(); config.put(FelixConstants.RESOLVER_PARALLELISM, "1"); return config; } }; pluginOSGiFramework.start(); try (ZipInputStream zippedOSGiBundleFile = new ZipInputStream( FileUtils.openInputStream(pathOfFileInDefaultFiles("descriptor-aware-test-plugin.osgi.jar")))) { descriptorBundleDir = explodeBundleIntoDirectory(zippedOSGiBundleFile, "descriptor-plugin-bundle-dir"); } try (ZipInputStream zippedOSGiBundleFile = new ZipInputStream(FileUtils.openInputStream( pathOfFileInDefaultFiles("error-generating-descriptor-aware-test-plugin.osgi.jar")))) { errorGeneratingDescriptorBundleDir = explodeBundleIntoDirectory(zippedOSGiBundleFile, "error-generating-descriptor-plugin-bundle-dir"); } try (ZipInputStream zippedOSGiBundleFile = new ZipInputStream(FileUtils .openInputStream(pathOfFileInDefaultFiles("exception-throwing-at-load-plugin.osgi.jar")))) { exceptionThrowingAtLoadDescriptorBundleDir = explodeBundleIntoDirectory(zippedOSGiBundleFile, "exception-throwing-at-load-plugin-bundle-dir"); } try (ZipInputStream zippedOSGiBundleFile = new ZipInputStream(FileUtils .openInputStream(pathOfFileInDefaultFiles("valid-plugin-with-multiple-extensions.osgi.jar")))) { validMultipleExtensionPluginBundleDir = explodeBundleIntoDirectory(zippedOSGiBundleFile, "valid-plugin-with-multiple-extensions"); } try (ZipInputStream zippedOSGiBundleFile = new ZipInputStream(FileUtils.openInputStream( pathOfFileInDefaultFiles("dumb.plugin.that.responds.with.classloader.name.osgi.jar")))) { pluginToTestClassloadPluginBundleDir = explodeBundleIntoDirectory(zippedOSGiBundleFile, "plugin-to-test-classloader"); } }
From source file:cat.calidos.morfeu.utils.injection.DataFetcherModule.java
@Produces @Named("fileData") public InputStream fetchFileData(URI uri) throws FetchingException { try {//from ww w. ja v a 2 s . c om log.trace("Fetching local data from {}", uri); return FileUtils.openInputStream(FileUtils.toFile(uri.toURL())); } catch (Exception e) { throw new FetchingException("Problem fetching local data at '" + uri + "'", e); } }
From source file:com.aurel.track.util.LogoAction.java
/** * Write the image in the format given to the output stream *///from w ww . j a v a2s . com @Override public String execute() { String logo = null; HttpServletResponse response = ServletActionContext.getResponse(); if ("m".equals(logoType)) { response.setContentType("image/gif"); logo = "tracklogo.gif"; } else if ("r".equals(logoType)) { response.setContentType("image/png"); logo = "logo-254x105.png"; } else { response.setContentType("image/png"); logo = "trackLogo.png"; logoType = "x"; } OutputStream oStream = null; try { oStream = response.getOutputStream(); } catch (IOException e) { return null; } LogoBuffer lb = logoMap.get(logoType); if (lb != null) { ; try { oStream.write(lb.getImage(), 0, lb.getSize()); } catch (Exception e) { LOGGER.error("Problem with logos: " + e.getMessage()); } return null; } String logoDir = HandleHome.getTrackplus_Home() + "/logos"; InputStream in = null; BufferedInputStream instream = null; final int BUFFERSIZE = 256 * 1024; byte[] buffer = new byte[BUFFERSIZE]; try { in = FileUtils.openInputStream(new File(logoDir + "/" + logo)); instream = new BufferedInputStream(in); int size = -1; int isize = size; while (-1 != (size = instream.read(buffer, 0, BUFFERSIZE))) { oStream.write(buffer, 0, size); if (size > 256 * BUFFERSIZE) { LOGGER.error("Logos should not be larger than " + BUFFERSIZE / 1024 + " kByte!"); break; } isize = size; } byte[] tbuffer = new byte[isize]; for (int i = 0; i < size; ++i) { tbuffer[i] = buffer[i]; } lb = new LogoBuffer(); lb.setImage(tbuffer); lb.setSize(size); logoMap.put(logoType, lb); instream.close(); in.close(); } catch (Exception e) { LOGGER.error("Problem with logos: " + e.getMessage()); } return null; }
From source file:gov.nih.nci.caarray.application.fileaccess.FileAccessServiceBean.java
/** * {@inheritDoc}// w w w . j a v a 2 s. c om */ public CaArrayFile add(File file, String filename, CaArrayFile parent) { LogUtil.logSubsystemEntry(LOG, file, filename, parent); try { final InputStream is = FileUtils.openInputStream(file); final CaArrayFile caArrayFile = add(is, filename, parent); IOUtils.closeQuietly(is); return caArrayFile; } catch (final IOException e) { LogUtil.logSubsystemExit(LOG); throw new FileAccessException("File " + filename + " couldn't be read", e); } }
From source file:com.xpn.xwiki.web.TempResourceAction.java
/** * {@inheritDoc}//from www . j a v a2s. c om */ public String render(XWikiContext context) throws XWikiException { XWikiRequest request = context.getRequest(); XWikiResponse response = context.getResponse(); String uri = request.getRequestURI(); // Locate the temporary file. File tempFile = getTemporaryFile(uri, context); if (null == tempFile) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, "Invalid temporary resource URL"); } // Write temporary file into response. response.setDateHeader("Last-Modified", tempFile.lastModified()); String contentType = MimeTypes.OCTET_STREAM; try { contentType = tika.detect(tempFile); } catch (IOException ex) { LOGGER.warn(String.format("Unable to determine mime type for temporary resource [%s]", tempFile.getAbsolutePath()), ex); } response.setContentType(contentType); try { response.setContentLength((int) tempFile.length()); IOUtils.copy(FileUtils.openInputStream(tempFile), response.getOutputStream()); } catch (IOException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION, "Exception while sending response", e); } return null; }