當前位置: 首頁>>代碼示例>>Java>>正文


Java NanoHTTPD.newChunkedResponse方法代碼示例

本文整理匯總了Java中fi.iki.elonen.NanoHTTPD.newChunkedResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java NanoHTTPD.newChunkedResponse方法的具體用法?Java NanoHTTPD.newChunkedResponse怎麽用?Java NanoHTTPD.newChunkedResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fi.iki.elonen.NanoHTTPD的用法示例。


在下文中一共展示了NanoHTTPD.newChunkedResponse方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serve

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public Response serve(IHTTPSession session) {
    Response response;
    String uri = session.getUri();

    if (uri.equals("/")){
        uri = "/index.html";
    }
    String mimetype = getMimeType(uri);
    Log.d("HTTPServer","MimeType: "+mimetype);
    if (mimetype != null) {
        //Handle text files
        if (mimetype.contains("text/") || mimetype.contains("image/")){
            response = newFixedLengthResponse(getTextFile(uri.substring(1)));
        } else { //handle binary files
            FileInputStream fcontent = getBinaryFile(uri.substring(1));
            response = NanoHTTPD.newChunkedResponse(Response.Status.OK,mimetype,fcontent);
        }
        response.setMimeType(mimetype);
    } else { //Let API Object handle the request
        response = newFixedLengthResponse(mAPI.handle(session));
        response.setMimeType("application/json");
    }

    //Allow CORS
    response.addHeader("Access-Control-Allow-Origin","*");
    response.addHeader("Access-Control-Allow-Headers","auth-user, auth-password");
    return response;
}
 
開發者ID:strang3quark,項目名稱:remotedroid,代碼行數:30,代碼來源:HTTPServer.java

示例2: serve

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public Response serve(IHTTPSession session) {

    if (mNearbyListener != null)
    {
        //Neighbor neighbor = new Neighbor(session.
        //mNearbyListener.foundNeighbor(neighbor);
    }

    if (session.getUri().endsWith(SERVICE_DOWNLOAD_FILE_PATH))
    {
        try {
            return NanoHTTPD.newChunkedResponse(NanoHTTPD.Response.Status.OK, mShareMedia.mMimeType, new FileInputStream(mShareMedia.mFileMedia));
        }
        catch (IOException ioe)
        {
            return NanoHTTPD.newFixedLengthResponse(Response.Status.INTERNAL_ERROR,"text/plain",ioe.getLocalizedMessage());
        }
    }
    else if (session.getUri().endsWith(SERVICE_DOWNLOAD_METADATA_PATH))
    {
        return NanoHTTPD.newFixedLengthResponse(Response.Status.OK,"text/plain",mShareMedia.mMetadataJson);

    }
    else {
        String msg = "<html><body><h1>Hello server</h1>\n";
        Map<String, String> parms = session.getParms();
        if (parms.get("username") == null) {
            msg += "<form action='?' method='get'>\n  <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
        } else {
            msg += "<p>Hello, " + parms.get("username") + "!</p>";
        }
        return NanoHTTPD.newFixedLengthResponse(msg + "</body></html>\n");
    }
}
 
開發者ID:n8fr8,項目名稱:LittleBitLouder,代碼行數:36,代碼來源:NSDSender.java

示例3: get

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
public Response get(UriResource uriResource, Map<String, String> urlParams, IHTTPSession session) {
    return NanoHTTPD.newChunkedResponse(getStatus(), getMimeType(), getData());
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:4,代碼來源:RouterNanoHTTPD.java

示例4: createResponse

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
private Response createResponse(Status status, String mimeType, InputStream message) {
    Response response = NanoHTTPD.newChunkedResponse(status, mimeType, message);
    response.addHeader("Accept-Ranges", "bytes");
    return response;
}
 
開發者ID:codetoart,項目名稱:r2-streamer-java,代碼行數:6,代碼來源:ResourceHandler.java


注:本文中的fi.iki.elonen.NanoHTTPD.newChunkedResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。