public static String detectFilename(MultivaluedMap<String, String> httpHeaders) { String disposition = httpHeaders.getFirst("Content-Disposition"); if (disposition != null) { ContentDisposition c = new ContentDisposition(disposition); // only support "attachment" dispositions if ("attachment".equals(c.getType())) { String fn = c.getParameter("filename"); if (fn != null) { return fn; } } } // this really should not be used, since it's not an official field return httpHeaders.getFirst("File-Name"); }
private String findBoundary(String ct) { int idx = ct.indexOf("boundary="); if (idx == -1) { return AttachmentUtil.getUniqueBoundaryValue(); } ct = ct.substring(idx + 9); if (ct.charAt(0) == '"') { ct = ct.substring(1); idx = ct.indexOf('"'); return ct.substring(0, idx); } idx = ct.indexOf(';'); if (idx == -1) { return ct; } return ct.substring(0, idx); } }
public Attachment next() { Map.Entry<String, DataHandler> e = iterator.next(); key = e.getKey(); Attachment o = cache.get(key); if (o == null) { o = new AttachmentImpl(key, e.getValue()); cache.put(key, o); } return o; }
ct = "application/octet-stream"; dh = new DataHandler(new ByteDataSource((byte[])o, ct)); } else if (o instanceof String) { if (ct == null) { ct = "text/plain; charset=\'UTF-8\'"; dh = new DataHandler(new ByteDataSource(((String)o).getBytes(StandardCharsets.UTF_8), ct)); } else { throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", AttachmentImpl att = new AttachmentImpl(id); att.setDataHandler(dh); att.setHeader("Content-Type", ct); att.setHeader("Content-ID", "<" + id + ">"); atts.add(att);
public DataHandler put(String key, DataHandler value) { Attachment at = new AttachmentImpl(key, value); collection.add(at); return value; }
@Override protected Attachment createAttachment(Object object, String id) { DataHandler handler = (DataHandler)object; AttachmentImpl att = new AttachmentImpl(id, handler); att.setXOP(true); return att; }
/** * Create an Attachment from the MIME stream. If there is a previous attachment * that is not read, cache that attachment. * * @throws IOException */ private Attachment createAttachment(Map<String, List<String>> headers) throws IOException { InputStream partStream = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT), this); createCount++; return AttachmentUtil.createAttachment(partStream, headers); }
try { msg.setContent(InputStream.class, ds.getInputStream()); AttachmentDeserializer deser = new AttachmentDeserializer(msg); deser.initializeAttachments(); } catch (IOException ex) { throw new Fault(ex);
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) { IOUtils.copy(src.getInputStream(), bos, 1024); ds = new ByteDataSource(bos.toByteArray(), ct); ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8), ct); StaxUtils.copy(o, writer); writer.flush(); ds = new ByteDataSource(bwriter.toByteArray(), ct); } catch (XMLStreamException e1) { throw new Fault(e1);
public void initializeAttachments() throws IOException { initializeRootMessage(); attachments = new LazyAttachmentCollection(this); message.setAttachments(attachments); }
if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { try { ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage); } catch (IOException e) { throw new Fault(e);
@Test public void testJAXBAndActivationDependency() { //TIKA-2778 AttachmentUtil.getCommandMap(); }
private Object createAttachments(Map<String, Object> mc, String propertyName) { if (mc == null) { return null; } Collection<Attachment> attachments = CastUtils.cast((Collection<?>)mc.get(Message.ATTACHMENTS)); Map<String, DataHandler> dataHandlers; if (attachments instanceof WrappedAttachments) { dataHandlers = ((WrappedAttachments) attachments).getAttachments(); } else { if (attachments == null) { attachments = new ArrayList<>(); mc.put(Message.ATTACHMENTS, attachments); } dataHandlers = AttachmentUtil.getDHMap(attachments); mc.put(propertyName, dataHandlers); scopes.put(propertyName, Scope.APPLICATION); } return dataHandlers; }
public DataHandler put(String key, DataHandler value) { Attachment at = new AttachmentImpl(key, value); collection.add(at); return value; }
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a) { T[] copy = a.length == attachments.size() ? a : (T[])Array.newInstance(a.getClass().getComponentType(), attachments.size()); int i = 0; for (Map.Entry<String, DataHandler> entry : attachments.entrySet()) { Attachment o = cache.get(entry.getKey()); if (o == null) { o = new AttachmentImpl(entry.getKey(), entry.getValue()); cache.put(entry.getKey(), o); } copy[i++] = (T)o; } return copy; }
/** * Create an Attachment from the MIME stream. If there is a previous attachment * that is not read, cache that attachment. * * @throws IOException */ private Attachment createAttachment(Map<String, List<String>> headers) throws IOException { InputStream partStream = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT), this); createCount++; return AttachmentUtil.createAttachment(partStream, headers); }
public DataHandler put(String key, DataHandler value) { Attachment at = new AttachmentImpl(key, value); collection.add(at); return value; }
/** * Create an Attachment from the MIME stream. If there is a previous attachment * that is not read, cache that attachment. * * @return * @throws IOException */ private Attachment createAttachment(InternetHeaders headers) throws IOException { InputStream partStream = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount), this); createCount++; return AttachmentUtil.createAttachment(partStream, headers); }
public DataHandler put(String key, DataHandler value) { Attachment at = new AttachmentImpl(key, value); collection.add(at); return value; }
/** * Create an Attachment from the MIME stream. If there is a previous attachment * that is not read, cache that attachment. * * @return * @throws IOException */ private Attachment createAttachment(InternetHeaders headers) throws IOException { InputStream partStream = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount), this); createCount++; return AttachmentUtil.createAttachment(partStream, headers); }