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


Java ServletInputStream类代码示例

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


ServletInputStream类属于javax.servlet包,在下文中一共展示了ServletInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getInputStreamCache

import javax.servlet.ServletInputStream; //导入依赖的package包/类
@Test
public void getInputStreamCache() throws IOException {
  requestEx.setCacheRequest(true);

  ServletInputStream inputStream = request.getInputStream();
  new Expectations(IOUtils.class) {
    {
      IOUtils.toByteArray(inputStream);
      result = "abc".getBytes();
    }
  };

  ServletInputStream cachedInputStream = requestEx.getInputStream();
  Assert.assertEquals("abc", IOUtils.toString(cachedInputStream));
  Assert.assertEquals("abc", requestEx.getBodyBuffer().toString());
  // do not create another one
  Assert.assertSame(cachedInputStream, requestEx.getInputStream());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestStandardHttpServletRequestEx.java

示例3: 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

示例4: 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

示例5: getWrappedHttpServletRequest

import javax.servlet.ServletInputStream; //导入依赖的package包/类
private static HttpServletRequest getWrappedHttpServletRequest(HttpServletRequest request) throws IOException
{
    //TODO is it really necessary to wrap the request into a BufferedInputStream?
    // If not, then we could remove the check for multipart upload. 
    // The check is needed as we get an IOException (Resetting to invalid mark) for files more than 8193 bytes. 
    boolean resetSupported = true;
    String contentType = request.getHeader(HEADER_CONTENT_TYPE);
    if (contentType != null && contentType.startsWith(MULTIPART_FORM_DATA))
    {
       resetSupported = false;
    }
    final PublicApiServletInputStream sis = new PublicApiServletInputStream(request.getInputStream(), resetSupported);
    HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request)
    {
        public ServletInputStream getInputStream() throws java.io.IOException
        {
            return sis;
        }
    };
    return wrapper;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:22,代码来源:PublicApiHttpServletRequest.java

示例6: getInputStream

import javax.servlet.ServletInputStream; //导入依赖的package包/类
/**
 * Return the servlet input stream for this Request.  The default
 * implementation returns a servlet input stream created by
 * <code>createInputStream()</code>.
 *
 * @exception IllegalStateException if <code>getReader()</code> has
 *  already been called for this request
 * @exception IOException if an input/output error occurs
 */
@Override
public ServletInputStream getInputStream() throws IOException {

    if (usingReader) {
        throw new IllegalStateException
            (sm.getString("coyoteRequest.getInputStream.ise"));
    }

    usingInputStream = true;
    if (inputStream == null) {
        inputStream = new CoyoteInputStream(inputBuffer);
    }
    return inputStream;

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:Request.java

示例7: 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

示例8: 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

示例9: testBodyReading

import javax.servlet.ServletInputStream; //导入依赖的package包/类
public void testBodyReading(String first, String second) throws IOException {
    ServletInputStream x = (ServletInputStream) new RpcHandlerTest_InputStream(second);
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Map<String, Set<String>> headers = new TreeMap<>();
    when(request.getHeaderNames())
            .thenReturn(
                    new RpcReadExceptionTest.RpcHandlerTest_IteratorEnumeration<>(headers.keySet().iterator())
            );

    when(request.getInputStream()).thenReturn(x);
    when(request.getRequestURL())
            .thenReturn(new StringBuffer("http://fizz.buzz"));

    RpcReadException rpcReadException = new RpcReadException(first.getBytes(), x, "i am a message");
    String json = rpcReadException.toJson(request);

    try {
        JsonElement root = new JsonParser().parse(json);
        JsonObject jsob = root.getAsJsonObject();
        JsonElement b = jsob.get("request_body");
        Assert.assertNotNull(b);
        Assert.assertEquals(first+second, this.decode(b.getAsString()));
    } catch (Exception ex) {
        Assert.fail(ex.toString());
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:27,代码来源:RpcReadExceptionTest.java

示例10: onDataInRequestShouldReturnThisData

import javax.servlet.ServletInputStream; //导入依赖的package包/类
@Test
public void onDataInRequestShouldReturnThisData() throws Exception {
	// GIVEN
	final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("hello".getBytes());
	when(request.getInputStream()).thenReturn(new ServletInputStream() {
		@Override
		public int read() throws IOException {
			return byteArrayInputStream.read();
		}
	});

	// WHEN
	BufferedRequestWrapper sut = new BufferedRequestWrapper(request);
	ServletInputStream inputStream = sut.getInputStream();

	// THEN
	assertThat(inputStream).hasSameContentAs(new ByteArrayInputStream("hello".getBytes()));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:19,代码来源:BufferedRequestWrapperTest.java

示例11: testMissingParameters

import javax.servlet.ServletInputStream; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
@Test(expected = IllegalArgumentException.class)
public void testMissingParameters() throws Exception {
  Map requestParameterMap = new HashMap();

  HttpServletRequest req = mock(HttpServletRequest.class);
  final String tabData = "a\tb\tc";

  ServletInputStream servletInputStream = new DelegatingServletInputStream(
      new ByteArrayInputStream(tabData.getBytes()));

  when(req.getInputStream()).thenReturn(servletInputStream);
  when(req.getParameterMap()).thenReturn(requestParameterMap);

  Context context = mock(Context.class);
  when(
      context.getString(BLOBHandler.MANDATORY_PARAMETERS,
          BLOBHandler.DEFAULT_MANDATORY_PARAMETERS)).thenReturn("param1");

  handler.configure(context);

  handler.getEvents(req);

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:TestBLOBHandler.java

示例12: 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

示例13: putObject

import javax.servlet.ServletInputStream; //导入依赖的package包/类
/**
 * Adds an object to a bucket.
 *
 * http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
 *
 * @param bucketName the Bucket in which to store the file in.
 * @param request http servlet request
 * @return ResponseEntity with Status Code and ETag
 */
@RequestMapping(value = "/{bucketName:.+}/**", method = RequestMethod.PUT)
public ResponseEntity<String> putObject(@PathVariable final String bucketName,
    final HttpServletRequest request) {
  final String filename = filenameFrom(bucketName, request);
  try (ServletInputStream inputStream = request.getInputStream()) {
    final S3Object s3Object = fileStore.putS3Object(bucketName,
        filename,
        request.getContentType(),
        inputStream,
        isV4SigningEnabled(request));

    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setETag("\"" + s3Object.getMd5() + "\"");
    responseHeaders.setLastModified(s3Object.getLastModified());
    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
  } catch (final IOException e) {
    LOG.error("Object could not be saved!", e);
    return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
  }
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:30,代码来源:FileStoreController.java

示例14: getInputStream

import javax.servlet.ServletInputStream; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream () throws IOException {
    if ( null == body ) {
        return super.getInputStream();
    }
    final ByteArrayInputStream inputStream = new ByteArrayInputStream( body );
    return new ServletInputStream() {
        @Override
        public boolean isFinished () {
            return false;
        }

        @Override
        public boolean isReady () {
            return false;
        }

        @Override
        public void setReadListener ( ReadListener readListener ) {

        }

        @Override
        public int read () throws IOException {
            return inputStream.read();
        }
    };
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:29,代码来源:BodyReaderWrapper.java

示例15: getInputStream

import javax.servlet.ServletInputStream; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
  if (inputStream == null) {
    inputStream = new BufferInputStream(context.getBody().getByteBuf());
  }
  return inputStream;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:VertxServerRequestToHttpServletRequest.java


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