List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:org.wte4j.impl.word.Docx4JWordTemplateTest.java
@Test public void writeAsOpenXMLTest() throws IOException, Docx4JException, JAXBException { Docx4JWordTemplate doc = new Docx4JWordTemplate(); File file = File.createTempFile("test", "docx"); OutputStream out = FileUtils.openOutputStream(file); try {// www . j a v a 2 s .c o m doc.writeAsOpenXML(out); } finally { IOUtils.closeQuietly(out); } ZipFile zipFile = new ZipFile(file); ZipEntry entry = zipFile.getEntry("word/document.xml"); assertNotNull(entry); }
From source file:org.wte4j.impl.WordTemplate.java
@Override public void toDocument(E data, File file) throws IOException, InvalidTemplateException, WteException { OutputStream out = FileUtils.openOutputStream(file); toDocument(data, out);/*from ww w . ja v a 2s . co m*/ }
From source file:org.wte4j.impl.WordTemplate.java
@Override public void toTestDocument(File file) throws IOException, InvalidTemplateException { OutputStream out = FileUtils.openOutputStream(file); toTestDocument(out);/*from ww w. j a v a2 s. c o m*/ }
From source file:org.wte4j.impl.WordTemplate.java
@Override public void write(File file) throws IOException { OutputStream out = FileUtils.openOutputStream(file); write(out); }
From source file:org.wte4j.impl.WordTemplateRepositoryTest.java
@Test @Transactional/*w ww .j av a 2s . c om*/ public void persistTemplateWithFileStore() throws Exception { WordTemplate<?> template = newTemplate(); FileStore fileStore = mock(FileStore.class); File file = File.createTempFile("content", "docx"); OutputStream out = FileUtils.openOutputStream(file); when(fileStore.getOutStream(anyString())).thenReturn(out); repository.setFileStore(fileStore); try { repository.persist(template); File epected = FileUtils.toFile(getClass().getResource("empty.docx")); assertTrue(FileUtils.contentEquals(epected, file)); } finally { file.deleteOnExit(); } }
From source file:org.wte4j.impl.WordTemplateRepositoryTest.java
@Test @Transactional/*from ww w . j a v a 2 s .c o m*/ public void updateTemplateWithFileStore() throws Exception { FileStore fileStore = mock(FileStore.class); File file = File.createTempFile("content", "docx"); OutputStream out = FileUtils.openOutputStream(file); when(fileStore.getOutStream(anyString())).thenReturn(out); repository.setFileStore(fileStore); WordTemplate<?> template = unlockedTemplate(); template.getPersistentData().setContent(getContent("empty.docx")); try { repository.persist(template); File expected = FileUtils.toFile(getClass().getResource("empty.docx")); assertTrue(FileUtils.contentEquals(expected, file)); } finally { file.deleteOnExit(); } }
From source file:org.wte4j.persistence.WordTemplateRepositoryTest.java
@Test @Transactional/* www. j av a2 s . co m*/ public void persistTemplateWithFileStore() throws Exception { WordTemplate<?> template = newTemplate(); FileStore fileStore = mock(FileStore.class); File file = File.createTempFile("content", "docx"); OutputStream out = FileUtils.openOutputStream(file); when(fileStore.getOutStream(anyString())).thenReturn(out); repository.setFileStore(fileStore); try { repository.persist(template); File epected = FileUtils.toFile(getClass().getResource("empty.docx")); assertTrue(FileUtils.contentEquals(epected, file)); } finally { file.deleteOnExit(); } }
From source file:org.wte4j.persistence.WordTemplateRepositoryTest.java
@Test @Transactional/*from w w w . ja v a2s .c o m*/ public void updateTemplateWithFileStore() throws Exception { FileStore fileStore = mock(FileStore.class); File file = File.createTempFile("content", "docx"); OutputStream out = FileUtils.openOutputStream(file); when(fileStore.getOutStream(anyString())).thenReturn(out); repository.setFileStore(fileStore); WordTemplate<?> template = unlockedTemplate(); template.getTemplateData().setContent(getContent("empty.docx"), new User()); try { repository.persist(template); File expected = FileUtils.toFile(getClass().getResource("empty.docx")); assertTrue(FileUtils.contentEquals(expected, file)); } finally { file.deleteOnExit(); } }
From source file:org.xwiki.extension.job.internal.DefaultJobStatusStorage.java
/** * @param status the job status to save//from w w w. jav a 2 s . c om * @throws IOException when falling to store the provided status */ private void saveJobStatus(JobStatus status) throws IOException { File statusFile = getJobFolder(status.getRequest().getId()); statusFile = new File(statusFile, FILENAME_STATUS); FileOutputStream stream = FileUtils.openOutputStream(statusFile); try { OutputStreamWriter writer = new OutputStreamWriter(stream, DEFAULT_ENCODING); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); this.xstream.toXML(status, writer); writer.flush(); } finally { IOUtils.closeQuietly(stream); } }
From source file:org.xwiki.extension.repository.internal.DefaultLocalExtensionRepository.java
@Override public LocalExtension storeExtension(Extension extension) throws LocalExtensionRepositoryException { DefaultLocalExtension localExtension = this.extensions.get(extension.getId()); if (localExtension == null) { try {//from ww w . j a v a 2 s. com localExtension = createExtension(extension); // Store extension in the local repository FileOutputStream fos = FileUtils.openOutputStream(localExtension.getFile().getFile()); try { InputStream is = extension.getFile().openStream(); try { IOUtils.copy(is, fos); } finally { is.close(); } } finally { fos.close(); } this.storage.saveDescriptor(localExtension); // Cache extension addLocalExtension(localExtension); } catch (Exception e) { // TODO: clean throw new LocalExtensionRepositoryException( "Failed to save extensoin [" + extension + "] descriptor", e); } } else { throw new LocalExtensionRepositoryException( "Extension [" + extension + "] already exists in local repository"); } return localExtension; }