Java Code Examples for org.apache.commons.io.IOUtils#toBufferedInputStream()
The following examples show how to use
org.apache.commons.io.IOUtils#toBufferedInputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WordprocessingMLTemplateWriter.java From docx4j-template with Apache License 2.0 | 6 votes |
public static void writeToStream(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException { Assert.notNull(wmlPackage, " wmlPackage is not specified!"); Assert.notNull(output, " output is not specified!"); InputStream input = null; try { //Document对象 MainDocumentPart document = wmlPackage.getMainDocumentPart(); //Document XML String documentXML = XmlUtils.marshaltoString(wmlPackage); //转成字节输入流 input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes())); //输出模板 IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(input); } }
Example 2
Source File: WordprocessingMLTemplateWriter.java From docx4j-template with Apache License 2.0 | 6 votes |
public void writeToWriter(WordprocessingMLPackage wmlPackage,Writer output) throws IOException, Docx4JException { Assert.notNull(wmlPackage, " wmlPackage is not specified!"); Assert.notNull(output, " output is not specified!"); InputStream input = null; try { //Document对象 MainDocumentPart document = wmlPackage.getMainDocumentPart(); //Document XML String documentXML = XmlUtils.marshaltoString(wmlPackage.getPackage()); //转成字节输入流 input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes())); //获取模板输出编码格式 String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_WMLTEMPLATE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME ); //输出模板 IOUtils.copy(input, output, Charset.forName(charsetName)); } finally { IOUtils.closeQuietly(input); } }
Example 3
Source File: SaveImageCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test public void saveImage() throws Exception { try ( InputStream inputStream = dockerRule.getClient().saveImageCmd("busybox").exec(); InputStream image = IOUtils.toBufferedInputStream(inputStream) ) { assertThat(image.read(), not(-1)); } try ( InputStream inputStream = dockerRule.getClient().saveImageCmd("busybox").withTag("latest").exec(); InputStream image2 = IOUtils.toBufferedInputStream(inputStream) ) { assertThat(image2.read(), not(-1)); } }
Example 4
Source File: TestHttpService.java From arcusplatform with Apache License 2.0 | 5 votes |
@Test public void testHttpDownload() throws Exception { File output = HttpService.download("http://httpbin.org/stream-bytes/1024"); output.deleteOnExit(); System.out.println("downloaded file: " + output); System.out.println("downloaded file size: " + output.length()); try (InputStream is = IOUtils.toBufferedInputStream(new FileInputStream(output))) { byte[] results = IOUtils.toByteArray(is); Assert.assertTrue("download did not work correctly", results != null && results.length > 16); } }
Example 5
Source File: SaveImagesCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void saveNoImages() throws Exception { try ( InputStream inputStream = dockerRule.getClient().saveImagesCmd().exec(); InputStream image = IOUtils.toBufferedInputStream(inputStream) ){ assertThat(image.read(), not(-1)); } }
Example 6
Source File: SaveImagesCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void saveImagesWithNameAndTag() throws Exception { try ( InputStream inputStream = dockerRule.getClient().saveImagesCmd().withImage("busybox", "latest").exec(); InputStream image = IOUtils.toBufferedInputStream(inputStream) ) { assertThat(image.read(), not(-1)); } }
Example 7
Source File: SaveImagesCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void saveMultipleImages() throws Exception { try ( InputStream inputStream = dockerRule.getClient().saveImagesCmd() // Not a real life use-case but "busybox" is the only one I dare to assume is really there. .withImage("busybox", "latest") .withImage("busybox", "latest") .exec(); InputStream image = IOUtils.toBufferedInputStream(inputStream) ) { assertThat(image.read(), not(-1)); } }