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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? httpposter.java

?? J2ME MIDP_Example_Applications
?? JAVA
字號(hào):
// 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 example.mesql;

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
 */
public 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;


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


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


    public 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);
        notify();
        // wake up sending thread
    }


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

            synchronized (this)
            {
                while (requestQueue.size() == 0)
                {
                    try
                    {
                        wait();
                        // releases lock
                    }
                    catch (InterruptedException e)
                    {
                    }

                    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();
                        break;
                    // open again, this time with credentials

                    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)
            {
                url = rewrittenUrl;
                // use this new one in future
            }
        }
        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)
                {
                }
            }
        }

        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)
                {
                }
            }
        }
    }


    private static 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
            {
                responseBuf = new StringBuffer();
                // default length
            }

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


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


    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 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);
    }



    protected 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();
    }


    // Base-64 encoding is defined in http://RFC.net/rfc1521.html
    final static char[] alphabet =
            {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
                'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
                'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
                'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
                'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                'w', 'x', 'y', 'z', '0', '1', '2', '3',
                '4', '5', '6', '7', '8', '9', '+', '/'};


    // Each 3 chars of input is encoded as 4 chars of output from above
    // 64-char alphabet. It's assumed that chars are 8-bit values.
    // If length is multiple of 3, no problem.
    // If length is multiple of 3 + 1, last output char is zero-completed
    // and two '=' characters are appended.
    // If length is multiple of 3 + 2, last output char is zero-completed
    // and one '=' character is appended
    protected static String base64Encode(String str)
    {
        StringBuffer buf = new StringBuffer((str.length() + 2) / 3 * 4);
        int completeGroupChars = (str.length() / 3) * 3;
        int extraChars = str.length() % 3;

        // first write complete groups of 3 chars
        int i;
        for (i = 0; i < completeGroupChars; i += 3)
        {
            int group = ((((int) str.charAt(i)) & 0xFF) << 16) |
                    ((((int) str.charAt(i + 1)) & 0xFF) << 8) |
                    (((int) str.charAt(i + 2)) & 0xFF);

            buf.append(alphabet[(group >> 18) & 63]);
            buf.append(alphabet[(group >> 12) & 63]);
            buf.append(alphabet[(group >> 6) & 63]);
            buf.append(alphabet[group & 63]);
        }

        if (extraChars == 2)
        {
            int group = ((((int) str.charAt(i)) & 0xFF) << 16) |
                    ((((int) str.charAt(i + 1)) & 0xFF) << 8);
            buf.append(alphabet[(group >> 18) & 63]);
            buf.append(alphabet[(group >> 12) & 63]);
            buf.append(alphabet[(group >> 6) & 63]);
            buf.append('=');
        }
        else if (extraChars == 1)
        {
            int group = (((int) str.charAt(i)) & 0xFF) << 16;
            buf.append(alphabet[(group >> 18) & 63]);
            buf.append(alphabet[(group >> 12) & 63]);
            buf.append('=');
            buf.append('=');
        }
        return buf.toString();
    }


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


}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩精品一区二区三区在线| 欧美日韩精品综合在线| 欧美一区二区三区视频免费播放| 久久久激情视频| 日韩国产精品久久| 91亚洲精华国产精华精华液| 国产视频一区在线观看| 美脚の诱脚舐め脚责91| 欧美日韩一区小说| 亚洲人成人一区二区在线观看| 国内外成人在线视频| 欧美日韩精品欧美日韩精品一综合| 国产精品系列在线| 国产精品1区二区.| 精品成人一区二区三区| 日韩精品91亚洲二区在线观看 | 亚洲婷婷综合久久一本伊一区| 精品写真视频在线观看| 欧美一级精品在线| 五月天一区二区三区| 欧美无人高清视频在线观看| 中文字幕在线免费不卡| 成人在线综合网| 久久精品免费在线观看| 国产乱码精品一区二区三| 精品欧美乱码久久久久久| 奇米亚洲午夜久久精品| 91精品国产高清一区二区三区| 一区二区三区四区不卡在线| 99精品国产99久久久久久白柏| 日本一区二区三区在线不卡| 国产一区二区福利| 久久精品亚洲一区二区三区浴池 | 日韩码欧中文字| 99久久精品一区二区| 国产精品久久久久天堂| 成人三级在线视频| 中文一区二区完整视频在线观看| 国产精品亚洲专一区二区三区| 久久久久青草大香线综合精品| 国内精品视频666| 久久久精品免费网站| 国产毛片精品一区| 国产视频一区二区在线观看| 国产.精品.日韩.另类.中文.在线.播放| 欧美精品一区二区三区很污很色的| 久久国产日韩欧美精品| 久久亚洲影视婷婷| 国产成人a级片| 国产精品免费网站在线观看| 99国产一区二区三精品乱码| 亚洲精品国产高清久久伦理二区| 91福利视频在线| 婷婷亚洲久悠悠色悠在线播放 | 国产成人午夜片在线观看高清观看| 国产清纯在线一区二区www| 风间由美性色一区二区三区| 最近日韩中文字幕| 色婷婷国产精品| 天天射综合影视| 精品国产乱码久久久久久夜甘婷婷| 国产一区二区主播在线| 国产女同性恋一区二区| 色综合天天综合色综合av| 一区二区在线观看视频| 欧美绝品在线观看成人午夜影视| 久久精品av麻豆的观看方式| 久久女同互慰一区二区三区| 99久久99久久精品免费看蜜桃| 有码一区二区三区| 91.com在线观看| 国产精品白丝jk黑袜喷水| 亚洲日本护士毛茸茸| 欧美日本在线看| 国产乱码精品一品二品| 亚洲美女免费在线| 欧美一区二区成人| 成人ar影院免费观看视频| 一区二区免费在线| 精品国产乱码91久久久久久网站| 成人动漫一区二区三区| 亚洲无线码一区二区三区| 欧美变态tickle挠乳网站| 成人av在线一区二区| 一个色妞综合视频在线观看| 精品久久久久一区二区国产| 播五月开心婷婷综合| 五月天激情小说综合| 国产午夜精品一区二区 | 国产揄拍国内精品对白| 亚洲九九爱视频| 91精品婷婷国产综合久久 | 日韩二区三区四区| 国产精品剧情在线亚洲| 欧美二区三区91| 成年人网站91| 久久99国产精品麻豆| 亚洲乱码国产乱码精品精可以看| 日韩欧美在线网站| 色88888久久久久久影院野外| 另类综合日韩欧美亚洲| 成人免费在线视频| 精品久久久久久久久久久久久久久久久 | 日本视频一区二区| 中文字幕一区二区在线播放| 欧美一区二区精美| 色欧美乱欧美15图片| 国产一区二区三区高清播放| 亚洲小说欧美激情另类| 中文子幕无线码一区tr| 日韩午夜激情视频| 欧美亚洲国产一卡| 成人av先锋影音| 狠狠色狠狠色综合| 视频一区二区不卡| 一区二区三区四区不卡视频| 中文字幕国产精品一区二区| 日韩美女一区二区三区四区| 欧美自拍丝袜亚洲| 成人免费视频app| 国产一区二区三区免费播放| 日韩精品一二三区| 亚洲一区二区三区美女| 国产精品乱人伦中文| 久久久久成人黄色影片| 日韩视频一区二区在线观看| 欧美无砖砖区免费| 91视频你懂的| 成人激情动漫在线观看| 国产一区二区美女诱惑| 麻豆成人免费电影| 日日夜夜免费精品| 亚洲成人自拍网| 亚洲一区二区在线播放相泽| 中文字幕亚洲一区二区av在线 | 欧美中文字幕一区| 97精品久久久午夜一区二区三区 | 成人久久18免费网站麻豆| 黄页网站大全一区二区| 奇米色777欧美一区二区| 午夜欧美一区二区三区在线播放| 亚洲欧美日韩综合aⅴ视频| 国产精品乱人伦| 国产精品网站在线播放| 国产精品入口麻豆九色| 国产精品区一区二区三区| 日本一区二区免费在线| 久久九九全国免费| 国产午夜精品一区二区 | 欧美日韩午夜影院| 欧美视频一区二区三区四区| 欧美少妇一区二区| 欧美日韩黄色影视| 欧美日韩精品高清| 欧美日本在线一区| 欧美一区二区三区四区久久| 欧美一区二区观看视频| 日韩免费福利电影在线观看| 日韩欧美在线不卡| 日韩视频免费直播| 精品88久久久久88久久久| 久久久久高清精品| 国产日韩精品一区二区三区在线| 国产午夜精品一区二区三区嫩草| 国产欧美日韩亚州综合| 国产精品美女一区二区在线观看| 成人欧美一区二区三区1314| 亚洲精品日韩综合观看成人91| 一区二区三区久久| 亚洲高清免费观看高清完整版在线观看| 亚洲高清不卡在线| 日本欧美一区二区三区| 久久国产日韩欧美精品| 国产成人av一区二区| 99久久婷婷国产综合精品电影| 91久久精品国产91性色tv | 丁香亚洲综合激情啪啪综合| 不卡av在线网| 欧美午夜寂寞影院| 日韩欧美在线不卡| 国产欧美日韩精品a在线观看| 亚洲欧洲无码一区二区三区| 亚洲一区二区av在线| 日本 国产 欧美色综合| 国产真实乱偷精品视频免| thepron国产精品| 欧美色视频一区| 欧美精品一区二区蜜臀亚洲| 欧美国产日本韩| 亚洲一二三区不卡| 国内国产精品久久| 91麻豆.com| 日韩欧美在线一区二区三区| 中文字幕第一页久久| 亚洲自拍偷拍图区| 精品影视av免费| 色综合一区二区| 欧美va亚洲va香蕉在线| 亚洲欧美日韩国产另类专区| 日本美女一区二区|