当前位置: 首页>>代码示例>>Java>>正文


Java ServletInputStream.read方法代码示例

本文整理汇总了Java中javax.servlet.ServletInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java ServletInputStream.read方法的具体用法?Java ServletInputStream.read怎么用?Java ServletInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletInputStream的用法示例。


在下文中一共展示了ServletInputStream.read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInputStream

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
  final ServletInputStream inputStream = d.getInputStream();
  return new ServletInputStream() {

    @Override
    public int read() throws IOException {
      int b = inputStream.read();
      if (b != -1) {
        reqBody.write(b);
      }
      return b;
    }

    @Override
    public void setReadListener(ReadListener readListener) {
      inputStream.setReadListener(readListener);
    }

    @Override
    public boolean isReady() {
      return inputStream.isReady();
    }

    @Override
    public boolean isFinished() {
      return inputStream.isFinished();
    }
  };
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:31,代码来源:AccessLogFilter.java

示例2: testGetInputStream

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
@Test
public void testGetInputStream() throws IOException {
  Buffer body = Buffer.buffer();
  body.appendByte((byte) 1);

  new Expectations() {
    {
      context.getBody();
      result = body;
    }
  };

  ServletInputStream is = request.getInputStream();
  Assert.assertSame(is, request.getInputStream());
  int value = is.read();
  is.close();
  Assert.assertEquals(1, value);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestVertxServerRequestToHttpServletRequest.java

示例3: getReqParaMap

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
/**
 * 获取客户端get/post方法上传来的参数信息,并转换为
 * <code>map<String,String></code>形式
 */
private HashMap<String, String> getReqParaMap(ServletInputStream is) throws IOException {
    byte[] buf = new byte[1024];
    int len;
    StringBuffer sb = new StringBuffer();
    while ((len = is.read(buf)) != -1) {
        sb.append(new String(buf, 0, len));
    }

    String paraStr = sb.toString();
    HashMap<String, String> paraMap = new HashMap<>();
    if (paraStr.length() > 0) {
        String[] split = paraStr.split("&");
        for (String aSplit : split) {
            String[] entry = aSplit.split("=");
            paraMap.put(entry[0], entry[1]);
        }
    }
    return paraMap;
}
 
开发者ID:lucid-lynxz,项目名称:Webhook_server,代码行数:24,代码来源:ApiServlet.java

示例4: readRpcBody

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
private Message readRpcBody(ServletInputStream in,
                            Class<? extends Message> requestClass) throws Exception {
    byte chunkSize[] = new byte[4];
    in.read(chunkSize);
    int size = Ints.fromByteArray(chunkSize);
    if (size == 0) {
        return ProtobufUtil.newEmptyMessage(requestClass);
    }
    if (size > ProtobufUtil.MAX_BODY_CHUNK_SIZE) {
        String message = "Invalid body chunk size: " + size;
        throw new RpcReadException(chunkSize, in, message);
    }
    byte bodyData[] = readyFully(in, size);
    Message pbRequest = ProtobufUtil.byteArrayToProtobuf(bodyData, requestClass);
    return pbRequest;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:17,代码来源:ProtobufHandler.java

示例5: readyFully

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
private byte[] readyFully(ServletInputStream in, int totalSize) throws Exception {
    byte[] retval = new byte[totalSize];
    int bytesRead = 0;
    while (bytesRead < totalSize) {
        try {
            int read = in.read(retval, bytesRead, totalSize - bytesRead);
            if (read == -1) {
                throw new RpcCallException(RpcCallException.Category.InternalServerError,
                        "Unable to read complete request or response");
            }
            bytesRead += read;
        } catch (IOException e) {
            throw new RpcCallException(RpcCallException.Category.InternalServerError,
                    "IOException reading data: " + e);
        }
    }
    return retval;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:19,代码来源:ProtobufHandler.java

示例6: readRequestData

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
@Override
public IoFuture<byte[]> readRequestData() {
    final ByteArrayOutputStream data = new ByteArrayOutputStream();
    try {
        final ServletInputStream in = request.getInputStream();
        byte[] buf = new byte[1024];
        int r;
        while ((r = in.read(buf)) != -1) {
            data.write(buf, 0, r);
        }
        return new FinishedIoFuture<>(data.toByteArray());
    } catch (IOException e) {
        final FutureResult<byte[]> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletWebSocketHttpExchange.java

示例7: readRpcEnvelope

import javax.servlet.ServletInputStream; //导入方法依赖的package包/类
private RpcEnvelope.Request readRpcEnvelope(ServletInputStream in) throws Exception {
    byte chunkSize[] = new byte[4];
    in.read(chunkSize);
    int size = Ints.fromByteArray(chunkSize);
    if (size <= 0 || size > ProtobufUtil.MAX_HEADER_CHUNK_SIZE) {
        String message = "Invalid header chunk size: " + size;
        throw new RpcReadException(chunkSize, in, message);
    }
    byte headerData[] = readyFully(in, size);
    RpcEnvelope.Request rpcRequest = RpcEnvelope.Request.parseFrom(headerData);
    return rpcRequest;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:13,代码来源:ProtobufHandler.java


注:本文中的javax.servlet.ServletInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。