@Override public void getContent(OutputStream os) throws ContentIOException { delegatee.getContent(os); }
@Override public void getContent(OutputStream os) throws ContentIOException { delegatee.getContent(os); }
@Override public void getContent(File file) throws ContentIOException { delegatee.getContent(file); }
@Override public void getContent(File file) throws ContentIOException { delegatee.getContent(file); }
File tmp = File.createTempFile("for-ocr",".tmp"); ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); reader.getContent(tmp); // Run the OCR program here tmp.delete();
private void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension) throws Exception { // create required temp files File sourceFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_source_", "." + sourceExtension); File targetFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_target_", "." + targetExtension); // pull reader file into source temp file reader.getContent(sourceFile); // For most target mimetypes, it only makes sense to read the first page of the // source, as the target is a single page, so set the pageLimit automatically. // However for others, such as PDF (see ALF-7278) all pages should be read. // transform the source temp file to the target temp file transformInternal(sourceFile, sourceMimetype, targetFile, targetMimetype, options); // check that the file was created if (!targetFile.exists() || targetFile.length() == 0) { throw new ContentIOException("ImageMagick transformation failed to write output file"); } // upload the output image writer.putContent(targetFile); }
private void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension) throws Exception { // create required temp files File sourceFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_source_", "." + sourceExtension); File targetFile = TempFileProvider.createTempFile( getClass().getSimpleName() + "_target_", "." + targetExtension); // pull reader file into source temp file reader.getContent(sourceFile); // For most target mimetypes, it only makes sense to read the first page of the // source, as the target is a single page, so set the pageLimit automatically. // However for others, such as PDF (see ALF-7278) all pages should be read. // transform the source temp file to the target temp file transformInternal(sourceFile, sourceMimetype, targetFile, targetMimetype, options); // check that the file was created if (!targetFile.exists() || targetFile.length() == 0) { throw new ContentIOException("ImageMagick transformation failed to write output file"); } // upload the output image writer.putContent(targetFile); }
/** * Populates a file with the content in the reader. */ public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException { String encoding = reader.getEncoding(); if (encodeAsUtf8(sourceMimetype, encoding)) { saveContentInUtf8File(reader, file); } else { reader.getContent(file); } }
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable { String sourceMimetype = reader.getMimetype(); if (logger.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Extracting metadata content from ") .append(sourceMimetype); logger.debug(msg.toString()); } // create temporary files to convert from and to File tempFile = TempFileProvider.createTempFile(this.getClass() .getSimpleName() + "-", "." + mimetypeService.getExtension(sourceMimetype)); // download the content from the source reader reader.getContent(tempFile); ResultsCallback callback = new ResultsCallback(); jodc.getOfficeManager().execute(new ExtractMetadataOfficeTask(tempFile, callback)); return callback.getResults(); }
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable { String sourceMimetype = reader.getMimetype(); if (logger.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("Extracting metadata content from ") .append(sourceMimetype); logger.debug(msg.toString()); } // create temporary files to convert from and to File tempFile = TempFileProvider.createTempFile(this.getClass() .getSimpleName() + "-", "." + mimetypeService.getExtension(sourceMimetype)); // download the content from the source reader reader.getContent(tempFile); ResultsCallback callback = new ResultsCallback(); jodc.getOfficeManager().execute(new ExtractMetadataOfficeTask(tempFile, callback)); return callback.getResults(); }
/** * Populates a file with the content in the reader. */ public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException { String encoding = reader.getEncoding(); if (encodeAsUtf8(sourceMimetype, encoding)) { saveContentInUtf8File(reader, file); } else { reader.getContent(file); } }
private void outputThumbnailTempContentLocation(NodeRef thumbnail, String ext, String message) throws IOException { File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", "." + ext); ContentReader reader = this.contentService.getReader(thumbnail, ContentModel.PROP_CONTENT); reader.getContent(tempFile); System.out.println(message + ": " + tempFile.getPath()); }
@Override public boolean put(String contentUrl, ContentReader source) { File tempFile = createCacheFile(); // Copy the content from the source into a cache file if (source.getSize() > 0L) { source.getContent(tempFile); File cacheFile = renameTempToActive(tempFile); // Add a record of the cached file to the in-memory cache. recordCacheEntries(contentUrl, cacheFile); return true; } return false; }
@Override public Void execute() throws Throwable { ContentReader reader = contentService.getReader(sharePersistedExtNodeRef, ContentModel.PROP_CONTENT); originalShareExtFile = TempFileProvider.createTempFile(CustomModelServiceImplTest.class.getName(), ".xml"); reader.getContent(originalShareExtFile); return null; } });
@Override public boolean put(String contentUrl, ContentReader source) { File tempFile = createCacheFile(); // Copy the content from the source into a cache file if (source.getSize() > 0L) { source.getContent(tempFile); File cacheFile = renameTempToActive(tempFile); // Add a record of the cached file to the in-memory cache. recordCacheEntries(contentUrl, cacheFile); return true; } return false; }
@Test public void testReadAndWriteStreamByPull() throws Exception { ContentWriter writer = getWriter(); String content = "ABC"; // put the content using a stream InputStream is = new ByteArrayInputStream(content.getBytes()); writer.putContent(is); assertTrue("Stream close not detected", writer.isClosed()); // get the content using a stream ByteArrayOutputStream os = new ByteArrayOutputStream(100); ContentReader reader = writer.getReader(); reader.getContent(os); byte[] bytes = os.toByteArray(); String check = new String(bytes); assertEquals("Write out and read in using streams failed", content, check); }
public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception { // We can only work from a file File htmlFile = TempFileProvider.createTempFile("HtmlParserContentTransformer_", ".html"); reader.getContent(htmlFile); // Fetch the encoding of the HTML, as set in the ContentReader // This will default to 'UTF-8' if not specifically set String encoding = reader.getEncoding(); // Create the extractor EncodingAwareStringBean extractor = new EncodingAwareStringBean(); extractor.setCollapse(false); extractor.setLinks(false); extractor.setReplaceNonBreakingSpaces(false); extractor.setURL(htmlFile, encoding); // get the text String text = extractor.getStrings(); // write it to the writer writer.putContent(text); // Tidy up htmlFile.delete(); } }
public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception { // We can only work from a file File htmlFile = TempFileProvider.createTempFile("HtmlParserContentTransformer_", ".html"); reader.getContent(htmlFile); // Fetch the encoding of the HTML, as set in the ContentReader // This will default to 'UTF-8' if not specifically set String encoding = reader.getEncoding(); // Create the extractor EncodingAwareStringBean extractor = new EncodingAwareStringBean(); extractor.setCollapse(false); extractor.setLinks(false); extractor.setReplaceNonBreakingSpaces(false); extractor.setURL(htmlFile, encoding); // get the text String text = extractor.getStrings(); // write it to the writer writer.putContent(text); // Tidy up htmlFile.delete(); } }
reader.getContent(sinkFile);
@Test public void testCreateRenditionThumbnailFromPdfPage2() throws Exception { ImageTransformationOptions options = new ImageTransformationOptions(); PagedSourceOptions pagedSourceOptions = new PagedSourceOptions(); pagedSourceOptions.setStartPageNumber(new Integer(2)); pagedSourceOptions.setEndPageNumber(new Integer(2)); options.addSourceOptions(pagedSourceOptions); ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2"); thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition); checkTransformer(); NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF); NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2"); assertNotNull(thumbnail0); checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1))); checkRendition("doclib_2", thumbnail0); // Check the length File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg"); ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT); long size = reader.getSize(); System.out.println("size=" + size); assertTrue("Page 2 should be blank and less than 4500 bytes", size < 4500); reader.getContent(tempFile); System.out.println("doclib_2 test: " + tempFile.getPath()); }