1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
688 gss[l - 1] = 1;
689 }
690
691
692 /**
693 * Iterates through all the parts and outputs each Mime part
694 * separated by a boundary.
695 */
696
697 public void writeTo(OutputStream os)
698 throws IOException, MessagingException {
699
700 // inputStream was not null
701 if (in != null) {
702 contentType.setParameter("boundary", this.boundary);
703 }
704
705 String bnd = "--" + contentType.getParameter("boundary");
706 for (int i = 0; i < parts.size(); i++) {
707 OutputUtil.writeln(bnd, os); // put out boundary
708 ((MimeBodyPart)parts.get(i)).writeTo(os);
709 OutputUtil.writeln(os); // put out empty line
710 }
711
712 if (in != null) {
713 OutputUtil.writeln(bnd, os); // put out boundary
714 if ((os instanceof ByteOutputStream) && lazyAttachments) {
715 ((ByteOutputStream) os).write(in);
716 } else {
717 ByteOutputStream baos = null;
718 try {
719 baos = new ByteOutputStream(in.available());
720 baos.write(in);
721 baos.writeTo(os);
722 // reset the inputstream so that we can support a
723 // getAttachment later
724 in = baos.newInputStream();
725 } finally {
726 if (baos != null)
727 baos.close();
728 }
|
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
688 gss[l - 1] = 1;
689 }
690
691
692 /**
693 * Iterates through all the parts and outputs each Mime part
694 * separated by a boundary.
695 */
696
697 public void writeTo(OutputStream os)
698 throws IOException, MessagingException {
699
700 // inputStream was not null
701 if (in != null) {
702 contentType.setParameter("boundary", this.boundary);
703 }
704
705 String bnd = "--" + contentType.getParameter("boundary");
706 for (int i = 0; i < parts.size(); i++) {
707 OutputUtil.writeln(bnd, os); // put out boundary
708 parts.get(i).writeTo(os);
709 OutputUtil.writeln(os); // put out empty line
710 }
711
712 if (in != null) {
713 OutputUtil.writeln(bnd, os); // put out boundary
714 if ((os instanceof ByteOutputStream) && lazyAttachments) {
715 ((ByteOutputStream) os).write(in);
716 } else {
717 ByteOutputStream baos = null;
718 try {
719 baos = new ByteOutputStream(in.available());
720 baos.write(in);
721 baos.writeTo(os);
722 // reset the inputstream so that we can support a
723 // getAttachment later
724 in = baos.newInputStream();
725 } finally {
726 if (baos != null)
727 baos.close();
728 }
|