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:dynamicrefactoring.domain.xml.reader.JDOMXMLRefactoringReaderImp.java
/** * Devuelve la definicin de la refactorizacin. * //from w w w .j a v a 2s.com * @return la definicin de la refactorizacin. */ @Override public DynamicRefactoringDefinition getDynamicRefactoringDefinition(File file) { try { return readFile(FileUtils.openInputStream(file)); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceTest.java
@Test public void testUnpackFiles() throws Exception { // testing unpacking of a file already in the project // add a file final Project project = this.daoFactoryStub.getSearchDao().retrieve(Project.class, 123L); final CaArrayFile file = this.projectManagementService.addFile(project, MageTabDataFiles.SPECIFICATION_ZIP); this.fileAccessServiceStub.setDeletableStatus(file, true); assertEquals(MageTabDataFiles.SPECIFICATION_ZIP.getName(), file.getName()); assertEquals(1, project.getFiles().size()); assertNotNull(project.getFiles().iterator().next().getProject()); assertContains(project.getFiles(), MageTabDataFiles.SPECIFICATION_ZIP.getName()); // unpack zip file final CaArrayFile myFile = project.getFiles().first(); final DataStorageFacade dataStorageFacade = mock(DataStorageFacade.class); when(dataStorageFacade.openInputStream(myFile.getDataHandle(), false)) .thenReturn(FileUtils.openInputStream(MageTabDataFiles.SPECIFICATION_ZIP)); final FileUploadUtils fileUploadUtils = new FileUploadUtils(dataStorageFacade); // now do the unpack final List<CaArrayFile> cFileList = new ArrayList<CaArrayFile>(); cFileList.add(myFile);/*from w w w .j a v a 2 s. c om*/ final FileProcessingResult result = fileUploadUtils.unpackFiles(project, cFileList); // the unpack should have added 10 files and removed the zip archive assertEquals(16, result.getCount()); assertEquals(1, this.fileAccessServiceStub.getRemovedFileCount()); assertEquals(16, project.getFiles().size()); assertNotNull(project.getFiles().iterator().next().getProject()); assertNotContains(project.getFiles(), "specification.zip"); assertContains(project.getFiles(), MageTabDataFiles.SPECIFICATION_EXAMPLE_IDF.getName()); }
From source file:com.glaf.core.security.RSAUtils.java
private static KeyPair readKeyPair() { InputStream in = null;//from ww w.j a v a 2s . com ObjectInputStream ois = null; try { SysKeyService sysKeyService = ContextFactory.getBean("sysKeyService"); SysKey sysKey = sysKeyService.getSysKey("RSAKey"); if (sysKey != null && sysKey.getData() != null) { in = new ByteArrayInputStream(sysKey.getData()); ois = new ObjectInputStream(in); oneKeyPair = (KeyPair) ois.readObject(); return oneKeyPair; } } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(ois); IOUtils.closeQuietly(in); } try { in = FileUtils.openInputStream(rsaPairFile); ois = new ObjectInputStream(in); oneKeyPair = (KeyPair) ois.readObject(); return oneKeyPair; } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(ois); IOUtils.closeQuietly(in); } return null; }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java
protected void initializeXmlDigesterLoader() { if (PluginConfigurationServiceDefault.logger.isDebugEnabled()) PluginConfigurationServiceDefault.logger.debug("Initializing the XML digester."); Schema schema;/*w ww .j a v a 2s .c om*/ FileInputStream stream = null; try { stream = FileUtils.openInputStream(this.xsdFile); schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource(stream)); } catch (SAXException e) { throw new FatalBeanException("Could not parse plugin configuration XSD", e); } catch (IOException e) { throw new FatalBeanException("Could not parse plugin configuration XSD", e); } finally { try { if (stream != null) stream.close(); } catch (IOException e) { PluginConfigurationServiceDefault.logger.warn("Failed to close XSD file stream.", e); } } this.digesterLoader.setNamespaceAware(true); this.digesterLoader.setSchema(schema); this.digesterLoader.setErrorHandler(new ConfigurationErrorHandler()); this.digesterLoader.setUseContextClassLoader(false); this.digesterLoader.setClassLoader(Digester.class.getClassLoader()); ConvertUtils.register(new JodaXML8601DateTimeConverter(), DateTime.class); }
From source file:architecture.ee.web.attachment.DefaultImageManager.java
public InputStream getImageInputStream(Image image) { try {//www. j a v a 2 s . c om File file = getImageFromCacheIfExist(image); return FileUtils.openInputStream(file); } catch (IOException e) { throw new SystemException(e); } }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that setting a read length trim value will write the trimmed reads to * the output properly./*ww w . ja v a2s. co m*/ * * @throws IOException if there is a problem reading or writing to the files */ public void trimReadLengthsAt23() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads"; reformat.setInputFilenames(inputFilename); final String outputFilename = "test-results/reformat-test-start.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); reformat.setTrimReadLength(23); final File inputFile = new File(inputFilename); final File outputFile = new File(outputFilename); assertFalse("The reformatted file should not be the same as the original", FileUtils.contentEquals(inputFile, outputFile)); final ReadsReader reader = new ReadsReader(FileUtils.openInputStream(outputFile)); assertTrue("There should be reads in this file", reader.hasNext()); int readCount = 0; for (final Reads.ReadEntry entry : reader) { if (readCount == 0) { assertEquals("Reader returned the wrong sequence string", "CTCATGTTCATACACCTNTCCCCCATTCTCCTCCT".subSequence(0, 22), entry.getSequence().toString(Charset.defaultCharset().name())); } readCount++; assertEquals("Entry ", readCount + " was not trimmed", entry.getReadLength()); } assertEquals("There should have been 73 entries in the reformatted file", 73, readCount); }
From source file:architecture.ee.web.attachment.DefaultImageManager.java
public InputStream getImageThumbnailInputStream(Image image, int width, int height) { try {//from w w w . j a v a2 s . c o m File file = getThumbnailFromCacheIfExist(image, width, height); return FileUtils.openInputStream(file); } catch (IOException e) { throw new SystemException(e); } finally { } }
From source file:net.sf.jsignpdf.utils.KeyStoreUtils.java
/** * Loads a {@link X509Certificate} from the given path. Returns null if the * certificate can't be loaded.//www .j a va 2 s . co m * * @param filePath * @return */ public static X509Certificate loadCertificate(final String filePath) { if (StringUtils.isEmpty(filePath)) { LOGGER.debug("Empty file path"); return null; } FileInputStream inStream = null; X509Certificate cert = null; try { final CertificateFactory certFac = CertificateFactory.getInstance(Constants.CERT_TYPE_X509); // X.509 inStream = FileUtils.openInputStream(new File(filePath)); cert = (X509Certificate) certFac.generateCertificate(inStream); } catch (Exception e) { LOGGER.debug("Unable to load certificate", e); } finally { IOUtils.closeQuietly(inStream); } return cert; }
From source file:com.edgenius.core.repository.SimpleRepositoryServiceImpl.java
public List<FileNode> getAllIdentifierNodes(ITicket ticket, String type, String identifierUuid, boolean withResource) throws RepositoryException { if (!ticket.isAllowRead()) { String error = "Workspace has not read permission " + ticket.getSpacename(); log.warn(error);/*ww w. j av a 2 s . com*/ throw new RepositoryException("Permission denied: " + error); } CrWorkspace crW = getCrWorkspace(ticket); List<CrFileNode> nodes = crFileNodeDAO.getIdentifierNodes(type, identifierUuid); List<FileNode> list = new ArrayList<FileNode>(); //retrieve all geniuswiki:file nodes under this identifier for (Iterator<CrFileNode> iter = nodes.iterator(); iter.hasNext();) { CrFileNode fileNode = iter.next(); //copy geniuswiki:file history as well FileNode my = FileNode.copyPersistToNode(fileNode); //copy geniuswiki:filenode->nt:resource node as well if (withResource) { File file = new File(FileUtil.getFullPath(homeDir, crW.getSpaceUuid(), fileNode.getNodeType(), fileNode.getIdentifierUuid(), fileNode.getNodeUuid(), Integer.valueOf(fileNode.getVersion()).toString(), SimpleRepositoryServiceImpl.DEFAULT_FILE_NAME)); try { my.setFile(FileUtils.openInputStream(file)); } catch (IOException e) { log.warn("Failed get node " + file.getAbsolutePath() + " with error " + e); } } list.add(my); } return list; }
From source file:com.glaf.core.security.RSAUtils.java
/** * RSA??//w w w. j a v a2 s. c o m * * @param keyPair * ?? */ private static void saveKeyPair(KeyPair keyPair) { FileOutputStream fos = null; ObjectOutputStream oos = null; try { fos = FileUtils.openOutputStream(rsaPairFile); oos = new ObjectOutputStream(fos); oos.writeObject(keyPair); } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(oos); IOUtils.closeQuietly(fos); } FileInputStream fin = null; try { fin = FileUtils.openInputStream(rsaPairFile); SysKey sysKey = new SysKey(); sysKey.setId("RSAKey"); sysKey.setCreateBy("system"); sysKey.setName("RSAKey"); sysKey.setType("RSA"); sysKey.setTitle("RSA?"); sysKey.setPath(rsaPairFile.getName()); sysKey.setData(IOUtils.toByteArray(fin)); SysKeyService sysKeyService = ContextFactory.getBean("sysKeyService"); sysKeyService.save(sysKey); } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(fin); } }