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:org.openhim.mediator.XDSMediatorMain.java
private static MediatorConfig loadConfig(String configPath) throws IOException, RoutingTable.RouteAlreadyMappedException { MediatorConfig config = new MediatorConfig(); if (configPath != null) { Properties props = new Properties(); File conf = new File(configPath); InputStream in = FileUtils.openInputStream(conf); props.load(in);//from w w w .j a v a 2 s .co m IOUtils.closeQuietly(in); config.setProperties(props); } else { config.setProperties("mediator.properties"); } config.setName(config.getProperty("mediator.name")); config.setServerHost(config.getProperty("mediator.host")); config.setServerPort(Integer.parseInt(config.getProperty("mediator.port"))); config.setRootTimeout(Integer.parseInt(config.getProperty("mediator.timeout"))); config.setCoreHost(config.getProperty("core.host")); config.setCoreAPIUsername(config.getProperty("core.api.user")); config.setCoreAPIPassword(config.getProperty("core.api.password")); if (config.getProperty("core.api.port") != null) { config.setCoreAPIPort(Integer.parseInt(config.getProperty("core.api.port"))); } config.setRoutingTable(buildRoutingTable()); config.setStartupActors(buildStartupActorsConfig()); InputStream regInfo = XDSMediatorMain.class.getClassLoader() .getResourceAsStream("mediator-registration-info.json"); RegistrationConfig regConfig = new RegistrationConfig(regInfo); config.setRegistrationConfig(regConfig); return config; }
From source file:org.opentestsystem.delivery.testreg.upload.parser.ExcelFileUploadParserTest.java
@Test public void testNormalExcel() throws Exception { final Workbook excelWb = makeNormalExcelFile(this.excelFile); excelWb.write(new FileOutputStream(this.excelFile)); final Map<String, List<DataRecord>> recordMap = this.excelParser .parse(FileUtils.openInputStream(this.excelFile), "GROUPOFSTATES").getParsedObject(); assertThat(recordMap, notNullValue()); assertThat(recordMap.get("GROUPOFSTATES").size(), is(3)); }
From source file:org.opentestsystem.delivery.testreg.upload.parser.ExcelFileUploadParserTest.java
@Test public void testNormalExcelWithBlankRows() throws Exception { final Workbook blankExcelWb = makeNormalExcelFile(this.excelFile); addBlankRows(blankExcelWb);/*w ww . ja v a2s .c om*/ blankExcelWb.write(new FileOutputStream(this.excelFile)); final Map<String, List<DataRecord>> recordMap = this.excelParser .parse(FileUtils.openInputStream(this.excelFile), "GROUPOFSTATES").getParsedObject(); assertThat(recordMap, notNullValue()); assertThat(recordMap.get("GROUPOFSTATES").size(), is(10)); }
From source file:org.opentestsystem.delivery.testreg.upload.parser.ExcelFileUploadParserTest.java
@Test(expected = IllegalArgumentException.class) public void testNormalExcelWithBlankRowsWithZeroRecordLength() throws Exception { final Workbook blankExcelWb = makeNormalExcelFile(this.excelFile); addBlankFormulaRows(blankExcelWb);//from ww w . ja v a 2 s. com blankExcelWb.write(new FileOutputStream(this.excelFile)); final Map<String, List<DataRecord>> recordMap = this.excelParser .parse(FileUtils.openInputStream(this.excelFile), "GROUPOFSTATES").getParsedObject(); assertThat(recordMap, notNullValue()); assertThat(recordMap.get("GROUPOFSTATES").size(), is(10)); }
From source file:org.opentestsystem.delivery.testreg.upload.parser.ExcelFileUploadParserTest.java
@Test public void testIgnoreBlankRows() throws Exception { this.excelParser.setIgnoreEmptyRows(true); final Workbook blankExcelWb = makeNormalExcelFile(this.excelFile); addBlankRows(blankExcelWb);/*from w ww . j av a 2s . c o m*/ blankExcelWb.write(new FileOutputStream(this.excelFile)); final Map<String, List<DataRecord>> recordMap = this.excelParser .parse(FileUtils.openInputStream(this.excelFile), "GROUPOFSTATES").getParsedObject(); assertThat(recordMap, notNullValue()); assertThat(recordMap.get("GROUPOFSTATES").size(), is(3)); }
From source file:org.opentestsystem.delivery.testreg.upload.parser.ExcelFileUploadParserTest.java
@Test public void testRowsWithWhitespaces() throws Exception { this.excelParser.setTrimRecords(true); final Workbook excelWb = makeNormalExcelFile(this.excelFile); addSomeRecordsWithWhitespaces(excelWb); excelWb.write(new FileOutputStream(this.excelFile)); final Map<String, List<DataRecord>> recordMap = this.excelParser .parse(FileUtils.openInputStream(this.excelFile), "GROUPOFSTATES").getParsedObject(); assertThat(recordMap, notNullValue()); assertThat(recordMap.get("GROUPOFSTATES").size(), is(5)); assertThat(recordMap.get("GROUPOFSTATES").get(3).getColumns(), is( new String[] { "China", "Asia", "1.35B", "200000", "Socialist-Communist", "President", "8 yrs" })); assertThat(recordMap.get("GROUPOFSTATES").get(4).getColumns(), is(new String[] { "Singapore", "Asia", "5.3M", "10000", "Capitalist", "President", "4 yrs" })); }
From source file:org.opoo.press.impl.ConfigImpl.java
/** * @param file/*from w w w. j a v a 2 s . com*/ */ @SuppressWarnings("unchecked") private void loadConfigFromFile(File file) { String name = file.getName(); InputStream inputStream = null; Map<String, Object> map = null; try { inputStream = FileUtils.openInputStream(file); if (FilenameUtils.isExtension(name, "json")) { if (objectMapper == null) { objectMapper = new ObjectMapper(); } map = objectMapper.readValue(inputStream, Map.class); } else { //yaml is not thread safe, so create new instance map = new Yaml().loadAs(inputStream, Map.class); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(inputStream); } if (map != null) { log.debug("Config loaded: {}", map); putAll(map); } }
From source file:org.overlord.dtgov.ui.server.servlets.DeploymentUploadServlet.java
/** * Uploads a single deployment to S-RAMP. * @param deploymentType//from ww w. j a va 2 s .c o m * @param fileName * @param client * @param tempFile * @param responseParams * @param version * @throws Exception */ private void uploadSingleDeployment(String deploymentType, String fileName, File tempFile, Map<String, String> responseParams, String version) throws Exception { ArtifactType at = ArtifactType.valueOf(deploymentType); String uuid = null; // First, upload the deployment InputStream contentStream = null; try { contentStream = FileUtils.openInputStream(tempFile); BaseArtifactType artifact = at.newArtifactInstance(); artifact.setName(fileName); artifact.setVersion(version); artifact = clientAccessor.getClient().uploadArtifact(artifact, contentStream); responseParams.put("model", at.getArtifactType().getModel()); //$NON-NLS-1$ responseParams.put("type", at.getArtifactType().getType()); //$NON-NLS-1$ responseParams.put("uuid", artifact.getUuid()); //$NON-NLS-1$ uuid = artifact.getUuid(); } finally { IOUtils.closeQuietly(contentStream); } // Try to expand the artifact (works if an expander is available for the given artifact type). ZipToSrampArchive j2sramp = null; SrampArchive archive = null; try { j2sramp = ZipToSrampArchiveRegistry.createExpander(at, tempFile); if (j2sramp != null) { j2sramp.setContextParam(DefaultMetaDataFactory.PARENT_UUID, uuid); archive = j2sramp.createSrampArchive(); clientAccessor.getClient().uploadBatch(archive); } } finally { SrampArchive.closeQuietly(archive); ZipToSrampArchive.closeQuietly(j2sramp); } }
From source file:org.overlord.sramp.atom.archive.expand.DiscoveredArtifact.java
/** * Returns an {@link InputStream} over the content of the artifact. * @throws IOException// w ww.j a va 2s. c o m */ public InputStream getContent() throws IOException { return FileUtils.openInputStream(file); }
From source file:org.overlord.sramp.atom.archive.SrampArchive.java
/** * Gets the content {@link InputStream} for the given S-RAMP archive entry. * @param entry the s-ramp archive entry * @return an {@link InputStream} over the artifact content or null if no content found (meta-data only) * @throws IOException//from www. j av a2 s .c o m */ public InputStream getInputStream(SrampArchiveEntry entry) throws IOException { File artifactPath = new File(this.workDir, entry.getPath()); if (artifactPath.exists()) return FileUtils.openInputStream(artifactPath); else return null; }