/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*-
* news stream opener
*/
/** An RFC 844 or MIME message header. Includes methods
for parsing headers from incoming streams, fetching
values, setting values, and printing headers.
Key values of null are legal: they indicate lines in
the header that don't have a valid key, but do have
a value (this isn't legal according to the standard,
but lines like this are everywhere). */
public
class MessageHeader {
private int nkeys;
public MessageHeader () {
grow();
}
}
/**
*/
public synchronized void reset() {
nkeys = 0;
grow();
}
/**
* Find the value that corresponds to this key.
* It finds only the first occurrence of the key.
* @param k the key to find.
* @return null if not found.
*/
if (k == null) {
for (int i = nkeys; --i >= 0;)
return values[i];
} else
for (int i = nkeys; --i >= 0;) {
if (k.equalsIgnoreCase(keys[i]))
return values[i];
}
return null;
}
// return the location of the key
for (int i = nkeys; --i >= 0;)
if ((keys[i] == k) ||
return i;
return -1;
}
return keys[n];
}
return values[n];
}
/** Deprecated: Use multiValueIterator() instead.
*
* Find the next value that corresponds to this key.
* It finds the first value that follows v. To iterate
* over all the values of a key use:
* <pre>
* for(String v=h.findValue(k); v!=null; v=h.findNextValue(k, v)) {
* ...
* }
* </pre>
*/
boolean foundV = false;
if (k == null) {
for (int i = nkeys; --i >= 0;)
if (foundV)
return values[i];
else if (values[i] == v)
foundV = true;
} else
for (int i = nkeys; --i >= 0;)
if (k.equalsIgnoreCase(keys[i]))
if (foundV)
return values[i];
else if (values[i] == v)
foundV = true;
return null;
}
/**
* Removes bare Negotiate and Kerberos headers when an "NTLM ..."
* appears. All Performed on headers with key being k.
* @return true if there is a change
*/
boolean found = false;
for (int i=0; i<nkeys; i++) {
if (k.equalsIgnoreCase(keys[i])
found = true;
break;
}
}
if (found) {
int j = 0;
for (int i=0; i<nkeys; i++) {
if (k.equalsIgnoreCase(keys[i]) && (
continue;
}
if (i != j) {
}
j++;
}
if (j != nkeys) {
nkeys = j;
return true;
}
}
return false;
}
boolean haveNext = false;
key = k;
}
public boolean hasNext () {
synchronized (lock) {
if (haveNext) {
return true;
}
haveNext = true;
return true;
}
index ++;
}
return false;
}
}
synchronized (lock) {
if (haveNext) {
haveNext = false;
}
if (hasNext()) {
return next();
} else {
throw new NoSuchElementException ("No more elements");
}
}
}
public void remove () {
throw new UnsupportedOperationException ("remove not allowed");
}
}
/**
* return an Iterator that returns all values of a particular
* key in sequence
*/
return new HeaderIterator (k, this);
}
return getHeaders(null);
}
}
public synchronized Map<String, List<String>> filterAndAddHeaders(String[] excludeList, Map<String, List<String>> include) {
boolean skipIt = false;
for (int i = nkeys; --i >= 0;) {
if (excludeList != null) {
// check if the key is in the excludeList.
// if so, don't include it in the Map.
if ((excludeList[j] != null) &&
skipIt = true;
break;
}
}
}
if (!skipIt) {
if (l == null) {
}
} else {
// reset the flag
skipIt = false;
}
}
if (l == null) {
l = new ArrayList();
}
}
}
}
return Collections.unmodifiableMap(m);
}
/** Prints the key-value pairs represented by this
header. Also prints the RFC required blank line
at the end. Omits pairs with a null key. */
for (int i = 0; i < nkeys; i++)
}
p.print("\r\n");
p.flush();
}
/** Adds a key value pair to the end of the
header. Duplicates are allowed */
grow();
nkeys++;
}
/** Prepends a key value pair to the beginning of the
header. Duplicates are allowed */
grow();
for (int i = nkeys; i > 0; i--) {
}
keys[0] = k;
values[0] = v;
nkeys++;
}
* with the new k/v. If the index didn't exist before
*/
grow();
if (i < 0) {
return;
} else if (i >= nkeys) {
add(k, v);
} else {
keys[i] = k;
values[i] = v;
}
}
private void grow() {
}
}
/**
* Remove the key from the header. If there are multiple values under
* the same key, they are all removed.
* Nothing is done if the key doesn't exist.
* After a remove, the other pairs' order are not changed.
* @param k the key to remove
*/
if(k == null) {
for (int i = 0; i < nkeys; i++) {
for(int j=i; j<nkeys-1; j++) {
}
nkeys--;
}
}
} else {
for (int i = 0; i < nkeys; i++) {
for(int j=i; j<nkeys-1; j++) {
}
nkeys--;
}
}
}
}
/** Sets the value of a key. If the key already
exists in the header, it's value will be
be added to the end of the header. */
for (int i = nkeys; --i >= 0;)
if (k.equalsIgnoreCase(keys[i])) {
values[i] = v;
return;
}
add(k, v);
}
/** Set's the value of a key only if there is no
* key with that value already.
*/
add(k, v);
}
}
/** Convert a message-id string to canonical form (strips off
leading and trailing <>s) */
return "";
int st = 0;
boolean substr = false;
int c;
c <= ' ')) {
st++;
substr = true;
}
c <= ' ')) {
len--;
substr = true;
}
}
/** Parse a MIME header from an input stream. */
synchronized (this) {
nkeys = 0;
}
}
/** Parse and merge a MIME header from an input stream. */
return;
char s[] = new char[10];
int len = 0;
int keyend = -1;
int c;
switch (c) {
case ':':
inKey = false;
break;
case '\t':
c = ' ';
case ' ':
inKey = false;
break;
case '\r':
case '\n':
if (firstc == '\r')
}
break parseloop;
/* continuation */
c = ' ';
break;
}
s = ns;
}
s[len++] = (char) c;
}
firstc = -1;
}
len--;
String k;
if (keyend <= 0) {
k = null;
keyend = 0;
} else {
keyend++;
keyend++;
}
String v;
v = new String();
else
add(k, v);
}
}
}
return result;
}
}