< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/internet/InternetHeaders.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, 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

@@ -71,16 +71,16 @@
  * @author Bill Shannon
  * @see MimeUtility
  */
 public final class InternetHeaders {
 
-    private final FinalArrayList headers = new FinalArrayList();
+    private final FinalArrayList<hdr> headers = new FinalArrayList<hdr>();
 
     /**
      * Lazily cerated view of header lines (Strings).
      */
-    private List headerValueView;
+    private List<String> headerValueView;
 
     /**
      * Create an empty InternetHeaders object.
      */
     public InternetHeaders() {

@@ -117,11 +117,11 @@
         // to have BodyParts with no header lines.
         String line;
         LineInputStream lis = new LineInputStream(is);
         String prevline = null; // the previous header line, as a string
         // a buffer to accumulate the header in, when we know it's needed
-        StringBuffer lineBuffer = new StringBuffer();
+        StringBuilder lineBuffer = new StringBuilder();
 
         try {
             //while ((line = lis.readLine()) != null) {
             do {
                 line = lis.readLine();

@@ -159,23 +159,23 @@
      * @param   name header name
      * @return          array of header values, or null if none
      */
     public String[] getHeader(String name) {
         // XXX - should we just step through in index order?
-        FinalArrayList v = new FinalArrayList(); // accumulate return values
+        FinalArrayList<String> v = new FinalArrayList<String>(); // accumulate return values
 
         int len = headers.size();
         for( int i=0; i<len; i++ ) {
-            hdr h = (hdr) headers.get(i);
+            hdr h = headers.get(i);
             if (name.equalsIgnoreCase(h.name)) {
                 v.add(h.getValue());
             }
         }
         if (v.size() == 0)
             return (null);
         // convert Vector to an array for return
-        return (String[]) v.toArray(new String[v.size()]);
+        return v.toArray(new String[v.size()]);
     }
 
     /**
      * Get all the headers for this header name, returned as a single
      * String, with headers separated by the delimiter. If the

@@ -195,11 +195,11 @@
             return null;
 
         if ((s.length == 1) || delimiter == null)
             return s[0];
 
-        StringBuffer r = new StringBuffer(s[0]);
+        StringBuilder r = new StringBuilder(s[0]);
         for (int i = 1; i < s.length; i++) {
             r.append(delimiter);
             r.append(s[i]);
         }
         return r.toString();

@@ -217,11 +217,11 @@
      */
     public void setHeader(String name, String value) {
         boolean found = false;
 
         for (int i = 0; i < headers.size(); i++) {
-            hdr h = (hdr) headers.get(i);
+            hdr h = headers.get(i);
             if (name.equalsIgnoreCase(h.name)) {
                 if (!found) {
                     int j;
                     if (h.line != null && (j = h.line.indexOf(':')) >= 0) {
                         h.line = h.line.substring(0, j + 1) + " " + value;

@@ -250,11 +250,11 @@
      * @param   value   header value
      */
     public void addHeader(String name, String value) {
         int pos = headers.size();
         for (int i = headers.size() - 1; i >= 0; i--) {
-            hdr h = (hdr) headers.get(i);
+            hdr h = headers.get(i);
             if (name.equalsIgnoreCase(h.name)) {
                 headers.add(i + 1, new hdr(name, value));
                 return;
             }
             // marker for default place to add new headers

@@ -269,11 +269,11 @@
      *
      * @param   name header name
      */
     public void removeHeader(String name) {
         for (int i = 0; i < headers.size(); i++) {
-            hdr h = (hdr) headers.get(i);
+            hdr h = headers.get(i);
             if (name.equalsIgnoreCase(h.name)) {
                 headers.remove(i);
                 i--;    // have to look at i again
             }
         }

@@ -283,11 +283,11 @@
      * Return all the headers as an Enumeration of
      * {@link Header} objects.
      *
      * @return  Header objects
      */
-    public FinalArrayList getAllHeaders() {
+    public FinalArrayList<hdr> getAllHeaders() {
         return headers; // conceptually it should be read-only, but for performance reason I'm not wrapping it here
     }
 
     /**
      * Add an RFC822 header line to the header store.

@@ -300,11 +300,11 @@
      */
     public void addHeaderLine(String line) {
         try {
             char c = line.charAt(0);
             if (c == ' ' || c == '\t') {
-                hdr h = (hdr) headers.get(headers.size() - 1);
+                hdr h = headers.get(headers.size() - 1);
                 h.line += "\r\n" + line;
             } else
                 headers.add(new hdr(line));
         } catch (StringIndexOutOfBoundsException e) {
             // line is empty, ignore it

@@ -315,15 +315,15 @@
     }
 
     /**
      * Return all the header lines as a collection
      */
-    public List getAllHeaderLines() {
+    public List<String> getAllHeaderLines() {
         if(headerValueView==null)
-            headerValueView = new AbstractList() {
-                public Object get(int index) {
-                    return ((hdr)headers.get(index)).line;
+            headerValueView = new AbstractList<String>() {
+                public String get(int index) {
+                    return headers.get(index).line;
                 }
 
                 public int size() {
                     return headers.size();
                 }
< prev index next >