public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
/** * Return an InputStream for the data. * Note that a new stream is returned each time * this method is called. * * @return the InputStream * @exception IOException if no data has been set */ public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("no data"); if (len < 0) len = data.length; return new SharedByteArrayInputStream(data, 0, len); }
/** * Return an InputStream for the data. * Note that a new stream is returned each time * this method is called. * * @return the InputStream * @exception IOException if no data has been set */ @Override public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("no data"); if (len < 0) len = data.length; return new SharedByteArrayInputStream(data, 0, len); }
/** * Return a new InputStream representing a subset of the data * from this InputStream, starting at <code>start</code> (inclusive) * up to <code>end</code> (exclusive). <code>start</code> must be * non-negative. If <code>end</code> is -1, the new stream ends * at the same place as this stream. The returned InputStream * will also implement the SharedInputStream interface. * * @param start the starting position * @param end the ending position + 1 * @return the new stream */ public InputStream newStream(long start, long end) { if (start < 0) throw new IllegalArgumentException("start < 0"); if (end == -1) end = count - this.start; return new SharedByteArrayInputStream(buf, this.start + (int)start, (int)(end - start)); } }
/** * Return a new InputStream representing a subset of the data * from this InputStream, starting at <code>start</code> (inclusive) * up to <code>end</code> (exclusive). <code>start</code> must be * non-negative. If <code>end</code> is -1, the new stream ends * at the same place as this stream. The returned InputStream * will also implement the SharedInputStream interface. * * @param start the starting position * @param end the ending position + 1 * @return the new stream */ @Override public InputStream newStream(long start, long end) { if (start < 0) throw new IllegalArgumentException("start < 0"); if (end == -1) end = count - this.start; return new SharedByteArrayInputStream(buf, this.start + (int)start, (int)(end - start)); } }
/** * Produce the raw bytes of the content. This method is used during * parsing, to create a DataHandler object for the content. Subclasses * that can provide a separate input stream for just the message * content might want to override this method. <p> * * This implementation returns a SharedInputStream, if * <code>contentStream</code> is not null. Otherwise, it * returns a ByteArrayInputStream constructed * out of the <code>content</code> byte array. * * @return an InputStream containing the raw bytes * @exception MessagingException for failures * @see #content */ protected InputStream getContentStream() throws MessagingException { if (contentStream != null) return ((SharedInputStream)contentStream).newStream(0, -1); if (content != null) return new SharedByteArrayInputStream(content); throw new MessagingException("No MimeMessage content"); }
/** * Produce the raw bytes of the content. This method is used during * parsing, to create a DataHandler object for the content. Subclasses * that can provide a separate input stream for just the message * content might want to override this method. <p> * * This implementation returns a SharedInputStream, if * <code>contentStream</code> is not null. Otherwise, it * returns a ByteArrayInputStream constructed * out of the <code>content</code> byte array. * * @return an InputStream containing the raw bytes * @exception MessagingException for failures * @see #content */ protected InputStream getContentStream() throws MessagingException { if (contentStream != null) return ((SharedInputStream)contentStream).newStream(0, -1); if (content != null) return new SharedByteArrayInputStream(content); throw new MessagingException("No MimeMessage content"); }
bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close();
bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close();
public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
public static SharedByteArrayInputStream getSystemResourceAsSharedStream(String filename) { return new SharedByteArrayInputStream(getSystemResourceAsByteArray(filename)); } }
/** * Send message. * * @param messageBody MIME message body * @throws IOException on error */ public void sendMessage(byte[] messageBody) throws IOException { try { sendMessage(new MimeMessage(null, new SharedByteArrayInputStream(messageBody))); } catch (MessagingException e) { throw new IOException(e.getMessage()); } }
public static SharedByteArrayInputStream getSystemResourceAsSharedStream(String filename) { return new SharedByteArrayInputStream(getSystemResourceAsByteArray(filename)); } }
public MimeMessageObjectMessageSource(ObjectMessage message) throws JMSException { this.message = message; this.id = message.getJMSMessageID(); this.content = (byte[]) message.getObject(); in = new SharedByteArrayInputStream(content); }
private static SharedByteArrayInputStream copyFullContent(MailboxMessage original) throws MailboxException { try { return new SharedByteArrayInputStream(IOUtils.toByteArray(original.getFullContent())); } catch (IOException e) { throw new MailboxException("Unable to parse message", e); } }
/** * Create a copy of the given message */ public JPAStreamingMailboxMessage(JPAMailbox mailbox, MessageUid uid, long modSeq, MailboxMessage message) throws MailboxException { super(mailbox, uid, modSeq, message); try { this.content = new SharedByteArrayInputStream(IOUtils.toByteArray(message.getFullContent())); this.header = getHeaderContent(); this.body = getBodyContent(); } catch (IOException e) { throw new MailboxException("Unable to parse message",e); } }
private SimpleMailboxMessage createMessage(MailboxId mailboxId) { int size = 45; int bodyStartOctet = 25; byte[] content = "Subject: test\r\n\r\nBody\r\n".getBytes(StandardCharsets.UTF_8); return new SimpleMailboxMessage(TestMessageId.of(58), new Date(), size, bodyStartOctet, new SharedByteArrayInputStream(content), new Flags(), new PropertyBuilder(), mailboxId); } }
private SimpleMailboxMessage createMessage(MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder, Collection<MessageAttachment> attachments) { return SimpleMailboxMessage.builder() .messageId(messageId) .mailboxId(MAILBOX_ID) .uid(messageUid) .internalDate(new Date()) .bodyStartOctet(bodyStart) .size(content.length()) .content(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) .flags(new Flags()) .propertyBuilder(propertyBuilder) .addAttachments(attachments) .build(); }