@Override public InputStream getStream() throws XWikiException { return this.attachment.getContentInputStream(this.context); } }
@Override public InputStream getStream() throws XWikiException { return this.attachment.getContentInputStream(this.context); } }
/** * Returns the content of this attachment. * * @return an input stream for reading the attachment content */ public InputStream getContent() { try { return this.attachment.getContentInputStream(this.contextProvider.get()); } catch (Exception e) { return null; } }
/** * @param attachment an image attachment * @param context the XWiki context * @return the width of the specified image * @throws IOException if reading the image from the attachment content fails * @throws XWikiException if reading the attachment content fails */ public int getWidth(XWikiAttachment attachment, XWikiContext context) throws IOException, XWikiException { return this.imageProcessor.readImage(attachment.getContentInputStream(context)).getWidth(null); }
/** * @param attachment an image attachment * @param context the XWiki context * @return the height of the specified image * @throws IOException if reading the image from the attachment content fails * @throws XWikiException if reading the attachment content fails */ public int getHeight(XWikiAttachment attachment, XWikiContext context) throws IOException, XWikiException { return this.imageProcessor.readImage(attachment.getContentInputStream(context)).getHeight(null); } }
private boolean isCorrectVCF(XWikiAttachment attachment, String eid, XWikiContext context) throws XWikiException, IOException { BufferedReader in = IOUtils.toBufferedReader(new InputStreamReader(attachment.getContentInputStream(context), XWiki.DEFAULT_ENCODING)); String line; while ((line = in.readLine()) != null) { if (line.startsWith("##")) { // Still in the meta, go on continue; } else if (!line.startsWith("#CHROM")) { // Actual data, we're past the meta but didn't encounter the header, strange... // Malformed file, abandon break; } String[] fields = line.split("\t"); if (fields.length != 10 || !StringUtils.equals(eid, fields[9])) { // Wrong sample ID or more than one sample, bail out break; } return true; } return false; } }
/** * Generate an url targeting attachment in provided wiki page. * * @param filename the name of the attachment. * @param space the space of the page containing the attachment. * @param name the name of the page containing the attachment. * @param xwikidb the wiki of the page containing the attachment. * @param context the XWiki context. * @return the generated url. * @throws XWikiException error when retrieving document attachment. * @throws IOException error when retrieving document attachment. * @throws URISyntaxException when retrieving document attachment. */ private URL createAttachmentURL(String filename, String space, String name, String xwikidb, XWikiContext context) throws XWikiException, IOException, URISyntaxException { String db = (xwikidb == null ? context.getDatabase() : xwikidb); String path = "attachment/" + db + "." + space + "." + name + "." + filename; File file = new File(this.exportDir, path); if (!file.exists()) { XWikiDocument doc = context.getWiki().getDocument( db + XWikiDocument.DB_SPACE_SEP + space + XWikiDocument.SPACE_NAME_SEP + name, context); XWikiAttachment attachment = doc.getAttachment(filename); FileOutputStream fos = new FileOutputStream(file); IOUtils.copy(attachment.getContentInputStream(context), fos); fos.close(); } return new URI("file://" + path.replace(" ", "%20")).toURL(); }
/** * Tries to extract text indexable content from a generic attachment. * * @param attachment the attachment to extract the content from * @return the text representation of the attachment's content * @throws SolrIndexerException if problems occur */ protected String getContentAsText(XWikiAttachment attachment) { try { Metadata metadata = new Metadata(); metadata.set(TikaMetadataKeys.RESOURCE_NAME_KEY, attachment.getFilename()); InputStream in = attachment.getContentInputStream(this.xcontextProvider.get()); try { return TikaUtils.parseToString(in, metadata); } finally { in.close(); } } catch (Exception e) { this.logger.error("Failed to retrieve the content of attachment [{}]", attachment.getReference(), e); return null; } }
IOUtils.copy(attachment.getContentInputStream(context), fos); fos.close(); usedFiles.put(key, file);
boolean keepAspectRatio, float requestedQuality, XWikiContext context) throws Exception Image image = this.imageProcessor.readImage(attachment.getContentInputStream(context));
private String getContentAsText(XWikiDocument doc, XWikiContext context) { String contentText = null; try { XWikiAttachment att = doc.getAttachment(this.filename); LOGGER.debug("Start parsing attachement [{}] in document [{}]", this.filename, doc.getDocumentReference()); Tika tika = new Tika(); Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, this.filename); contentText = StringUtils.lowerCase(tika.parseToString(att.getContentInputStream(context), metadata)); } catch (Throwable ex) { LOGGER.warn("error getting content of attachment [{}] for document [{}]", new Object[] {this.filename, doc.getDocumentReference(), ex}); } return contentText; } }
if (!isZipFile(attachment.getContentInputStream(context))) { return attachment; ZipInputStream zis = new ZipInputStream(attachment.getContentInputStream(context)); ZipEntry entry;
if (StringUtils.endsWithIgnoreCase(attachment.getFilename(), ".vcf") && isCorrectVCF(attachment, eid, context)) { data.addBinaryBody(patient.getId() + ".vcf", attachment.getContentInputStream(context)); hasData = true;
stream = new BufferedInputStream(attachment.getContentInputStream(context));
} else { setupHeaders(response, mimetype, attachment.getDate(), attachment.getContentSize(context)); IOUtils.copy(attachment.getContentInputStream(context), response.getOutputStream());
String content = IOUtils.toString(attachment.getContentInputStream(context), DEFAULT_ENCODING); if (!StringUtils.isBlank(content)) {
Long size; try { content = attachment.getContentInputStream(xcontext); size = Long.valueOf(attachment.getFilesize()); } catch (XWikiException e) {
sourceImageInputStream = realAvatarAttachment.getContentInputStream(context);
IOUtils.copy(attachment.getContentInputStream(context), response.getOutputStream()); } catch (XWikiException e) { Object[] args = {filename};
IOUtils.copy(attachment.getContentInputStream(context), response.getOutputStream()); } catch (IOException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP,