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


Java HttpServletRequest.getContentLength方法代碼示例

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


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

示例1: readRequestPayLoadBytes

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 *@description 讀取Post請求中的有效載荷對象
 *@time 創建時間:2017年12月14日上午11:31:40
 *@param request
 *@return
 *@throws IOException
 *@author dzn
 */
public static final byte[] readRequestPayLoadBytes(HttpServletRequest request) throws IOException {
    request.setCharacterEncoding("UTF-8");
    int contentLen = request.getContentLength();
    InputStream is = request.getInputStream();
    if (contentLen > 0) {
        int readLen = 0;
        int readLengthThisTime = 0;
        byte[] message = new byte[contentLen];
        try {
            while (readLen != contentLen) {
                readLengthThisTime = is.read(message, readLen, contentLen - readLen);
                if (readLengthThisTime == -1) {
                    break;
                }
                readLen += readLengthThisTime;
            }
            return message;
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }
    return new byte[] {};
}
 
開發者ID:SnailFastGo,項目名稱:netty_op,代碼行數:33,代碼來源:JettyServerHandler.java

示例2: readBytes

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * read bytes from http request
 * @param request
 * @return
 * @throws IOException 
 */
public static final byte[] readBytes(HttpServletRequest request) throws IOException {
	request.setCharacterEncoding("UTF-8");
       int contentLen = request.getContentLength();
	InputStream is = request.getInputStream();
	if (contentLen > 0) {
		int readLen = 0;
		int readLengthThisTime = 0;
		byte[] message = new byte[contentLen];
		try {
			while (readLen != contentLen) {
				readLengthThisTime = is.read(message, readLen, contentLen - readLen);
				if (readLengthThisTime == -1) {
					break;
				}
				readLen += readLengthThisTime;
			}
			return message;
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			throw e;
		}
	}
	return new byte[] {};
}
 
開發者ID:mmwhd,項目名稱:stage-job,代碼行數:31,代碼來源:HttpClientUtil.java

示例3: readBytes

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * read bytes from http request
 * @param request
 * @return
 * @throws IOException 
 */
public static final byte[] readBytes(HttpServletRequest request) throws IOException {
	request.setCharacterEncoding("UTF-8");
       int contentLen = request.getContentLength();
	InputStream is = request.getInputStream();
	if (contentLen > 0) {
		int readLen = 0;
		int readLengthThisTime = 0;
		byte[] message = new byte[contentLen];
		try {
			while (readLen != contentLen) {
				readLengthThisTime = is.read(message, readLen, contentLen - readLen);
				if (readLengthThisTime == -1) {
					break;
				}
				readLen += readLengthThisTime;
			}
			return message;
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		}
	}
	return new byte[] {};
}
 
開發者ID:kevinKaiF,項目名稱:xxl-job,代碼行數:31,代碼來源:HttpClientUtil.java

示例4: getInputStreamEntity

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private InputStreamEntity getInputStreamEntity(HttpServletRequest request) throws IOException
{
    int contentLength = request.getContentLength();

    ContentType contentType = null;
    if (request.getContentType() != null) {
        contentType = ContentType.parse(request.getContentType());
    }

    return new InputStreamEntity(request.getInputStream(), contentLength, contentType);
}
 
開發者ID:coveo,項目名稱:k8s-proxy,代碼行數:12,代碼來源:K8sReverseProxy.java

示例5: testRequestMessageBody

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void testRequestMessageBody() throws Exception {
    String body = "12345678901234567890";
    InputStream stream = new ByteArrayInputStream( body.getBytes( "UTF-8" ) );
    WebRequest wr = new PutMethodWebRequest( "http://localhost/simple", stream, "text/plain" );
    HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), body.getBytes() );

    assertEquals( "Request content length", body.length(), request.getContentLength() );
    BufferedInputStream bis = new BufferedInputStream( request.getInputStream() );
    byte[] buffer = new byte[ request.getContentLength() ];
    bis.read( buffer );
    assertEquals( "Request content", body, new String( buffer ) );
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:13,代碼來源:HttpServletRequestTest.java

示例6: getBody

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private GerritProjectEvent getBody(HttpServletRequest req) throws IOException {
  char[] body = new char[req.getContentLength()];
  try (InputStreamReader is = new InputStreamReader(req.getInputStream())) {
    IOUtils.readFully(is, body);
    String bodyString = new String(body);
    log.info("Received body: " + bodyString);
    return gson.fromJson(bodyString, GerritProjectEvent.class);
  }
}
 
開發者ID:GerritForge,項目名稱:gerrit-plugin,代碼行數:10,代碼來源:GerritWebHook.java

示例7: JsonContentCachingRequestWrapper

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public JsonContentCachingRequestWrapper(HttpServletRequest request) {
	super(request);
	int contentLength = request.getContentLength();
	this.cachedContent = new ByteArrayOutputStream(contentLength >= 0 ? contentLength : 1024);
}
 
開發者ID:wengwh,項目名稱:plumdo-stock,代碼行數:6,代碼來源:JsonContentCachingRequestWrapper.java

示例8: gatherRequestInfo

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private void gatherRequestInfo(ParameterShuttle infoShuttle, HttpServletRequest request) throws IOException {
		infoShuttle.sessionID = request.getSession().getId();

		infoShuttle.postFromUser = request.getMethod().equals("POST");
		if (infoShuttle.postFromUser) {
			infoShuttle.userContentType = request.getContentType();
			infoShuttle.userContentLength = request.getContentLength();
		}

/*		String query = request.getQueryString();
		if (query != null) {
			int pos = 0;

			infoShuttle.postToSite = query.startsWith(ParameterShuttle.bridgePostTag);
			if (infoShuttle.postToSite)
				pos = ParameterShuttle.bridgePostTag.length();

			if (query.startsWith(ParameterShuttle.bridgeGotoTag, pos)) {
				int p2 = query.indexOf(ParameterShuttle.bridgeThenTag, pos);

				if (p2 > -1) {
					infoShuttle.userGoto = query.substring(pos + ParameterShuttle.bridgeGotoTag.length(), p2);
					infoShuttle.userThen = query.substring(p2 + ParameterShuttle.bridgeThenTag.length());
				}
				else {
					infoShuttle.userGoto = query.substring(pos + ParameterShuttle.bridgeGotoTag.length());
				}
			}
			else if (query.startsWith(ParameterShuttle.bridgeThenTag, pos)) {
				infoShuttle.userThen = query.substring(pos + ParameterShuttle.bridgeThenTag.length());
			}
		}*/
		infoShuttle.postToSite = infoShuttle.postFromUser;//request.getParameter(Parameter.ProxyPost.getName()) != null;
		infoShuttle.userGoto = request.getParameter(Parameter.ProxyGoto.getName());
		infoShuttle.userThen = request.getParameter(Parameter.ProxyThen.getName());

		Enumeration<String> allHeaderNames = GenericUtils.cast(request.getHeaderNames());
		while (allHeaderNames.hasMoreElements()) {
			String name = (String) allHeaderNames.nextElement();
			infoShuttle.userHeaderNames.add(name.toLowerCase());
			infoShuttle.userHeaderValues.add(request.getHeader(name));
		}

		ParameterShuttle.getSelfURL(
			request.getScheme(),
			request.getServerName(),
			request.getServerPort(),
			request.getRequestURI()
		);
	}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:51,代碼來源:ProxyServletRequester.java


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