src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/mimepull/DataHead.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -31,11 +31,11 @@
 /**
  * Represents an attachment part in a MIME message. MIME message parsing is done
  * lazily using a pull parser, so the part may not have all the data. {@link #read}
  * and {@link #readOnce} may trigger the actual parsing the message. In fact,
  * parsing of an attachment part may be triggered by calling {@link #read} methods
- * on some other attachemnt parts. All this happens behind the scenes so the
+ * on some other attachment parts. All this happens behind the scenes so the
  * application developer need not worry about these details.
  *
  * @author Jitendra Kotamraju
  */
 final class DataHead {

@@ -82,17 +82,22 @@
         if (dataFile != null) {
             dataFile.renameTo(f);
         } else {
             try {
                 OutputStream os = new FileOutputStream(f);
+                try {
                 InputStream in = readOnce();
                 byte[] buf = new byte[8192];
                 int len;
                 while((len=in.read(buf)) != -1) {
                     os.write(buf, 0, len);
                 }
+                } finally {
+                    if (os != null) {
                 os.close();
+                    }
+                }
             } catch(IOException ioe) {
                 throw new MIMEParsingException(ioe);
             }
         }
     }

@@ -139,10 +144,11 @@
      * <p>
      * Calling this method also marks the stream as 'consumed'
      *
      * @return true if readOnce() is not called before
      */
+    @SuppressWarnings("ThrowableInitCause")
     private boolean unconsumed() {
         if (consumedAt != null) {
             AssertionError error = new AssertionError("readOnce() is already called before. See the nested exception from where it's called.");
             error.initCause(consumedAt);
             throw error;

@@ -193,18 +199,21 @@
             buf = current.data.read();
         }
 
         @Override
         public int read(byte b[], int off, int sz) throws IOException {
-            if(!fetch())    return -1;
+            if (!fetch()) {
+                return -1;
+            }
 
             sz = Math.min(sz, len-offset);
             System.arraycopy(buf,offset,b,off,sz);
             offset += sz;
             return sz;
         }
 
+        @Override
         public int read() throws IOException {
             if (!fetch()) {
                 return -1;
             }
             return (buf[offset++] & 0xff);

@@ -242,10 +251,11 @@
                 this.len = current.data.size();
             }
             return true;
         }
 
+        @Override
         public void close() throws IOException {
             super.close();
             current = null;
             closed = true;
         }