本文整理汇总了Java中sun.net.www.HeaderParser类的典型用法代码示例。如果您正苦于以下问题:Java HeaderParser类的具体用法?Java HeaderParser怎么用?Java HeaderParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HeaderParser类属于sun.net.www包,在下文中一共展示了HeaderParser类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setHeaders
import sun.net.www.HeaderParser; //导入依赖的package包/类
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, not used because
* HeaderParser converts the fields to lower case, use raw instead
* @param raw The raw header field.
* @return true if all goes well, false if no headers were set.
*/
@Override
public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
try {
String response;
byte[] incoming = null;
String[] parts = raw.split("\\s+");
if (parts.length > 1) {
incoming = Base64.getDecoder().decode(parts[1]);
}
response = hci.scheme + " " + Base64.getEncoder().encodeToString(
incoming==null?firstToken():nextToken(incoming));
conn.setAuthenticationProperty(getHeaderName(), response);
return true;
} catch (IOException e) {
return false;
}
}
示例2: setHeaders
import sun.net.www.HeaderParser; //导入依赖的package包/类
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, not used because
* HeaderParser converts the fields to lower case, use raw instead
* @param raw The raw header field.
* @return true if all goes well, false if no headers were set.
*/
@Override
public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
try {
NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj();
if (seq == null) {
seq = new NTLMAuthSequence (username, password, ntdomain);
conn.authObj(seq);
}
String response = "NTLM " + seq.getAuthHeader (raw.length()>6?raw.substring(5):null);
conn.setAuthenticationProperty(getHeaderName(), response);
if (seq.isComplete()) {
conn.authObj(null);
}
return true;
} catch (IOException e) {
conn.authObj(null);
return false;
}
}
示例3: main
import sun.net.www.HeaderParser; //导入依赖的package包/类
public static void main (String args[]) {
MessageHeader head = createMessageHeader (s1);
Iterator iter = head.multiValueIterator ("Foo");
checkHeader (iter, s1_Foo);
iter = head.multiValueIterator ("Fub");
checkHeader (iter, s1_Fub);
HeaderParser hp = new HeaderParser (s2).subsequence (1,12);
check (hp, s23_expect);
hp = new HeaderParser (s3).subsequence (1,12);
check (hp, s23_expect);
hp = new HeaderParser (s3).subsequence (0,11);
check (hp, s23_expect1);
hp = new HeaderParser (s2).subsequence (4,6);
check (hp, s23_expect2);
}
示例4: check
import sun.net.www.HeaderParser; //导入依赖的package包/类
static boolean check (HeaderParser p, String[][]expect) {
Iterator keys = p.keys();
Iterator vals = p.values();
boolean empty = true;
for (int j=0; keys.hasNext(); j++) {
empty = false;
String key = (String)keys.next();
String ival = (String)vals.next();
String val = p.findValue (key);
if (val == null && ival == null)
continue;
if (!val.equals(ival)) {
throw new RuntimeException ("Error " + val + "/" + ival);
}
if (!expect[j][0].equals (key)) {
throw new RuntimeException ("Error "+key+"/" + expect[j][0]);
}
if (expect[j][1] != null && !expect[j][1].equals (val)) {
throw new RuntimeException ("Error "+val+"/" + expect[j][1]);
}
}
return empty;
}
示例5: create
import sun.net.www.HeaderParser; //导入依赖的package包/类
public static DigestResponse create(String raw) {
String username, realm, nonce, nc, uri, response, cnonce,
algorithm, qop, opaque;
HeaderParser parser = new HeaderParser(raw);
username = parser.findValue("username");
realm = parser.findValue("realm");
nonce = parser.findValue("nonce");
nc = parser.findValue("nc");
uri = parser.findValue("uri");
cnonce = parser.findValue("cnonce");
response = parser.findValue("response");
algorithm = parser.findValue("algorithm");
qop = parser.findValue("qop");
opaque = parser.findValue("opaque");
return new DigestResponse(realm, username, nonce, cnonce, nc, uri,
algorithm, qop, opaque, response);
}
示例6: setHeaders
import sun.net.www.HeaderParser; //导入依赖的package包/类
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, not used because
* HeaderParser converts the fields to lower case, use raw instead
* @param raw The raw header field.
* @return true if all goes well, false if no headers were set.
*/
@Override
public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
try {
String response;
byte[] incoming = null;
String[] parts = raw.split("\\s+");
if (parts.length > 1) {
incoming = new BASE64Decoder().decodeBuffer(parts[1]);
}
response = hci.scheme + " " + new B64Encoder().encode(
incoming==null?firstToken():nextToken(incoming));
conn.setAuthenticationProperty(getHeaderName(), response);
return true;
} catch (IOException e) {
return false;
}
}
示例7: setHeaders
import sun.net.www.HeaderParser; //导入依赖的package包/类
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, not used because
* HeaderParser converts the fields to lower case, use raw instead
* @param raw The raw header field.
* @return true if all goes well, false if no headers were set.
*/
@Override
public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
try {
NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj();
if (seq == null) {
seq = new NTLMAuthSequence (username, password, ntdomain);
conn.authObj(seq);
}
String response = "NTLM " + seq.getAuthHeader (raw.length()>6?raw.substring(5):null);
conn.setAuthenticationProperty(getHeaderName(), response);
return true;
} catch (IOException e) {
return false;
}
}