InternetHeaders (Java EE 5)

Java EE API


javax.mail.internet Class InternetHeaders

java.lang.Object
  extended by javax.mail.internet.InternetHeaders

public class InternetHeaders
extends Object


InternetHeaders 是一个管理 RFC822 样式头的实用工具类。如果给定一个 RFC822 格式的消息流,此类将读取各行,直到指示头结束的空行为止。输入流位于正文的起始处。行存储在对象内,可以被提取为 String 或 javax.mail.Header 对象。

此类主要供服务提供者使用。MimeMessage 和 MimeBody 使用此类保存它们的头。


有关 RFC822 和 MIME 头的注意事项

RFC822 和 MIME 头字段只能包含 US-ASCII 字符。如果头包含非 US-ASCII 字符,则它必须根据 RFC 2047 的规则进行编码。此包提供的 MimeUtility 类可以用于实现这一点。setHeaderaddHeaderaddHeaderLine 方法的调用者负责针对特定的头强制执行 MIME 要求。此外,如果这些头字段超过了传输的行长度限制(SMTP 1000 字节),则发送前必须进行折叠(包装)。收到的头可能已经进行了折叠。应用程序负责根据需要折叠和展开头。

英文文档:

InternetHeaders is a utility class that manages RFC822 style headers. Given an RFC822 format message stream, it reads lines until the blank line that indicates end of header. The input stream is positioned at the start of the body. The lines are stored within the object and can be extracted as either Strings or Header objects.

This class is mostly intended for service providers. MimeMessage and MimeBody use this class for holding their headers.


A note on RFC822 and MIME headers

RFC822 and MIME header fields must contain only US-ASCII characters. If a header contains non US-ASCII characters, it must be encoded as per the rules in RFC 2047. The MimeUtility class provided in this package can be used to to achieve this. Callers of the setHeader, addHeader, and addHeaderLine methods are responsible for enforcing the MIME requirements for the specified headers. In addition, these header fields must be folded (wrapped) before being sent if they exceed the line length limitation for the transport (1000 bytes for SMTP). Received headers may have been folded. The application is responsible for folding and unfolding headers as appropriate.

Author:
John Mani, Bill Shannon
See Also:
MimeUtility

Nested Class Summary
protected static class
 
Field Summary
protected  List
 
Constructor Summary
 
Method Summary
 void
 void
 Enumeration
 Enumeration
 String[]
 String
 Enumeration
 Enumeration
 Enumeration
 Enumeration
 void
 void
 void
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

headers

protected List headers
The actual list of Headers, including placeholder entries. Placeholder entries are Headers with a null value and are never seen by clients of the InternetHeaders class. Placeholder entries are used to keep track of the preferred order of headers. Headers are never actually removed from the list, they're converted into placeholder entries. New headers are added after existing headers of the same name (or before in the case of Received and Return-Path headers). If no existing header or placeholder for the header is found, new headers are added after the special placeholder with the name ":".

Since:
JavaMail 1.4

Constructor Detail

public InternetHeaders()
创建空 InternetHeaders 对象。插入占位符条目以指示头的首选顺序。
英文文档:

InternetHeaders

public InternetHeaders()
Create an empty InternetHeaders object. Placeholder entries are inserted to indicate the preferred order of headers.


public InternetHeaders(java.io.InputStream is) throws MessagingException
读取和解析给定的 RFC822 消息流,直到分隔头与正文的空白行为止。输入流位于正文的起始处。头行进行内部存储。

为了提高效率,将 BufferedInputStream 包装成实际输入流并作为参数传递。

不插入占位符条目,保留头原来的顺序。

is RFC822 输入流

英文文档:

InternetHeaders

public InternetHeaders(InputStream is)
                throws MessagingException
Read and parse the given RFC822 message stream till the blank line separating the header from the body. The input stream is left positioned at the start of the body. The header lines are stored internally.

For efficiency, wrap a BufferedInputStream around the actual input stream and pass it as the parameter.

No placeholder entries are inserted; the original order of the headers is preserved.

Parameters:
is - RFC822 input stream
Throws:
MessagingException

Method Detail

public void load(java.io.InputStream is) throws MessagingException
读取和解析给定的 RFC822 消息流,直到分隔头与正文的空白行为止。将头行存储在此 InternetHeaders 对象内。保留头行的顺序。

注意,头行被添加到此 InternetHeaders 对象中,因此此对象中的任何现有头将不会受到影响。头将按顺序添加到现有头列表的末尾。

is RFC822 输入流

英文文档:

load

public void load(InputStream is)
          throws MessagingException
Read and parse the given RFC822 message stream till the blank line separating the header from the body. Store the header lines inside this InternetHeaders object. The order of header lines is preserved.

Note that the header lines are added into this InternetHeaders object, so any existing headers in this object will not be affected. Headers are added to the end of the existing list of headers, in order.

