try { msg.setContent(InputStream.class, ds.getInputStream()); AttachmentDeserializer deser = new AttachmentDeserializer(msg); deser.initializeAttachments(); } catch (IOException ex) { throw new Fault(ex);
public AttachmentImpl readNext() throws IOException { // Cache any mime parts that are currently being streamed cacheStreamedAttachments(); if (closed) { return null; } int v = stream.read(); if (v == -1) { return null; } stream.unread(v); Map<String, List<String>> headers = loadPartHeaders(stream); return (AttachmentImpl)createAttachment(headers); }
/** * Check for more attachments by attempting to deserialize the next attachment. * * @param shouldLoadNew if <i>false</i>, the "loaded attachments" List will not be changed. * @return there is more attachment or not * @throws IOException */ public boolean hasNext(boolean shouldLoadNew) throws IOException { if (shouldLoadNew) { Attachment a = deserializer.readNext(); if (a != null) { attachments.add(a); return true; } return false; } return deserializer.hasNext(); }
String boundaryString = findBoundaryFromContentType(contentType); if (null == boundaryString) { boundaryString = findBoundaryFromInputStream(); if (!readTillFirstBoundary(stream, boundary)) { throw new IOException("Couldn't find MIME boundary: " + boundaryString); Map<String, List<String>> ih = loadPartHeaders(stream); message.put(ATTACHMENT_PART_HEADERS, ih); String val = AttachmentUtil.getHeader(ih, "Content-Type", "; ");
String boundaryString = findBoundaryFromContentType(contentType); if (null == boundaryString) { boundaryString = findBoundaryFromInputStream(); if (!readTillFirstBoundary(stream, boundary)) { throw new IOException("Couldn't find MIME boundary: " + boundaryString);
deserializer.initializeAttachments();
public AttachmentImpl readNext() throws IOException { // Cache any mime parts that are currently being streamed cacheStreamedAttachments(); if (closed) { return null; } int v = stream.read(); if (v == -1) { return null; } stream.unread(v); InternetHeaders headers; try { headers = new InternetHeaders(stream); } catch (MessagingException e) { // TODO create custom IOException throw new RuntimeException(e); } return (AttachmentImpl)createAttachment(headers); }
@Override public void close() throws IOException { IOUtils.consume(is); is.close(); if (!isClosed && deserializer != null) { deserializer.markClosed(this); } isClosed = true; }
public void initializeAttachments() throws IOException { initializeRootMessage(); attachments = new LazyAttachmentCollection(this); message.setAttachments(attachments); }
/** * Check for more attachment. * * @return whether there is more attachment or not. It will not deserialize the next attachment. * @throws IOException */ public boolean hasNext() throws IOException { cacheStreamedAttachments(); if (closed) { return false; } int v = stream.read(); if (v == -1) { return false; } stream.unread(v); return true; }
private void cacheStreamedAttachments() throws IOException { if (body instanceof DelegatingInputStream && !((DelegatingInputStream) body).isClosed()) { cache((DelegatingInputStream) body, true); } List<Attachment> atts = new ArrayList<Attachment>(attachments.getLoadedAttachments()); for (Attachment a : atts) { DataSource s = a.getDataHandler().getDataSource(); if (s instanceof AttachmentDataSource) { AttachmentDataSource ads = (AttachmentDataSource)s; if (!ads.isCached()) { ads.cache(message); } } else if (s.getInputStream() instanceof DelegatingInputStream) { cache((DelegatingInputStream) s.getInputStream(), false); } else { //assume a normal stream that is already cached } } }
String boundaryString = findBoundaryFromContentType(contentType); if (null == boundaryString) { boundaryString = findBoundaryFromInputStream(); if (!readTillFirstBoundary(stream, boundary)) { throw new IOException("Couldn't find MIME boundary: " + boundaryString); Map<String, List<String>> ih = loadPartHeaders(stream); message.put(ATTACHMENT_PART_HEADERS, ih); String val = AttachmentUtil.getHeader(ih, "Content-Type", "; ");
String boundaryString = findBoundaryFromContentType(contentType); if (null == boundaryString) { boundaryString = findBoundaryFromInputStream(); if (!readTillFirstBoundary(stream, boundary)) { throw new IOException("Couldn't find MIME boundary: " + boundaryString);
public AttachmentImpl readNext() throws IOException { // Cache any mime parts that are currently being streamed cacheStreamedAttachments(); if (closed) { return null; } int v = stream.read(); if (v == -1) { return null; } stream.unread(v); InternetHeaders headers; try { headers = new InternetHeaders(stream); } catch (MessagingException e) { // TODO create custom IOException throw new RuntimeException(e); } return (AttachmentImpl)createAttachment(headers); }
@Override public void close() throws IOException { IOUtils.consume(is); is.close(); if (!isClosed && deserializer != null) { deserializer.markClosed(this); } isClosed = true; }
public void initializeAttachments() throws IOException { initializeRootMessage(); attachments = new LazyAttachmentCollection(this); message.setAttachments(attachments); }
/** * Check for more attachment. * * @return whether there is more attachment or not. It will not deserialize the next attachment. * @throws IOException */ public boolean hasNext() throws IOException { cacheStreamedAttachments(); if (closed) { return false; } int v = stream.read(); if (v == -1) { return false; } stream.unread(v); return true; }
private void cacheStreamedAttachments() throws IOException { if (body instanceof DelegatingInputStream && !((DelegatingInputStream) body).isClosed()) { cache((DelegatingInputStream) body); } List<Attachment> atts = new ArrayList<>(attachments.getLoadedAttachments()); for (Attachment a : atts) { DataSource s = a.getDataHandler().getDataSource(); if (s instanceof AttachmentDataSource) { AttachmentDataSource ads = (AttachmentDataSource)s; if (!ads.isCached()) { ads.cache(message); } } else if (s.getInputStream() instanceof DelegatingInputStream) { cache((DelegatingInputStream) s.getInputStream()); } else { //assume a normal stream that is already cached } } }
public void handleMessage(Message message) { if (isGET(message)) { LOG.fine("AttachmentInInterceptor skipped in HTTP GET method"); return; } if (message.getContent(InputStream.class) == null) { return; } String contentType = (String) message.get(Message.CONTENT_TYPE); if (AttachmentUtil.isTypeSupported(contentType, getSupportedTypes())) { AttachmentDeserializer ad = new AttachmentDeserializer(message, getSupportedTypes()); try { ad.initializeAttachments(); } catch (IOException e) { throw new Fault(e); } } }
/** * Check for more attachments by attempting to deserialize the next attachment. * * @param shouldLoadNew if <i>false</i>, the "loaded attachments" List will not be changed. * @return there is more attachment or not * @throws IOException */ public boolean hasNext(boolean shouldLoadNew) throws IOException { if (shouldLoadNew) { Attachment a = deserializer.readNext(); if (a != null) { attachments.add(a); return true; } return false; } return deserializer.hasNext(); }