1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.xml.internal.org.jvnet.mimepull; |
26 package com.sun.xml.internal.org.jvnet.mimepull; |
27 |
27 |
|
28 import java.io.Closeable; |
28 import java.io.File; |
29 import java.io.File; |
29 import java.io.InputStream; |
30 import java.io.InputStream; |
30 import java.nio.ByteBuffer; |
31 import java.nio.ByteBuffer; |
31 import java.util.List; |
32 import java.util.List; |
32 import java.util.logging.Level; |
33 import java.util.logging.Level; |
40 * on some other attachment parts. All this happens behind the scenes so the |
41 * on some other attachment parts. All this happens behind the scenes so the |
41 * application developer need not worry about these details. |
42 * application developer need not worry about these details. |
42 * |
43 * |
43 * @author Jitendra Kotamraju, Martin Grebac |
44 * @author Jitendra Kotamraju, Martin Grebac |
44 */ |
45 */ |
45 public class MIMEPart { |
46 public class MIMEPart implements Closeable { |
46 |
47 |
47 private static final Logger LOGGER = Logger.getLogger(MIMEPart.class.getName()); |
48 private static final Logger LOGGER = Logger.getLogger(MIMEPart.class.getName()); |
48 |
49 |
|
50 private volatile boolean closed; |
49 private volatile InternetHeaders headers; |
51 private volatile InternetHeaders headers; |
50 private volatile String contentId; |
52 private volatile String contentId; |
51 private String contentType; |
53 private String contentType; |
52 private String contentTransferEncoding; |
54 private String contentTransferEncoding; |
53 |
55 |
54 volatile boolean parsed; // part is parsed or not |
56 volatile boolean parsed; // part is parsed or not |
55 final MIMEMessage msg; |
57 final MIMEMessage msg; |
56 private final DataHead dataHead; |
58 private final DataHead dataHead; |
|
59 |
|
60 private final Object lock = new Object(); |
57 |
61 |
58 MIMEPart(MIMEMessage msg) { |
62 MIMEPart(MIMEMessage msg) { |
59 this.msg = msg; |
63 this.msg = msg; |
60 this.dataHead = new DataHead(this); |
64 this.dataHead = new DataHead(this); |
61 } |
65 } |
89 /** |
93 /** |
90 * Cleans up any resources that are held by this part (for e.g. deletes |
94 * Cleans up any resources that are held by this part (for e.g. deletes |
91 * the temp file that is used to serve this part's content). After |
95 * the temp file that is used to serve this part's content). After |
92 * calling this, one shouldn't call {@link #read()} or {@link #readOnce()} |
96 * calling this, one shouldn't call {@link #read()} or {@link #readOnce()} |
93 */ |
97 */ |
|
98 @Override |
94 public void close() { |
99 public void close() { |
95 dataHead.close(); |
100 if (!closed) { |
|
101 synchronized (lock) { |
|
102 if (!closed) { |
|
103 dataHead.close(); |
|
104 closed = true; |
|
105 } |
|
106 } |
|
107 } |
96 } |
108 } |
97 |
109 |
98 /** |
110 /** |
99 * Can get the attachment part's content only once. The content |
111 * Can get the attachment part's content only once. The content |
100 * will be lost after the method. Content data is not be stored |
112 * will be lost after the method. Content data is not be stored |
240 */ |
252 */ |
241 void setContentTransferEncoding(String cte) { |
253 void setContentTransferEncoding(String cte) { |
242 this.contentTransferEncoding = cte; |
254 this.contentTransferEncoding = cte; |
243 } |
255 } |
244 |
256 |
|
257 /** |
|
258 * Return {@code true} if this part has already been closed, {@code false} otherwise. |
|
259 * |
|
260 * @return {@code true} if this part has already been closed, {@code false} otherwise. |
|
261 */ |
|
262 public boolean isClosed() { |
|
263 return closed; |
|
264 } |
|
265 |
245 @Override |
266 @Override |
246 public String toString() { |
267 public String toString() { |
247 return "Part="+contentId+":"+contentTransferEncoding; |
268 return "Part="+contentId+":"+contentTransferEncoding; |
248 } |
269 } |
249 |
270 |