本文整理匯總了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();
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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()));
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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();
}
};
}
示例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