/** * 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(); }
return ((SingleBody) body).copy();
body = MultipartBuilder.createCopy((Multipart) otherBody).build(); } else if (otherBody instanceof SingleBody) { body = ((SingleBody) otherBody).copy();
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; }