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.orpiske.ssps.common.resource.FileResourceExchange.java
@Override public Resource<InputStream> get(URI uri) throws ResourceExchangeException { File file = new File(uri); Resource<InputStream> ret = new Resource<InputStream>(); try {/*ww w . ja va 2s . c o m*/ inputStream = FileUtils.openInputStream(file); ret.setPayload(inputStream); ResourceInfo info = new ResourceInfo(); info.setSize(FileUtils.sizeOf(file)); info.setLastModified(file.lastModified()); ret.setResourceInfo(info); } catch (IOException e) { throw new ResourceExchangeException("I/O error: " + e.getMessage(), e); } return ret; }
From source file:birdnest.client.deamon.Settings.java
public void loadSettings(File currentFile) { try {/* ww w . j a va 2 s. co m*/ this.load(FileUtils.openInputStream(currentFile)); } catch (IOException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.antonjohansson.svncommit.core.config.Configuration.java
/** * Constructs a new {@link Configuration} with properties read from the given file. * * @param configurationFile The file to read properties from. *//*from w w w . ja va 2 s . c o m*/ public Configuration(File configurationFile) { try { Properties properties = new Properties(); properties.load(FileUtils.openInputStream(configurationFile)); this.replicationEnabled = Boolean.parseBoolean(properties.getProperty("replication-enabled")); } catch (IOException e) { throw new RuntimeException("Could not read configuration file", e); } }
From source file:net.dwarfguide.dfhack.DFHackConfigurationReader.java
public DFHackConfiguration deserialize() throws Exception { Serializer serializer = new Persister(); InputStream in;/*w w w. j a v a 2 s.c o m*/ try { in = FileUtils.openInputStream(new File(fileName)); } catch (IOException e) { LOGGER.info("Reading from bundled Memory.xml"); in = DFHackConfigurationReader.class.getResourceAsStream("Memory.xml"); } return serializer.read(DFHackConfiguration.class, in); }
From source file:it.marcoberri.mbmeteo.helper.ConfigurationHelper.java
private ConfigurationHelper() { try {// w ww . ja v a2s .c om final URL main = getClass().getProtectionDomain().getCodeSource().getLocation(); final String path = URLDecoder.decode(main.getPath(), "utf-8"); final String webInfFolderPosition = new File(path).getPath(); final String webInfFolder = webInfFolderPosition.substring(0, webInfFolderPosition.indexOf("classes")); prop = new Properties(); prop.load(FileUtils.openInputStream(new File(webInfFolder + File.separator + "config.properties"))); } catch (final IOException e) { throw new RuntimeException("Error initializing mongo db", e); } }
From source file:controllers.base.SecuredAction.java
public boolean hasVirus(File file) { if (file == null) { return false; }//from w w w . j a va 2 s .co m try { Process process = Runtime.getRuntime() .exec(Play.application().configuration().getString("application.virusChecker.command")); byte[] buffer = new byte[2048]; InputStream stream = FileUtils.openInputStream(file); while (IOUtils.read(stream, buffer, 0, 2048) != 0) { process.getOutputStream().write(buffer); } process.getOutputStream().close(); try { int result = process.waitFor(); if (result == 0) { return false; } else if (result == 1) { return true; } else { throw new InternalError(); } } catch (InterruptedException e) { return hasVirus(file); } } catch (IOException e) { throw new IllegalArgumentException(e); } }
From source file:gov.nih.nci.cacis.transform.XMLToRdfTransformerTest.java
@Before public void init() throws URISyntaxException, IOException { sampleMessageIS = FileUtils.openInputStream( new File(getClass().getClassLoader().getResource("caCISRequestSample3.xml").toURI())); sampleTrimIS = FileUtils.openInputStream( new File(getClass().getClassLoader().getResource("sample_transcend_trim.xml").toURI())); }
From source file:com.github.jrh3k5.habitat4j.app.test.rest.PropertiesClientInformationProvider.java
/** * Build a client information object.//w w w. j ava2 s.c om * * @param propertiesFile * A {@link File} from which data is to be read. * @return A {@link ClientInformation} built out of the given properties file. * @throws IOException * If any errors occur while reading the file. */ public ClientInformation getClientInformation(File propertiesFile) throws IOException { try (final InputStream inputStream = FileUtils.openInputStream(propertiesFile)) { final Properties properties = new Properties(); properties.load(inputStream); return new ClientInformation(properties.getProperty("client.code"), properties.getProperty("client.id"), properties.getProperty("client.secret")); } }
From source file:com.netflix.spinnaker.halyard.core.GlobalApplicationOptions.java
public static GlobalApplicationOptions getInstance() { if (GlobalApplicationOptions.options == null) { Yaml yamlParser = new Yaml(new SafeConstructor()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); try {// w w w . j a v a2 s . c o m GlobalApplicationOptions.options = objectMapper.convertValue( yamlParser.load(FileUtils.openInputStream(new File(CONFIG_PATH))), GlobalApplicationOptions.class); } catch (IOException e) { GlobalApplicationOptions.options = new GlobalApplicationOptions(); } } return GlobalApplicationOptions.options; }
From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterServerSystemTest.java
@Test public void invoke() throws Exception { InputStream sampleMessageIS = FileUtils .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI())); JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final CaCISRequest request = (CaCISRequest) jc.createUnmarshaller().unmarshal(sampleMessageIS); semanticAdapter.acceptSource(request); }