@Override public OutputStream getContentOutputStream() throws ContentIOException { OutputStream result = delegatee.getContentOutputStream(); if (null == releaseableResource) { releaseableResource = result; } return result; }
@Override public OutputStream getContentOutputStream() throws ContentIOException { return this.cacheWriter.getContentOutputStream(); }
@Override public OutputStream getContentOutputStream() throws ContentIOException { OutputStream result = delegatee.getContentOutputStream(); if (null == releaseableResource) { releaseableResource = result; } return result; }
@Override public OutputStream getContentOutputStream() throws ContentIOException { return this.cacheWriter.getContentOutputStream(); }
@Override public Object doWork() throws Exception { ContentWriter writer = contentService.getWriter(downloadNode, ContentModel.PROP_CONTENT, true); FileCopyUtils.copy(new FileInputStream(archiveFile), writer.getContentOutputStream()); return null; } });
@Override public Object doWork() throws Exception { ContentWriter writer = contentService.getWriter(downloadNode, ContentModel.PROP_CONTENT, true); FileCopyUtils.copy(new FileInputStream(archiveFile), writer.getContentOutputStream()); return null; } });
public OutputStream writeFile(NodeRef base, String path) { NodeRef target = lookup(base, path).getFirst(); return fContentService.getWriter(target, ContentModel.PROP_CONTENT, true).getContentOutputStream(); }
public OutputStream writeFile(NodeRef base, String path) { NodeRef target = lookup(base, path).getFirst(); return fContentService.getWriter(target, ContentModel.PROP_CONTENT, true).getContentOutputStream(); }
writer = new OutputStreamWriter(contentWriter.getContentOutputStream()); processTemplate(context, templateNode, model, writer);
/** * Delete the content stream */ public void delete() { ContentService contentService = services.getContentService(); ContentWriter writer = contentService.getWriter(nodeRef, this.property, true); OutputStream output = writer.getContentOutputStream(); try { output.close(); } catch (IOException e) { // NOTE: fall-through } writer.setMimetype(null); writer.setEncoding(null); // update cached variables after putContent() updateContentData(true); }
/** * Delete the content stream */ public void delete() { ContentService contentService = services.getContentService(); ContentWriter writer = contentService.getWriter(nodeRef, this.property, true); OutputStream output = writer.getContentOutputStream(); try { output.close(); } catch (IOException e) { // NOTE: fall-through } writer.setMimetype(null); writer.setEncoding(null); // update cached variables after putContent() updateContentData(true); }
os = writer.getContentOutputStream(); pdf.save(os);
public OutputStream createFile(NodeRef base, String path) { Pair<NodeRef, String> parentChild = getParentChildRelative(base, path); FileInfo info = fFileFolderService.create(parentChild.getFirst(), parentChild.getSecond(), ContentModel.TYPE_CONTENT); // TODO is update supposed to be true. ContentWriter writer = fContentService.getWriter(info.getNodeRef(), ContentModel.PROP_CONTENT, true); return writer.getContentOutputStream(); }
public OutputStream createFile(NodeRef base, String path) { Pair<NodeRef, String> parentChild = getParentChildRelative(base, path); FileInfo info = fFileFolderService.create(parentChild.getFirst(), parentChild.getSecond(), ContentModel.TYPE_CONTENT); // TODO is update supposed to be true. ContentWriter writer = fContentService.getWriter(info.getNodeRef(), ContentModel.PROP_CONTENT, true); return writer.getContentOutputStream(); }
/** * Writes the content of incoming message into Alfresco repository. * * @throws MessagingException */ private void writeContent() throws MessagingException { ContentWriter writer = serviceRegistry.getContentService().getWriter(messageFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_RFC822); try { OutputStream outputStream = writer.getContentOutputStream(); wrappedMessage.writeTo(outputStream); outputStream.close(); wrappedMessage = null; // it is not used any more and it is available to GC (to avoid memory leak with byte[] MimeMessage.content field) this.contentReader = serviceRegistry.getContentService().getReader(messageFileInfo.getNodeRef(), ContentModel.PROP_CONTENT); } catch (ContentIOException e) { throw new MessagingException(e.getMessage(), e); } catch (IOException e) { throw new MessagingException(e.getMessage(), e); } }
/** * Writes the content of incoming message into Alfresco repository. * * @throws MessagingException */ private void writeContent() throws MessagingException { ContentWriter writer = serviceRegistry.getContentService().getWriter(messageFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_RFC822); try { OutputStream outputStream = writer.getContentOutputStream(); wrappedMessage.writeTo(outputStream); outputStream.close(); wrappedMessage = null; // it is not used any more and it is available to GC (to avoid memory leak with byte[] MimeMessage.content field) this.contentReader = serviceRegistry.getContentService().getReader(messageFileInfo.getNodeRef(), ContentModel.PROP_CONTENT); } catch (ContentIOException e) { throw new MessagingException(e.getMessage(), e); } catch (IOException e) { throw new MessagingException(e.getMessage(), e); } }
@Test public void testReadAndWriteStreamByPush() throws Exception { ContentWriter writer = getWriter(); String content = "Some Random Content"; // get the content output stream OutputStream os = writer.getContentOutputStream(); os.write(content.getBytes()); assertFalse("Stream has not been closed", writer.isClosed()); // close the stream and check again os.close(); assertTrue("Stream close not detected", writer.isClosed()); // pull the content from a stream ContentReader reader = writer.getReader(); InputStream is = reader.getContentInputStream(); byte[] buffer = new byte[100]; int count = is.read(buffer); assertEquals("No content read", content.length(), count); is.close(); String check = new String(buffer, 0, count); assertEquals("Write out of and read into files failed", content, check); }
public void testAlf6560MimetypeSetting() throws Exception { FileInfo fileInfo = fileFolderService.create(workingRootNodeRef, "Something.html", ContentModel.TYPE_CONTENT); NodeRef fileNodeRef = fileInfo.getNodeRef(); // Write the content but without setting the mimetype ContentWriter writer = fileFolderService.getWriter(fileNodeRef); writer.putContent("CONTENT"); ContentReader reader = fileFolderService.getReader(fileNodeRef); assertEquals("Mimetype was not automatically set", MimetypeMap.MIMETYPE_HTML, reader.getMimetype()); // Now ask for encoding too writer = fileFolderService.getWriter(fileNodeRef); writer.guessEncoding(); OutputStream out = writer.getContentOutputStream(); out.write( "<html><body>hall\u00e5 v\u00e4rlden</body></html>".getBytes("UnicodeBig") ); out.close(); reader = fileFolderService.getReader(fileNodeRef); assertEquals("Mimetype was not automatically set", MimetypeMap.MIMETYPE_HTML, reader.getMimetype()); assertEquals("Encoding was not automatically set", "UTF-16BE", reader.getEncoding()); }
public void testZeroLengthFile() throws Exception { MetadataExtracter extractor = getExtracter(); File file = TempFileProvider.createTempFile(getName(), ".bin"); ContentWriter writer = new FileContentWriter(file); writer.getContentOutputStream().close(); ContentReader reader = writer.getReader(); // Try the zero length file against all supported mimetypes. // Note: Normally the reader would need to be fetched for each access, but we need to be sure // that the content is not accessed on the reader AT ALL. PropertyMap properties = new PropertyMap(); List<String> mimetypes = mimetypeMap.getMimetypes(); for (String mimetype : mimetypes) { if (!extractor.isSupported(mimetype)) { // Not interested continue; } reader.setMimetype(mimetype); extractor.extract(reader, properties); assertEquals("There should not be any new properties", 0, properties.size()); } }
@Test public void testMimetypAndEncodingAndLocale() throws Exception { ContentWriter writer = getWriter(); // set mimetype and encoding writer.setMimetype("text/plain"); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // create a UTF-16 string String content = "A little bit o' this and a little bit o' that"; byte[] bytesUtf16 = content.getBytes("UTF-16"); // write the bytes directly to the writer OutputStream os = writer.getContentOutputStream(); os.write(bytesUtf16); os.close(); // now get a reader from the writer ContentReader reader = writer.getReader(); assertEquals("Writer -> Reader content URL mismatch", writer.getContentUrl(), reader.getContentUrl()); assertEquals("Writer -> Reader mimetype mismatch", writer.getMimetype(), reader.getMimetype()); assertEquals("Writer -> Reader encoding mismatch", writer.getEncoding(), reader.getEncoding()); assertEquals("Writer -> Reader locale mismatch", writer.getLocale(), reader.getLocale()); // now get the string directly from the reader String contentCheck = reader.getContentString(); // internally it should have taken care of the encoding assertEquals("Encoding and decoding of strings failed", content, contentCheck); }