/** * Constructor that takes an InputStream containing the contents * of the set of mail headers. * * @param in the InputStream containing the header data * * @throws MessagingException if the super class cannot be properly instantiated * based on the stream */ public MailHeaders(InputStream in) throws MessagingException { super(); load(in); }
MailHeaders newHeaders = new MailHeaders(is);
/** * Generate a representation of the headers as a series of bytes. * * @return the byte array containing the headers */ public byte[] toByteArray() throws MessagingException{ ByteArrayOutputStream headersBytes = new ByteArrayOutputStream(); writeTo(headersBytes); return headersBytes.toByteArray(); }
/** * Write the headers to an output stream * * @param out the OutputStream to which to write the headers */ public void writeTo(OutputStream out) throws MessagingException{ MimeMessageUtil.writeHeadersTo(getAllHeaderLines(), out); }
/** * @see javax.mail.internet.MimeMessage#getRawInputStream() */ public InputStream getRawInputStream() throws MessagingException { if (!messageParsed && !isModified() && source != null) { InputStream is; try { is = source.getInputStream(); // skip the headers. new MailHeaders(is); return is; } catch (IOException e) { throw new MessagingException("Unable to read the stream: " + e.getMessage(), e); } } else return super.getRawInputStream(); }