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:net.sf.logsaw.core.internal.logresource.simple.SimpleLogResource.java
@Override public void synchronize(ILogEntryCollector collector, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(collector, "collector"); //$NON-NLS-1$ Assert.isTrue(isConfigured(), "must be configured before synchronize"); //$NON-NLS-1$ if (monitor == null) { monitor = new NullProgressMonitor(); }/*from w w w . j a va 2 s . co m*/ monitor.beginTask(NLS.bind(Messages.SimpleLogResource_synchronizeTask_name, getName()), getUnitsOfWork()); // Units of work will return atleast 1 InputStream input = null; try { // The ProgressingInputStream will take care of updating the monitor input = new ProgressingInputStream(FileUtils.openInputStream(logFile), monitor); getDialect().parse(this, input, collector); monitor.worked(1); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, NLS.bind(Messages.SimpleLogResource_error_fileNotFound, logFile.getPath()))); } finally { // Better safe than sorry IOUtils.closeQuietly(input); monitor.done(); } }
From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java
public void addLogoImage(LogoImage logoImage, File file) { try {// w w w. ja va 2s . c o m if (logoImage.getImageSize() == 0) logoImage.setImageSize((int) FileUtils.sizeOf(file)); addLogoImage(logoImage, file != null ? FileUtils.openInputStream(file) : null); } catch (IOException e) { } }
From source file:it.cnr.ilc.ilcioutils.IlcIOUtils.java
/** * read the content from file/*from ww w .ja v a 2 s. co m*/ * @param filepath a path where the file to read the content from is * @return the content of the file * @throws IOException */ public static String readFileContent(String filepath) throws IOException { String message = ""; File initialFile; InputStream targetStream = null; String theString = ""; try { initialFile = new File(filepath); targetStream = FileUtils.openInputStream(initialFile); theString = IOUtils.toString(targetStream, "UTF-8"); } catch (IOException e) { message = "IOaaException in reading the stream for " + filepath + " " + e.getMessage(); Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message); //System.exit(-1); } finally { if (targetStream != null) { try { targetStream.close(); } catch (IOException e) { message = "IOException in closing the stream for " + filepath + " " + e.getMessage(); Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message); //System.exit(-1); } } } //System.err.println(theString); return theString; }
From source file:com.splunk.shuttl.server.mbeans.ShuttlArchiverMBeanArchiverRootURITest.java
private void runHdfsTestCase(File hdfsPropertiesFile) throws IOException { String host = "thehost"; String port = "9876"; String archiverRootURI = createHdfsArchiverRootUri(host, port); createArchiverMbeanWithArchiverRootURI(archiverRootURI); assertEquals("hdfs", archiverMBean.getBackendName()); assertEquals("/archiver_root", archiverMBean.getArchivePath()); Properties hdfsProperties = new Properties(); hdfsProperties.load(FileUtils.openInputStream(hdfsPropertiesFile)); assertEquals(host, hdfsProperties.getProperty("hadoop.host")); assertEquals(port, hdfsProperties.getProperty("hadoop.port")); }
From source file:net.malisis.ddb.BlockPack.java
/** * Gets an inputStream from this {@link BlockPack} for the <i>path</i>. * * @param path/*from w w w. ja va 2 s . c o m*/ * @return * @throws IOException */ public InputStream getInputStream(String path) throws IOException { if (type == Type.FOLDER) { File file = new File(getDirectory() + path); if (!file.isFile()) return null; return FileUtils.openInputStream(file); } else if (type == Type.ZIP && zipFile != null) { ZipEntry entry = zipFile.getEntry(path); if (entry == null) return null; return zipFile.getInputStream(entry); } throw new IOException("Undetermined pack type : " + type); }
From source file:com.textocat.textokit.morph.opencorpora.resource.CachedDictionaryDeserializer.java
public GetDictionaryResult getDictionary(File file) throws Exception { URL url = file.toURI().toURL(); InputStream fileIS = FileUtils.openInputStream(file); return getDictionary(url, fileIS); }
From source file:com.tibco.businessworks6.sonar.plugin.source.XmlSource.java
/** * Create an {@link InputStream} based on the {@link XmlFile} file if defined * or based on the source code {@link String} * // w ww .j a v a2 s. c o m * @return created {@link InputStream} */ public InputStream createInputStream() { if (xmlFile.getIOFile() != null) { try { return FileUtils.openInputStream(xmlFile.getIOFile()); } catch (IOException e) { throw new SonarException(e); } } else { return new ByteArrayInputStream(code.getBytes()); } }
From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java
@Test public void testRemoveSeaCloudsApplicationData() throws Exception { Yaml yamlParser = new Yaml(); URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH); Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile()))); int oldSize = dataStore.listSeaCloudsApplicationData().size(); SeaCloudsApplicationData seaCloudsApplicationData = new SeaCloudsApplicationData(toscaDamMap); dataStore.addSeaCloudsApplicationData(seaCloudsApplicationData); SeaCloudsApplicationData seaCloudsApplicationDataById = dataStore .removeSeaCloudsApplicationDataById(seaCloudsApplicationData.getSeaCloudsApplicationId()); assertEquals(seaCloudsApplicationData, seaCloudsApplicationDataById); int newSize = dataStore.listSeaCloudsApplicationData().size(); assertEquals(oldSize, newSize);/*from w w w . ja v a 2 s.c o m*/ }
From source file:com.seleniumtests.core.config.ConfigReader.java
/** * read configuration from default config file (env.ini or config.ini) * read any other provided configuration files (through loadIni parameter) * @return//from w w w.j a v a2 s . c om */ public Map<String, TestVariable> readConfig() { Map<String, TestVariable> variables = new HashMap<>(); try (InputStream iniFileStream = FileUtils.openInputStream(getConfigFile());) { variables.putAll(readConfig(iniFileStream, testEnv)); } catch (NullPointerException e) { logger.warn( "config file is null, check config path has been set using 'SeleniumTestsContextManager.generateApplicationPath()'"); return variables; } catch (IOException e1) { logger.warn("no valid config.ini file for this application"); return variables; } // read additional files if (iniFiles != null) { for (String fileName : iniFiles.split(",")) { fileName = fileName.trim(); File currentConfFile = Paths.get(SeleniumTestsContextManager.getConfigPath(), fileName).toFile(); logger.info("reading file " + currentConfFile.getAbsolutePath()); try (InputStream iniFileStream = FileUtils.openInputStream(currentConfFile);) { variables.putAll(readConfig(iniFileStream, testEnv)); } catch (IOException e) { throw new ConfigurationException( String.format("File %s does not exist in data/<app>/config folder", fileName)); } } } return variables; }
From source file:ddf.catalog.resource.data.ReliableResource.java
private InputStream getProduct() throws IOException { if (filePath == null) { return null; }/* w ww. j a v a 2s .c o m*/ LOGGER.info("filePath = {}", filePath); return FileUtils.openInputStream(new File(filePath)); }