< 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 ****
/*
! * Copyright (c) 1997, 2013, 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
--- 1,7 ----
/*
! * 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,86 ****
* @author Bill Shannon
* @see MimeUtility
*/
public final class InternetHeaders {
! private final FinalArrayList headers = new FinalArrayList();
/**
* Lazily cerated view of header lines (Strings).
*/
! private List headerValueView;
/**
* Create an empty InternetHeaders object.
*/
public InternetHeaders() {
--- 71,86 ----
* @author Bill Shannon
* @see MimeUtility
*/
public final class InternetHeaders {
! private final FinalArrayList<hdr> headers = new FinalArrayList<hdr>();
/**
* Lazily cerated view of header lines (Strings).
*/
! private List<String> headerValueView;
/**
* Create an empty InternetHeaders object.
*/
public InternetHeaders() {
*** 117,127 ****
// 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();
try {
//while ((line = lis.readLine()) != null) {
do {
line = lis.readLine();
--- 117,127 ----
// 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
! StringBuilder lineBuffer = new StringBuilder();
try {
//while ((line = lis.readLine()) != null) {
do {
line = lis.readLine();
*** 159,181 ****
* @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
int len = headers.size();
for( int i=0; i<len; i++ ) {
! hdr h = (hdr) 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()]);
}
/**
* Get all the headers for this header name, returned as a single
* String, with headers separated by the delimiter. If the
--- 159,181 ----
* @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<String> v = new FinalArrayList<String>(); // accumulate return values
int len = headers.size();
for( int i=0; i<len; 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 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,205 ****
return null;
if ((s.length == 1) || delimiter == null)
return s[0];
! StringBuffer r = new StringBuffer(s[0]);
for (int i = 1; i < s.length; i++) {
r.append(delimiter);
r.append(s[i]);
}
return r.toString();
--- 195,205 ----
return null;
if ((s.length == 1) || delimiter == null)
return 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,227 ****
*/
public void setHeader(String name, String value) {
boolean found = false;
for (int i = 0; i < headers.size(); i++) {
! hdr h = (hdr) 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;
--- 217,227 ----
*/
public void setHeader(String name, String value) {
boolean found = false;
for (int i = 0; i < headers.size(); 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,260 ****
* @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);
if (name.equalsIgnoreCase(h.name)) {
headers.add(i + 1, new hdr(name, value));
return;
}
// marker for default place to add new headers
--- 250,260 ----
* @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 = 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,279 ****
*
* @param name header name
*/
public void removeHeader(String name) {
for (int i = 0; i < headers.size(); i++) {
! hdr h = (hdr) headers.get(i);
if (name.equalsIgnoreCase(h.name)) {
headers.remove(i);
i--; // have to look at i again
}
}
--- 269,279 ----
*
* @param name header name
*/
public void removeHeader(String name) {
for (int i = 0; i < headers.size(); i++) {
! hdr h = headers.get(i);
if (name.equalsIgnoreCase(h.name)) {
headers.remove(i);
i--; // have to look at i again
}
}
*** 283,293 ****
* Return all the headers as an Enumeration of
* {@link Header} objects.
*
* @return Header objects
*/
! public FinalArrayList 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.
--- 283,293 ----
* Return all the headers as an Enumeration of
* {@link Header} objects.
*
* @return Header objects
*/
! 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,310 ****
*/
public void addHeaderLine(String line) {
try {
char c = line.charAt(0);
if (c == ' ' || c == '\t') {
! hdr h = (hdr) headers.get(headers.size() - 1);
h.line += "\r\n" + line;
} else
headers.add(new hdr(line));
} catch (StringIndexOutOfBoundsException e) {
// line is empty, ignore it
--- 300,310 ----
*/
public void addHeaderLine(String line) {
try {
char c = line.charAt(0);
if (c == ' ' || c == '\t') {
! 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,329 ****
}
/**
* Return all the header lines as a collection
*/
! public List getAllHeaderLines() {
if(headerValueView==null)
! headerValueView = new AbstractList() {
! public Object get(int index) {
! return ((hdr)headers.get(index)).line;
}
public int size() {
return headers.size();
}
--- 315,329 ----
}
/**
* Return all the header lines as a collection
*/
! public List<String> getAllHeaderLines() {
if(headerValueView==null)
! headerValueView = new AbstractList<String>() {
! public String get(int index) {
! return headers.get(index).line;
}
public int size() {
return headers.size();
}
< prev index next >