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


Java NanoHTTPD.newFixedLengthResponse方法代碼示例

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


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

示例1: doGet

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
public Response doGet(IHTTPSession session) {
	String uri = session.getUri();
	String path = uri.substring(getRequestMappingURL().length());
	File result = new File(basePath, path);
	String requestCanonicalPath;
	try {
		requestCanonicalPath = result.getCanonicalPath();
	} catch (IOException e1) {
		return new503ErrorResponse();
	}
	//prevent escape from configured base directory
	if (!requestCanonicalPath.startsWith(canonicalBasePath) || !result.exists()) {
		return NanoHTTPD.newFixedLengthResponse(fi.iki.elonen.NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "not found");
	}
	try {
		return NanoHTTPD.newFixedLengthResponse(fi.iki.elonen.NanoHTTPD.Response.Status.OK, getMimeType(uri), new FileInputStream(result), result.length());
	} catch (FileNotFoundException e) {
		return new503ErrorResponse();
	}
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:21,代碼來源:StaticController.java

示例2: get

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public Response get(UriResource uriResource, Map<String, String> urlParams, IHTTPSession session) {
    Method method = session.getMethod();
    String uri = session.getUri();
    //Log.d(TAG, "Method: " + method + ", Url: " + uri);

    try {
        EpubFetcher fetcher = uriResource.initParameter(EpubFetcher.class);

        int offset = uri.indexOf("/", 0);
        int startIndex = uri.indexOf("/", offset + 1);
        String filePath = uri.substring(startIndex + 1);
        Link link = fetcher.publication.getResourceMimeType(filePath);
        String mimeType = link.getTypeLink();

        InputStream inputStream = fetcher.getDataInputStream(filePath);
        response = serveResponse(session, inputStream, mimeType);
    } catch (EpubFetcherException e) {
        e.printStackTrace();
        return NanoHTTPD.newFixedLengthResponse(Status.INTERNAL_ERROR, getMimeType(), ResponseStatus.FAILURE_RESPONSE);
    }
    return response;
}
 
開發者ID:codetoart,項目名稱:r2-streamer-java,代碼行數:24,代碼來源:ResourceHandler.java

示例3: get

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    String elementId = urlParams.get("elementId");
    try {
        Element el = Elements.getGlobal().getElement(elementId);
        final Rect rect = el.element.getVisibleBounds();
        JSONObject res = new JSONObject();
        res.put("x", rect.left);
        res.put("y", rect.top);
        res.put("height", rect.height());
        res.put("width", rect.width());
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(res, sessionId).toString());
    } catch (final Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:18,代碼來源:ElementController.java

示例4: serveOrCatch

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
public NanoHTTPD.Response serveOrCatch(NanoHttpdServer server, NanoHTTPD.IHTTPSession session) throws Exception {
    switch (session.getMethod()) {
        case GET:
            return get.serve(server, session);
        case PUT:
            return put.serve(server, session);
        default:
            NanoMaven.getLogger().error("Unknown method: " + session.getUri());
            return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, NanoHTTPD.MIME_HTML, "Unknown method");
    }
}
 
開發者ID:dzikoysk,項目名稱:NanoMaven,代碼行數:12,代碼來源:NanoRepositoryRouter.java

示例5: serve

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
private Response serve(IHTTPSession session) {
    String path = session.getUri();
    Map<String, String> parameters = session.getParms();
    LOGGER.debug("Request received: {} {}", path, parameters);
    String resource = resources.getResource(path, parameters);
    if (resource == null) {
        resource = resources.getResource("404");
    }
    if (resource == null) {
        resource = "Not found.";
    }
    return NanoHTTPD.newFixedLengthResponse(Status.OK, NanoHTTPD.MIME_PLAINTEXT, resource);
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:14,代碼來源:TestServer.java

示例6: process

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
public Response process(Map<String, String> urlParams, IHTTPSession session) {
    String error = "General error!";
    if (handlerObject != null || handler != null) {
        try {
            Object object = ((handlerObject != null) ? handlerObject : handler.newInstance());
            if (object instanceof UriResponder) {
                UriResponder responder = (UriResponder) object;
                switch (this.method) {
                    case Methods.GET:
                        return responder.get(this, urlParams, session);
                    case Methods.POST:
                        return responder.post(this, urlParams, session);
                    case Methods.PUT:
                        return responder.put(this, urlParams, session);
                    case Methods.DELETE:
                        return responder.delete(this, urlParams, session);
                    default:
                        return responder.other(session.getMethod().toString(), this, urlParams, session);
                }
            } else {
                return NanoHTTPD.newFixedLengthResponse(Status.OK, "text/plain", //
                        new StringBuilder("Return: ")//
                                .append(handler.getCanonicalName())//
                                .append(".toString() -> ")//
                                .append(object)//
                                .toString());
            }
        } catch (Exception e) {
            error = "Error: " + e.getClass().getName() + " : " + e.getMessage();
            LOG.log(Level.SEVERE, error, e);
        }
    }
    return NanoHTTPD.newFixedLengthResponse(Status.INTERNAL_ERROR, "text/plain", error);
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:35,代碼來源:RouterNanoHTTPD.java

示例7: serve

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

    for (Map.Entry<String, String> route : routes.entrySet()) {
        if (!uri.contains(route.getKey())) {
            continue;
        }

        return NanoHTTPD.newFixedLengthResponse(route.getValue());
    }

    return super.serve(session);
}
 
開發者ID:Panda-Programming-Language,項目名稱:Pandomium,代碼行數:15,代碼來源:PandomiumHTTPServer.java

示例8: get

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");

    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:7,代碼來源:UrlController.java

示例9: get

import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.NoSuchElement, sessionId).toString());
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:6,代碼來源:WindowController.java

示例10: createResponse

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


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