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