当前位置: 首页>>代码示例>>Java>>正文


Java MessageHeader类代码示例

本文整理汇总了Java中sun.net.www.MessageHeader的典型用法代码示例。如果您正苦于以下问题:Java MessageHeader类的具体用法?Java MessageHeader怎么用?Java MessageHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MessageHeader类属于sun.net.www包,在下文中一共展示了MessageHeader类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Manifest

import sun.net.www.MessageHeader; //导入依赖的package包/类
/**
 * Parse a manifest from a stream, optionally computing hashes
 * for the files.
 */
public Manifest(InputStream is, boolean compute) throws IOException {
    if (!is.markSupported()) {
        is = new BufferedInputStream(is);
    }
    /* do not rely on available() here! */
    while (true) {
        is.mark(1);
        if (is.read() == -1) { // EOF
            break;
        }
        is.reset();
        MessageHeader m = new MessageHeader(is);
        if (compute) {
            doHashes(m);
        }
        addEntry(m);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:Manifest.java

示例2: SignatureFile

import sun.net.www.MessageHeader; //导入依赖的package包/类
/**
 * Constructs a new Signature file corresponding to a given
 * Manifest. All entries in the manifest are signed.
 *
 * @param manifest the manifest to use.
 *
 * @param name for this signature file. This should
 * be less than 8 characters, and without a suffix (i.e.
 * without a period in it.
 *
 * @exception JarException if an invalid name is passed in.
 */
public SignatureFile(Manifest manifest, String name)
throws JarException {

    this(name, true);

    this.manifest = manifest;
    Enumeration<MessageHeader> enum_ = manifest.entries();
    while (enum_.hasMoreElements()) {
        MessageHeader mh = enum_.nextElement();
        String entryName = mh.findValue("Name");
        if (entryName != null) {
            add(entryName);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:SignatureFile.java

示例3: computeEntry

import sun.net.www.MessageHeader; //导入依赖的package包/类
/**
 * Given a manifest entry, computes the signature entry for this
 * manifest entry.
 */
private MessageHeader computeEntry(MessageHeader mh) throws IOException {
    MessageHeader smh = new MessageHeader();

    String name = mh.findValue("Name");
    if (name == null) {
        return null;
    }
    smh.set("Name", name);

    try {
        for (int i = 0; i < hashes.length; ++i) {
            MessageDigest dig = getDigest(hashes[i]);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            mh.print(ps);
            byte[] headerBytes = baos.toByteArray();
            byte[] digest = dig.digest(headerBytes);
            smh.set(hashes[i] + "-Digest", Base64.getMimeEncoder().encodeToString(digest));
        }
        return smh;
    } catch (NoSuchAlgorithmException e) {
        throw new JarException(e.getMessage());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:SignatureFile.java

示例4: stream

import sun.net.www.MessageHeader; //导入依赖的package包/类
/**
 * Add a signature file at current position in a stream
 */
public void stream(OutputStream os) throws IOException {

    /* the first header in the file should be the global one.
     * It should say "SignatureFile-Version: x.x"; barf if not
     */
    MessageHeader globals = entries.elementAt(0);
    if (globals.findValue("Signature-Version") == null) {
        throw new JarException("Signature file requires " +
                        "Signature-Version: 1.0 in 1st header");
    }

    PrintStream ps = new PrintStream(os);
    globals.print(ps);

    for (int i = 1; i < entries.size(); ++i) {
        MessageHeader mh = entries.elementAt(i);
        mh.print(ps);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:SignatureFile.java

示例5: processRequests

import sun.net.www.MessageHeader; //导入依赖的package包/类
private void processRequests() throws Exception {

        InputStream in = clientSocket.getInputStream();
        MessageHeader response = new MessageHeader(in);
        String statusLine = response.getValue(0);

        if (statusLine.startsWith("CONNECT")) {
            // retrieve the host and port info from the response line
            retrieveConnectInfo(statusLine);
            respondForConnect();
            doTunnel();
            ss.close();
        } else {
            System.out.println("proxy server: processes only "
                                   + "CONNECT method requests, recieved: "
                                   + statusLine);
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ProxyTunnelServer.java

示例6: handleConnection

import sun.net.www.MessageHeader; //导入依赖的package包/类
static void handleConnection(Socket s, String[] resp, int start, int end) {
    try {
        OutputStream os = s.getOutputStream();

        for (int i=start; i<end; i++) {
            MessageHeader header = new MessageHeader (s.getInputStream());
            //System.out.println("Input :" + header);
            //System.out.println("Output:" + resp[i]);
            os.write(resp[i].getBytes("ASCII"));
        }

        s.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:NTLMTest.java

示例7: run

import sun.net.www.MessageHeader; //导入依赖的package包/类
public void run () {
    try {
        String version = System.getProperty ("java.version");
        String expected = "foo Java/"+version;
        Socket s = server.accept ();
        MessageHeader header = new MessageHeader (s.getInputStream());
        String v = header.findValue ("User-Agent");
        if (!expected.equals (v)) {
            error ("Got unexpected User-Agent: " + v);
        } else {
            success ();
        }
        OutputStream w = s.getOutputStream();
        w.write("HTTP/1.1 200 OK\r\n".getBytes());
        w.write("Content-Type: text/plain\r\n".getBytes());
        w.write("Content-Length: 5\r\n".getBytes());
        w.write("\r\n".getBytes());
        w.write("12345\r\n".getBytes());
    } catch (Exception e) {
        error (e.toString());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:UserAgent.java

示例8: run

import sun.net.www.MessageHeader; //导入依赖的package包/类
public void run() {
    try {
        Socket sock = ss.accept();
        InputStream is = sock.getInputStream();
        OutputStream os = sock.getOutputStream();

        MessageHeader headers =  new MessageHeader (is);
        String requestLine = headers.getValue(0);

        int first  = requestLine.indexOf(' ');
        int second  = requestLine.lastIndexOf(' ');
        String URIString = requestLine.substring(first+1, second);

        URI requestURI = new URI(URIString);
        if (requestURI.getFragment() != null)
            os.write(replyFAILED.getBytes("UTF-8"));
        else
            os.write(replyOK.getBytes("UTF-8"));

        sock.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:RequestURI.java

示例9: main

import sun.net.www.MessageHeader; //导入依赖的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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:HeaderTests.java

示例10: main

import sun.net.www.MessageHeader; //导入依赖的package包/类
public static void main (String[] args) throws Exception {
    for (int i=0; i<7; i++) {
        ByteArrayInputStream bis = new ByteArrayInputStream(headers[i].getBytes());
        MessageHeader h = new MessageHeader(bis);
        String before = h.toString();
        before = before.substring(before.indexOf('{'));
        boolean result = h.filterNTLMResponses("WWW-Authenticate");
        String after = h.toString();
        after = after.substring(after.indexOf('{'));
        if (!expected[i].equals(after)) {
            throw new RuntimeException(Integer.toString(i) + " expected != after");
        }
        if (result != expectedResult[i]) {
            throw new RuntimeException(Integer.toString(i) + " result != expectedResult");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:MessageHeaderTest.java


注:本文中的sun.net.www.MessageHeader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。