List of usage examples for org.apache.commons.io.input AutoCloseInputStream AutoCloseInputStream
public AutoCloseInputStream(InputStream in)
From source file:org.duracloud.common.util.ApplicationConfig.java
public static Properties getPropsFromXml(String propsXml) { AutoCloseInputStream in = new AutoCloseInputStream(new ByteArrayInputStream(propsXml.getBytes())); return getPropsFromXmlStream(in); }
From source file:org.duracloud.common.util.ApplicationConfig.java
public static Properties getPropsFromXmlResource(String resourceName) { Properties props = new Properties(); AutoCloseInputStream in = new AutoCloseInputStream( ApplicationConfig.class.getClassLoader().getResourceAsStream(resourceName)); try {/*from ww w . j a va2 s. c o m*/ props.loadFromXML(in); } catch (Exception e) { String error = "Unable to find resource: '" + resourceName + "': " + e.getMessage(); throw new RuntimeException(error); } return props; }
From source file:org.duracloud.common.util.bulk.ManifestVerifier.java
private InputStream getInputStream(File file) { try {/*ww w . ja v a 2s.c om*/ return new AutoCloseInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.duracloud.common.util.IOUtil.java
public static InputStream getFileStream(File file) { try {/* www . jav a2s .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.durastore.rest.ContentRest.java
private Response doGetContent(String spaceID, String contentID, String storeID, boolean attachment, String range) throws InvalidRequestException, ResourceException { RetrievedContent retrievedContent = contentResource.getContent(spaceID, contentID, storeID, range); InputStream content = new AutoCloseInputStream(retrievedContent.getContentStream()); ResponseBuilder responseBuilder;/*from w w w. jav a 2 s. c o m*/ if (StringUtils.isNotEmpty(range)) { responseBuilder = Response.status(HttpStatus.SC_PARTIAL_CONTENT).entity(content); } else { responseBuilder = Response.ok(content); } if (attachment) { addContentDispositionHeader(responseBuilder, contentID); } return addContentPropertiesToResponse(responseBuilder, retrievedContent.getContentProperties()); }
From source file:org.duracloud.manifeststitch.StitchedManifestGenerator.java
public InputStream generate(String spaceId, ManifestFormat format) throws IOException { final File stitchedManifestFile = File.createTempFile("stitched-manifest-" + spaceId, "." + format.name().toLowerCase()); //download manifest and process each line. try (InputStream manifest = store.getManifest(spaceId, format); BufferedReader reader = new BufferedReader(new InputStreamReader(manifest)); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(stitchedManifestFile)));) { ManifestFormatter formatter = new ManifestFormatterFactory().create(format); String header = formatter.getHeader(); String line = null;//from www . j a v a 2 s .c om try { while ((line = reader.readLine()) != null) { //ignore any whitespace if (line.trim().length() == 0) { continue; } //write header if there is one. if (header != null && line.equals(header)) { writeLine(line, writer); continue; } //process the line processLine(line, formatter, writer); } } catch (IOException e) { log.error("failed to complete manifest stiching.", e); } } catch (ContentStoreException e) { log.error("failed to generate stitched manifest: " + e.getMessage(), e); throw new IOException(e); } return new AutoCloseInputStream(new FileInputStream(stitchedManifestFile) { @Override public void close() throws IOException { super.close(); stitchedManifestFile.delete(); } }); }
From source file:org.duracloud.services.duplication.ContentDuplicatorCreateTest.java
private InputStream getStream(String text) { return new AutoCloseInputStream(new ByteArrayInputStream(text.getBytes())); }
From source file:org.exoplatform.outlook.jcr.ContentLink.java
/** * Content.// ww w.ja v a 2s . c om * * @param userId the user id * @param workspace the workspace * @param path the path * @return the node content * @throws Exception the exception */ protected NodeContent content(String userId, String workspace, String path) throws Exception { Node node = node(userId, workspace, path); Node content = node.getNode("jcr:content"); final String mimeType = content.getProperty("jcr:mimeType").getString(); // data stream will be closed when EoF will be reached final InputStream data = new AutoCloseInputStream(content.getProperty("jcr:data").getStream()); return new NodeContent() { @Override public String getType() { return mimeType; } @Override public InputStream getData() { return data; } }; }
From source file:org.jahia.modules.external.ExtensionProperty.java
@Override public InputStream getStream() throws ValueFormatException, RepositoryException { checkRead();//from w w w. j a va 2 s . c o m final Binary binary = property.getValue().getBinary(); return new AutoCloseInputStream(binary.getStream()) { @Override public void close() throws IOException { super.close(); binary.dispose(); } }; }
From source file:org.jahia.modules.external.ExternalPropertyImpl.java
public InputStream getStream() throws ValueFormatException, RepositoryException { checkRead();//from w w w.j a v a2s . c o m if (value != null) { final Binary binary = value.getBinary(); return new AutoCloseInputStream(binary.getStream()) { @Override public void close() throws IOException { super.close(); binary.dispose(); } }; } return null; }