亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? httpposter.java

?? J2ME MIDP_Example_Applications
?? JAVA
字號:
// Copyright 2003 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
package whiteboard;

import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;

/**
 *  This class accepts and queues POST and GET requests for a particular URL,
 *  and services them in first-in-first-out order. Using the queue allows it to
 *  be thread-safe without forcing its clients ever to block. It also accept
 *  alternative MIME-types: It Supports Basic Authentication
 */
class HttpPoster
    implements Runnable
{
    protected String url;
    protected Display display;
    protected volatile boolean aborting = false;
    protected Vector requestQueue = new Vector();
    // store the last valid credentials
    protected String credentials = null;
    protected String username = null, password = null;


    HttpPoster(Display display, String url)
    {
        this.display = display;
        this.url = url;
        Thread thread = new Thread(this);
        thread.start();
    }


    void sendRequest(String type, String request, HttpPosterListener listener)
        throws IOException
    {
        sendRequest(type, null, request, listener);
    }


    synchronized void sendRequest(String type, String mimeType,
                                  String request, HttpPosterListener listener)
        throws IOException
    {
        // Create a new request and add it to the queue
        HttpRequest newRequest = new HttpRequest();
        newRequest.type = type;
        newRequest.request = request;
        newRequest.listener = listener;
        newRequest.mimeType = mimeType;
        requestQueue.addElement(newRequest);
        // wake up sending thread
        notify();
    }


    public void run()
    {
        running :
        while (!aborting)
        {
            HttpRequest request = null;

            synchronized (this)
            {
                while (requestQueue.size() == 0)
                {
                    try
                    {
                        // releases lock
                        wait();
                    }
                    catch (InterruptedException e)
                    {
                        // Ignore this thread is not interrupted in MIDP
                    }

                    if (aborting)
                    {
                        break running;
                    }
                }

                request = (HttpRequest) (requestQueue.elementAt(0));
                requestQueue.removeElementAt(0);
            }

            // sendRequest must have notified us
            doSend(request.type, request.mimeType, request.request, request.listener);
        }
    }



    private void doSend(String type, String mimeType,
                        String requestStr, HttpPosterListener listener)
    {
        HttpConnection conn = null;
        InputStream in = null;
        String responseStr = null;
        String errorStr = null;
        boolean wasError = false;
        try
        {
            int responseCode;
            do
            {

                conn = (HttpConnection) Connector.open(url);

                // Set the request method and headers
                conn.setRequestMethod(type);

                // write request
                writeRequest(conn, requestStr, mimeType);

                // read response
                responseStr = readResponse(conn);

                responseCode = conn.getResponseCode();
                switch (responseCode)
                {
                    case HttpConnection.HTTP_OK:
                        break;
                    case HttpConnection.HTTP_UNAUTHORIZED:
                        // missing credentials when server requires them,
                        // or credentials sent but invalid
                        credentials = getCredentials(
                            conn.getHeaderField("WWW-Authenticate"));
                        conn.close();
                        // open again, this time with credentials
                        break;
                    default:
                        throw new IOException("Unsupported response code: " + responseCode);
                }
            } while (responseCode != HttpConnection.HTTP_OK);

            // support URL rewriting for session handling
            String rewrittenUrl = conn.getHeaderField("X-RewrittenURL");
            if (rewrittenUrl != null)
            {
                // use this new one in future
                url = rewrittenUrl;
            }
        }
        catch (IOException e)
        {
            wasError = true;
            errorStr = e.getMessage();
        }
        catch (SecurityException e)
        {
            wasError = true;
            errorStr = e.getMessage();
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (IOException e)
                {
                    // already closing, just ignore
                }
            }
        }

        if (wasError)
        {
            listener.handleHttpError(errorStr);
        }
        else
        {
            listener.receiveHttpResponse(responseStr);
        }
    }


    private void writeRequest(HttpConnection conn, String request, String mimeType)
        throws IOException
    {
        OutputStream out = null;

        try
        {
            conn.setRequestProperty("Content-Length",
                                    Integer.toString(request.length()));
            if (mimeType != null)
            {
                conn.setRequestProperty("Content-Type", mimeType);
            }
            if (credentials != null)
            {
                conn.setRequestProperty("Authorization",
                                        "Basic " + credentials);
            }

            // Getting the output stream may flush the headers
            out = conn.openOutputStream();
            int requestLength = request.length();
            for (int i = 0; i < requestLength; ++i)
            {
                out.write(request.charAt(i));
            }
        }
        finally
        {
            if (out != null)
            {
                try
                {
                    out.close();
                }
                catch (IOException e)
                {
                    // already closing, just ignore
                }
            }
        }
    }


    private String readResponse(HttpConnection conn)
        throws IOException
    {
        InputStream in = null;
        String responseStr = null;
        try
        {
            // Opening the InputStream will open the connection
            // and read the HTTP headers. They are stored until
            // requested.
            in = conn.openInputStream();

            // Get the length and process the data
            StringBuffer responseBuf;
            long length = conn.getLength();
            if (length > 0)
            {
                responseBuf = new StringBuffer((int) length);
            }
            else
            {
                // default length
                responseBuf = new StringBuffer();
            }

            int ch;
            while ((ch = in.read()) != -1)
            {
                responseBuf.append((char) ch);
            }
            responseStr = responseBuf.toString();
        }
        finally
        {
            if (in != null)
            {
                try
                {
                    in.close();
                }
                catch (IOException e)
                {
                    // already closing, just ignore
                }
            }
        }
        return responseStr;
    }


    // This is just for tidying up - the instance is useless after it has
    // been called
    void abort()
    {
        aborting = true;
        synchronized (this)
        {
            // wake up our posting thread and kill it
            notify();
        }
    }


    private String getCredentials(String challenge)
        throws IOException
    {
        String realm = getAuthenticationRealm(challenge);
        promptForCredentials(realm);
        if (username == null || password == null)
        {
            throw new IOException("Must give username & password");
        }
        // Calculate the credentials
        return HttpUtils.base64Encode(username + ":" + password);
    }


    private String getAuthenticationRealm(String challenge)
        throws IOException
    {
        if (challenge == null)
        {
            throw new IOException("Missing authentication challenge");
        }
        challenge = challenge.trim();
        if (!challenge.startsWith("Basic"))
        {
            throw new IOException("Authentication scheme not \"Basic\"");
        }
        int length = challenge.length();
        // we don't check for extra double quotes...
        if ((length < 8) ||
            (!challenge.substring(5, 13).equals(" realm=\"")) ||
            (challenge.charAt(length - 1) != '\"'))
        {
            throw new IOException("Authentication realm syntax error");
        }
        return challenge.substring(13, length - 1);
    }



    private void promptForCredentials(String realm)
    {
        // This is a nasty method, as it must suspend the current
        // thread, put up a prompt dialog, get the result, and wake
        // up again
        PromptDialog dialog = new PromptDialog(display, realm);
        dialog.promptForInput();
        // this call blocks us until answered
        username = dialog.getUsername();
        password = dialog.getPassword();
    }


    private class HttpRequest
    {
        String type;
        String mimeType;
        String request;
        HttpPosterListener listener;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲美女视频在线观看| 经典一区二区三区| 欧美喷潮久久久xxxxx| 亚洲国产毛片aaaaa无费看| 欧美一区二区福利在线| 成人教育av在线| 偷偷要91色婷婷| 2020日本不卡一区二区视频| 91老师国产黑色丝袜在线| 久久aⅴ国产欧美74aaa| 一区二区三区国产豹纹内裤在线| 日韩欧美国产一区二区三区| 日本久久电影网| 国产在线精品不卡| 免费看精品久久片| 亚洲一二三四区| 国产精品福利影院| 亚洲另类中文字| 色狠狠一区二区三区香蕉| 成人理论电影网| 亚洲男人天堂av| 欧美日韩国产一二三| 亚洲一区二区精品久久av| 久久久久一区二区三区四区| 91精品国产欧美日韩| 欧美人牲a欧美精品| 欧美在线|欧美| 欧美在线免费观看视频| 91丨porny丨首页| 欧美亚洲日本一区| 亚洲视频在线观看一区| 欧美精品一区二区久久久| 欧美日韩美少妇| 69堂成人精品免费视频| 精品国产一区二区亚洲人成毛片| 色综合久久久久综合99| 色综合天天做天天爱| 欧美日韩三级视频| 日韩免费高清av| 亚洲精品五月天| 精品无人码麻豆乱码1区2区| 99综合影院在线| 精品久久久久99| 亚洲欧洲av一区二区三区久久| 亚洲一区二区在线观看视频| 国产在线播精品第三| 欧美精品九九99久久| 亚洲欧洲韩国日本视频| 国产中文字幕精品| 欧美一区二区三区在线观看| 亚洲一二三级电影| 色伊人久久综合中文字幕| 久久久久久久久久美女| 日本成人在线看| 欧美视频一区二区| 亚洲一区二区影院| 色先锋久久av资源部| 国产欧美一区二区三区沐欲| 久久99久久久久| 欧美一区二区二区| 日本vs亚洲vs韩国一区三区二区 | 亚洲精品水蜜桃| 99精品国产一区二区三区不卡| 国产喂奶挤奶一区二区三区| 久久99国产精品久久99| 日韩一区二区三区三四区视频在线观看 | 97精品国产97久久久久久久久久久久 | 大陆成人av片| 亚洲欧洲精品天堂一级| 床上的激情91.| 亚洲日本一区二区三区| 日本精品视频一区二区| 亚洲午夜免费视频| 日韩欧美高清dvd碟片| 久久国产精品色婷婷| 久久久一区二区| 成人国产视频在线观看| 国产精品久久久久久一区二区三区 | 日日噜噜夜夜狠狠视频欧美人| 欧美日韩一二三| 国产一区二区看久久| 最新国产精品久久精品| 欧美日高清视频| 国产精品亚洲专一区二区三区| 国产精品免费久久| 91高清视频在线| 精品亚洲免费视频| 国产精品无人区| 亚洲男同1069视频| 日韩视频国产视频| 久久国产婷婷国产香蕉| 欧美女孩性生活视频| 久久精品久久精品| 国产传媒欧美日韩成人| 岛国av在线一区| a4yy欧美一区二区三区| 色综合久久88色综合天天6 | 不卡欧美aaaaa| 欧洲精品一区二区三区在线观看| 99精品在线免费| 欧美一二三区在线观看| 精品国产网站在线观看| 成人免费小视频| 麻豆精品精品国产自在97香蕉 | 91浏览器入口在线观看| 欧美日韩一区三区| 欧美一区二区网站| 日韩欧美在线影院| 久久国产精品99久久人人澡| www.欧美精品一二区| 这里是久久伊人| 亚洲精品视频观看| 成人免费视频视频在线观看免费| 久久精品视频网| 久久国产精品无码网站| 色欧美日韩亚洲| 欧美高清在线视频| 亚洲国产wwwccc36天堂| 风间由美一区二区三区在线观看| 8v天堂国产在线一区二区| 亚洲成人中文在线| 91福利在线导航| 中文字幕av免费专区久久| 国产.欧美.日韩| 久久久国际精品| 国产福利91精品一区| 久久久久久久综合日本| 久久国产乱子精品免费女| 欧美成人一级视频| 国产在线精品免费av| 久久久久久久久久电影| 国产乱色国产精品免费视频| 2020国产精品| 成人av免费在线播放| 亚洲品质自拍视频| 7777精品伊人久久久大香线蕉完整版| 视频一区欧美精品| 久久嫩草精品久久久精品一| 国产精品69毛片高清亚洲| 亚洲少妇30p| 日韩一区二区三区视频在线| 日本不卡视频在线| 国产精品不卡在线观看| 色综合久久综合网欧美综合网| 天天亚洲美女在线视频| 欧美本精品男人aⅴ天堂| 国产成人综合自拍| 丝袜亚洲精品中文字幕一区| 久久久高清一区二区三区| 色婷婷精品大视频在线蜜桃视频 | 国产成+人+日韩+欧美+亚洲| 国产精品久久久久久久午夜片| 99久久精品国产麻豆演员表| 亚洲国产精品久久一线不卡| 91精品国产综合久久久久| 色婷婷综合中文久久一本| 国产成人免费视频一区| 久久精品国产99久久6| 亚洲国产精品久久久久婷婷884| 日韩视频免费观看高清在线视频| 91女厕偷拍女厕偷拍高清| 日本强好片久久久久久aaa| 欧美一二三在线| 欧美日韩国产欧美日美国产精品| 免费人成精品欧美精品| 婷婷久久综合九色综合伊人色| 国产精品不卡一区二区三区| 日韩欧美一级片| 欧美一区二区国产| 91 com成人网| 日韩精品一区在线| www亚洲一区| 国产精品三级在线观看| 亚洲人一二三区| 中文字幕一区在线观看视频| 亚洲视频在线观看一区| 综合激情成人伊人| 亚洲精品久久7777| 偷拍日韩校园综合在线| 日韩电影在线免费观看| 国产最新精品精品你懂的| 成人黄色网址在线观看| 91在线观看高清| 在线不卡欧美精品一区二区三区| 精品福利一区二区三区| 成人欧美一区二区三区黑人麻豆| 国产精品成人免费| 亚洲精品高清视频在线观看| 琪琪一区二区三区| 国产高清久久久| 欧美日韩综合在线免费观看| 69久久夜色精品国产69蝌蚪网 | 午夜精品在线看| 国产激情视频一区二区在线观看| 91福利视频久久久久| 中文字幕成人在线观看| 久久精品国产**网站演员| 91福利国产精品| 亚洲天堂中文字幕| 成人网在线免费视频|