KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > attachments > DimeMultiPart


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 /**
18  * @author Rick Rineholt
19  */

20
21 package org.apache.axis.attachments;
22
23
24
25
26
27 /**
28  * This class hold all parts of a DIME multipart message.
29  */

30
31 public final class DimeMultiPart {
32     static final long transSize = Integer.MAX_VALUE;
33     static final byte CURRENT_VERSION = 1; //Anything above this we don't support.
34
protected java.util.Vector JavaDoc parts = new java.util.Vector JavaDoc();
35     public DimeMultiPart() {}
36     public void addBodyPart(DimeBodyPart part) {
37         parts.add(part);
38     }
39
40     public void write(java.io.OutputStream JavaDoc os)
41        throws java.io.IOException JavaDoc {
42         int size = parts.size();
43         int last = size - 1;
44
45         for (int i = 0; i < size; ++i)
46             ((DimeBodyPart) parts.elementAt(i)).write(os,
47                 (byte) ((i == 0 ? DimeBodyPart.POSITION_FIRST :
48                  (byte) 0)
49                     | (i == last ? DimeBodyPart.POSITION_LAST :
50                      (byte) 0)), transSize);
51     }
52
53     public long getTransmissionSize() {
54         long size = 0;
55
56         for (int i = parts.size() - 1; i > -1; --i)
57             size +=
58             ((DimeBodyPart) parts.elementAt(i)).getTransmissionSize(
59               transSize);
60
61         return size;
62     }
63 }
64
Popular Tags