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.digidoc4j.ContainerBuilderTest.java
@Test public void openDDocContainerFromStreamWithTempDirectory() throws Exception { assertTrue(tempFolder.list().length == 0); InputStream stream = FileUtils.openInputStream(new File(DDOC_TEST_FILE)); ContainerBuilder.aContainer("DDOC").fromStream(stream).usingTempDirectory(tempFolder.getPath()).build(); assertTrue(tempFolder.list().length > 0); }
From source file:org.digidoc4j.ContainerBuilderTest.java
@Test public void openDDocContainerFromStreamWithTempDirectoryAndConfiguration() throws Exception { assertTrue(tempFolder.list().length == 0); InputStream stream = FileUtils.openInputStream(new File(DDOC_TEST_FILE)); ContainerBuilder.aContainer("DDOC").withConfiguration(TEST_CONFIGURATION).fromStream(stream) .usingTempDirectory(tempFolder.getPath()).build(); assertTrue(tempFolder.list().length > 0); }
From source file:org.digidoc4j.ContainerOpenerTest.java
@Test public void openBDocContainerAsStream() throws Exception { FileInputStream stream = FileUtils.openInputStream(new File(BDOC_TEST_FILE)); Container container = ContainerOpener.open(stream, configuration); assertContainerOpened(container, "BDOC"); }
From source file:org.digidoc4j.ContainerOpenerTest.java
@Test public void openDDocContainerAsStream() throws Exception { FileInputStream stream = FileUtils.openInputStream(new File(DDOC_TEST_FILE)); Container container = ContainerOpener.open(stream, configuration); assertContainerOpened(container, "DDOC"); }
From source file:org.digidoc4j.ContainerOpenerTest.java
@Test public void openBDocContainerAsStream_WithBigFilesNotSupported() throws Exception { boolean bigFilesSupportEnabled = false; FileInputStream stream = FileUtils.openInputStream(new File(BDOC_TEST_FILE)); Container container = ContainerOpener.open(stream, bigFilesSupportEnabled); assertContainerOpened(container, "BDOC"); }
From source file:org.duracloud.common.util.IOUtil.java
public static InputStream getFileStream(File file) { try {//from w w w. j a va2 s.c o m return new AutoCloseInputStream(FileUtils.openInputStream(file)); } catch (IOException e) { String err = "Error opening stream from file " + file.getAbsolutePath() + ": " + e.getMessage(); throw new DuraCloudRuntimeException(err, e); } }
From source file:org.duracloud.mill.dup.DuplicationTaskProcessor.java
private void putDestinationContent(final String spaceId, final String contentId, final String sourceChecksum, final Map<String, String> sourceProperties, final File file) throws TaskExecutionFailedException { try {/*ww w . j av a 2 s. co m*/ new Retrier().execute(new Retriable() { @Override public String retry() throws Exception { String srcMimetype = sourceProperties.get(StorageProvider.PROPERTIES_CONTENT_MIMETYPE); // Push to destination try (InputStream destStream = FileUtils.openInputStream(file)) { String destChecksum = destStore.addContent(spaceId, contentId, srcMimetype, sourceProperties, file.length(), sourceChecksum, destStream); if (sourceChecksum.equals(destChecksum)) { return "success"; } else { throw new RuntimeException("Checksum in dest " + "does not match source"); } } } }); } catch (Exception e) { cleanup(file); String msg = "Error attempting to add destination content: " + e.getMessage(); throw new DuplicationTaskExecutionFailedException(buildFailureMessage(msg), e); } }
From source file:org.duracloud.services.duplication.impl.ContentDuplicatorImpl.java
private FileInputStream openInputStream(File file) { try {// w ww.j a va 2s . c o m return FileUtils.openInputStream(file); } catch (IOException e) { String err = "Unable to open file: " + file.getAbsolutePath(); log.error(err + ", due to: {}", e.getMessage()); throw new DuraCloudRuntimeException(err, e); } }
From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java
private Xpp3Dom readExistingIpLog(final File iplogXmlFile) throws MojoExecutionException { final Xpp3Dom existingIpLog; if (iplogXmlFile.isFile()) { try (InputStream is = FileUtils.openInputStream(iplogXmlFile)) { existingIpLog = Xpp3DomBuilder.build(is, UTF_8); } catch (IOException | XmlPullParserException e) { getLog().debug(e);/*from ww w .jav a2s .com*/ throw new MojoExecutionException( format("Unable to read ip_log.xml file '%s'. %s", iplogXmlFile, e.getMessage())); } } else { existingIpLog = null; } return existingIpLog; }
From source file:org.eclipse.gyrex.preferences.internal.console.ImportCmd.java
@Override protected void doExecute() throws Exception { final IPreferencesService preferencesService = EclipsePreferencesUtil.getPreferencesService(); if (!StringUtils.endsWithIgnoreCase(file.getName(), FILE_EXT_EPF)) { file = new File(file.getParentFile(), file.getName().concat(FILE_EXT_EPF)); }/*from www. j a v a 2s.c o m*/ if (!file.isFile() || !file.canRead()) { printf("ERROR: Unable to read file %s", file.getAbsolutePath()); return; } IEclipsePreferences node = preferencesService.getRootNode(); final String path = ci.nextArgument(); if (StringUtils.isNotBlank(path)) { node = (IEclipsePreferences) node.node(path); } final FileInputStream in = FileUtils.openInputStream(file); try { preferencesService.importPreferences(in); printf("Successfully imported preferences from %s.", node.absolutePath(), file.getAbsolutePath()); } finally { IOUtils.closeQuietly(in); } }