Parameters:
is - RFC822 input stream
Throws:
MessagingException

public String[] getHeader(String name)
返回指定头的所有值。值为 String 对象。如果不存在指定名称的头,则返回 null
name 头名称
return 头值数组;如果没有,则返回 null
英文文档:

getHeader

public String[] getHeader(String name)
Return all the values for the specified header. The values are String objects. Returns null if no headers with the specified name exist.

Parameters:
name - header name
Returns:
array of header values, or null if none

public String getHeader(String name, String delimiter)
获取具有此头名称的所有头,以单个 String 返回,且头之间用 delimiter 分隔。如果 delimiter 为 null,则仅返回第一个头。如果不存在指定名称的头,则返回 null
name 头名称
delimiter 分界符
return 具有此名称的所有头的值字段;如果没有,则返回 null
英文文档:

getHeader

public String getHeader(String name,
                        String delimiter)
Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. If the delimiter is null, only the first header is returned. Returns null if no headers with the specified name exist.

Parameters:
name - header name
delimiter - delimiter
Returns:
the value fields for all headers with this name, or null if none

public void setHeader(String name, String value)
将匹配 name 的第一个头行更改为值 value;如果现有的头都不匹配,则添加一个新的头。移除第一个匹配头以外的所有匹配头。

注意,RFC822 头只能包含 US-ASCII 字符

name 头名称
value 头值

英文文档:

setHeader

public void setHeader(String name,
                      String value)
Change the first header line that matches name to have value, adding a new header if no existing header matches. Remove all matching headers but the first.

Note that RFC822 headers can only contain US-ASCII characters

Parameters:
name - header name
value - header value

public void addHeader(String name, String value)
将带有指定名称和值的头添加到头列表中。

当前实现了解大多数常见头的首选顺序,并会以此顺序插入头。此外,它了解 Received 头应以相反的顺序插入(最新的头在最旧的头之前),而且它们应该出现在头的起始处,其前面只可能是 Return-Path 头。

注意,RFC822 头只能包含 US-ASCII 字符。

name 头名称
value 头值

英文文档:

addHeader

public void addHeader(String name,
                      String value)
Add a header with the specified name and value to the header list.

The current implementation knows about the preferred order of most well-known headers and will insert headers in that order. In addition, it knows that Received headers should be inserted in reverse order (newest before oldest), and that they should appear at the beginning of the headers, preceeded only by a possible Return-Path header.

Note that RFC822 headers can only contain US-ASCII characters.

Parameters:
name - header name
value - header value

public void removeHeader(String name)
移除其名称与给定名称匹配的所有头条目
name 头名称
英文文档:

removeHeader

public void removeHeader(String name)
Remove all header entries that match the given name

Parameters:
name - header name

public java.util.Enumeration<E> getAllHeaders()
将所有头作为 javax.mail.Header 对象的枚举返回。
return Header 对象
英文文档:

getAllHeaders

public Enumeration getAllHeaders()
Return all the headers as an Enumeration of Header objects.

Returns:
Header objects

public java.util.Enumeration<E> getMatchingHeaders(String[] names)
返回所有匹配的 javax.mail.Header 对象。
return 匹配的 Header 对象
英文文档:

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
Return all matching Header objects.

Returns:
matching Header objects

public java.util.Enumeration<E> getNonMatchingHeaders(String[] names)
返回所有不匹配的 javax.mail.Header 对象。
return 不匹配的 Header 对象
英文文档:

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
Return all non-matching Header objects.

Returns:
non-matching Header objects

public void addHeaderLine(String line)
将 RFC822 头行添加到头存储库中。如果行以空格或制表符开始(连续行),则将它添加到列表的最后一个头行之后。否则,将新的头行添加到列表。

注意,RFC822 头只能包含 US-ASCII 字符

line 原始的 RFC822 头行

英文文档:

addHeaderLine

public void addHeaderLine(String line)
Add an RFC822 header line to the header store. If the line starts with a space or tab (a continuation line), add it to the last header line in the list. Otherwise, append the new header line to the list.

Note that RFC822 headers can only contain US-ASCII characters

Parameters:
line - raw RFC822 header line

public java.util.Enumeration<E> getAllHeaderLines()
将所有头行作为 Strings 枚举返回。
英文文档:

getAllHeaderLines

public Enumeration getAllHeaderLines()
Return all the header lines as an Enumeration of Strings.


public java.util.Enumeration<E> getMatchingHeaderLines(String[] names)
将所有匹配的头行作为 String 枚举返回。
英文文档:

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
Return all matching header lines as an Enumeration of Strings.


public java.util.Enumeration<E> getNonMatchingHeaderLines(String[] names)
返回所有不匹配的头行
英文文档:

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
Return all non-matching header lines



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!