当前位置: 首页>>代码示例>>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;未经允许,请勿转载。