/** * Writes this single body to the given stream. The default implementation copies * the input stream obtained by {@link #getInputStream()} to the specified output * stream. May be overwritten by a subclass to improve performance. * * @param out * the stream to write to. * @throws IOException * in case of an I/O error */ public void writeTo(OutputStream out) throws IOException { if (out == null) throw new IllegalArgumentException(); InputStream in = getInputStream(); SingleBody.copy(in, out); in.close(); }
body.writeTo(os); byte[] fileBytes = os.toByteArray(); return fileBytes;
public InputStream getBodyInputStream() { try { return ((SingleBody) message.getBody()).getInputStream(); } catch (IOException e) { return null; } }
return ((SingleBody) body).copy();
public SingleBodyBuilder copy(final SingleBody other) throws IOException { if (other == null) { return this; } if (other instanceof TextBody) { String charsetName = ((TextBody) other).getMimeCharset(); if (charsetName != null) { try { this.charset = Charset.forName(charsetName); } catch (IllegalCharsetNameException ex) { throw new UnsupportedEncodingException(charsetName); } catch (UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(charsetName); } } } this.bin = ContentUtil.buffer(other.getInputStream()); return this; }
body = MultipartBuilder.createCopy((Multipart) otherBody).build(); } else if (otherBody instanceof SingleBody) { body = ((SingleBody) otherBody).copy();
private Optional<MDNReport> parseReport(Entity report) { LOGGER.debug("Parsing report"); try { return new MDNReportParser().parse(((SingleBody)report.getBody()).getInputStream(), report.getCharset()); } catch (IOException e) { LOGGER.error("unable to parse MESSAGE_DISPOSITION_NOTIFICATION part", e); return Optional.empty(); } }
/** * Write the specified <code>Body</code> to the specified * <code>OutputStream</code>. * * @param body * the <code>Body</code> to write. * @param out * the OutputStream to write to. * @throws IOException * if an I/O error occurs. */ public void writeBody(Body body, OutputStream out) throws IOException { if (body instanceof Message) { writeEntity((Message) body, out); } else if (body instanceof Multipart) { writeMultipart((Multipart) body, out); } else if (body instanceof SingleBody) { ((SingleBody) body).writeTo(out); } else throw new IllegalArgumentException("Unsupported body class"); }
public Builder copy(Message other) { if (other == null) { return this; } clearFields(); final Header otherHeader = other.getHeader(); if (otherHeader != null) { final List<Field> otherFields = otherHeader.getFields(); for (Field field: otherFields) { addField(field); } } Body body = null; Body otherBody = other.getBody(); if (otherBody instanceof Message) { body = Builder.of((Message) otherBody).build(); } else if (otherBody instanceof Multipart) { body = MultipartBuilder.createCopy((Multipart) otherBody).build(); } else if (otherBody instanceof SingleBody) { body = ((SingleBody) otherBody).copy(); } setBody(body); return this; }