本文整理匯總了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;
}
示例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");
}
}
示例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());
}
示例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;
}