jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/org/jvnet/mimepull/MIMEPart.java
--- a/jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/org/jvnet/mimepull/MIMEPart.java Thu Apr 09 06:40:17 2015 -0700
+++ b/jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/org/jvnet/mimepull/MIMEPart.java Fri Apr 10 14:54:20 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
package com.sun.xml.internal.org.jvnet.mimepull;
+import java.io.Closeable;
import java.io.File;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -42,10 +43,11 @@
*
* @author Jitendra Kotamraju, Martin Grebac
*/
-public class MIMEPart {
+public class MIMEPart implements Closeable {
private static final Logger LOGGER = Logger.getLogger(MIMEPart.class.getName());
+ private volatile boolean closed;
private volatile InternetHeaders headers;
private volatile String contentId;
private String contentType;
@@ -55,6 +57,8 @@
final MIMEMessage msg;
private final DataHead dataHead;
+ private final Object lock = new Object();
+
MIMEPart(MIMEMessage msg) {
this.msg = msg;
this.dataHead = new DataHead(this);
@@ -91,8 +95,16 @@
* the temp file that is used to serve this part's content). After
* calling this, one shouldn't call {@link #read()} or {@link #readOnce()}
*/
+ @Override
public void close() {
- dataHead.close();
+ if (!closed) {
+ synchronized (lock) {
+ if (!closed) {
+ dataHead.close();
+ closed = true;
+ }
+ }
+ }
}
/**
@@ -242,6 +254,15 @@
this.contentTransferEncoding = cte;
}
+ /**
+ * Return {@code true} if this part has already been closed, {@code false} otherwise.
+ *
+ * @return {@code true} if this part has already been closed, {@code false} otherwise.
+ */
+ public boolean isClosed() {
+ return closed;
+ }
+
@Override
public String toString() {
return "Part="+contentId+":"+contentTransferEncoding;