本文整理汇总了Java中javax.servlet.ReadListener类的典型用法代码示例。如果您正苦于以下问题:Java ReadListener类的具体用法?Java ReadListener怎么用?Java ReadListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadListener类属于javax.servlet包,在下文中一共展示了ReadListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputStream
import javax.servlet.ReadListener; //导入依赖的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: setReadListener
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
public void setReadListener(final ReadListener readListener) {
if (readListener == null) {
throw UndertowServletMessages.MESSAGES.listenerCannotBeNull();
}
if (listener != null) {
throw UndertowServletMessages.MESSAGES.listenerAlreadySet();
}
listener = readListener;
channel.getReadSetter().set(new ServletInputStreamChannelListener());
//we resume from an async task, after the request has been dispatched
ioExecutor.execute(new Runnable() {
@Override
public void run() {
channel.wakeupReads();
}
});
}
示例3: getInputStream
import javax.servlet.ReadListener; //导入依赖的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();
}
};
}
示例4: getInputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
return new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
private TeeInputStream tee = new TeeInputStream(RequestWrapper.super.getInputStream(), bos);
@Override
public int read() throws IOException {
return tee.read();
}
};
}
示例5: getInputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
public ServletInputStream getInputStream() {
ByteArrayInputStream body = new ByteArrayInputStream(
builder.toString().getBytes());
return new ServletInputStream() {
@Override
public int read() throws IOException {
return body.read();
}
@Override
public void setReadListener(ReadListener listener) {
}
@Override
public boolean isReady() {
return true;
}
@Override
public boolean isFinished() {
return body.available() <= 0;
}
};
}
示例6: getInputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
return new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
private TeeInputStream tee = new TeeInputStream(RequestWrapper.super.getInputStream(), bos, true);
@Override
public int read() throws IOException {
return tee.read();
}
};
}
示例7: start
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
void start() {
input.setReadListener(new ReadListener() {
@Override
public void onDataAvailable() throws IOException {
read();
}
@Override
public void onAllDataRead() throws IOException {
end();
}
@Override
public void onError(Throwable t) {
errorActions.fire(t);
}
});
}
示例8: getInputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
return new ServletInputStream() {
@Override
public boolean isFinished() {
return byteArrayInputStream.available() == 0;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener listener) {
throw new RuntimeException("Not implemented");
}
public int read() throws IOException {
return byteArrayInputStream.read();
}
};
}
示例9: getInputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getPayload());
return new ServletInputStream() {
@Override
public int read() throws IOException {
return byteArrayInputStream.read();
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener listener) {
//
}
};
}
示例10: createServletOutputStream
import javax.servlet.ReadListener; //导入依赖的package包/类
ServletInputStream createServletOutputStream() {
final ByteArrayInputStream stream = new ByteArrayInputStream(body.getBytes());
// CHECKSTYLE:OFF
return new ServletInputStream() {
// CHECKSTYLE:ON
@Override
public int read() throws IOException {
return stream.read();
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
// nothing
}
};
}
示例11: withRequestBody
import javax.servlet.ReadListener; //导入依赖的package包/类
public void withRequestBody(String requestBody) throws IOException {
final ByteArrayInputStream in = new ByteArrayInputStream(requestBody.getBytes());
when(req.getInputStream()).then(new Answer<ServletInputStream>() {
@Override
public ServletInputStream answer(InvocationOnMock invocation) throws Throwable {
return new ServletInputStream() {
@Override
public int read() throws IOException {
return in.read();
}
@Override
public void setReadListener(ReadListener readListener) {
try {
readListener.onDataAvailable();
readListener.onAllDataRead();
} catch (IOException letItCrash) {
throw new RuntimeException(letItCrash);
}
}
@Override
public boolean isReady() {
return true;
}
@Override
public boolean isFinished() {
return in.available() > 0;
}
};
}
});
}
示例12: start
import javax.servlet.ReadListener; //导入依赖的package包/类
@Override
void start() {
input.setReadListener(new ReadListener() {
@Override
public void onDataAvailable() throws IOException {
read();
}
@Override
public void onAllDataRead() throws IOException {
end();
}
@Override
public void onError(Throwable t) {
errorActions.fire(t);
}
});
}
示例13: whenDataAvailableExpectReadBytesPublishedToSubscriber
import javax.servlet.ReadListener; //导入依赖的package包/类
/**
* TBD
* @throws Exception
*/
@Test public void whenDataAvailableExpectReadBytesPublishedToSubscriber() throws Exception {
List<Byte> expectedValues = Arrays.asList((byte)2, (byte)47);
AnswerArg1<ReadListener> answer = new AnswerArg1<>();
BufferedSubscriber<byte[]> bufferedSubscriber = new BufferedSubscriber<>();
// mock setup
// receive setReadListener's argument
Mockito
.doAnswer(answer)
.when(servletInputStreamMock).setReadListener(Mockito.any(ReadListener.class));
// return one byte on ServletInputStream.read
when(servletInputStreamMock.read())
.thenReturn(2)
.thenReturn(47);
when(servletInputStreamMock.isReady())
.thenReturn(true)
.thenReturn(true)
.thenReturn(false);
servletInputStreamPublisherAdapter.startReading();
servletInputStreamPublisherAdapter.subscribe(bufferedSubscriber);
// inform about data availability
answer.getArg().onDataAvailable();
// asserts
List<byte[]> receivedByteList = bufferedSubscriber.toList();
Assert.assertThat(receivedByteList.size(), CoreMatchers.equalTo(2));
// Assert.assertThat(receivedByteList, CoreMatchers.hasItem((byte)2));
// Assert.assertThat(receivedByteList, CoreMatchers.hasItem((byte)47));
}
示例14: whenNoMoreDataAvailableOnCompletedCalled
import javax.servlet.ReadListener; //导入依赖的package包/类
@Test public void whenNoMoreDataAvailableOnCompletedCalled() throws Exception {
AnswerArg1<ReadListener> answer = new AnswerArg1<>();
BufferedSubscriber<Object> bufferedSubscriber = new BufferedSubscriber<>();
// mock setup
// receive setReadListener's argument
Mockito
.doAnswer(answer)
.when(servletInputStreamMock).setReadListener(Mockito.any(ReadListener.class));
// return one byte on ServletInputStream.read
when(servletInputStreamMock.read())
.thenReturn(-1);
when(servletInputStreamMock.isReady())
.thenReturn(true);
servletInputStreamPublisherAdapter.startReading();
servletInputStreamPublisherAdapter.subscribe(bufferedSubscriber);
// inform about data availability
answer.getArg().onDataAvailable();
// asserts
Assert.assertThat(bufferedSubscriber.isCompleted(), CoreMatchers.equalTo(true));
}
示例15: whenIoExceptionThrownOnReadExpectOnErrorCalled
import javax.servlet.ReadListener; //导入依赖的package包/类
@Test public void whenIoExceptionThrownOnReadExpectOnErrorCalled() throws Exception {
IOException expectedException = new IOException();
AnswerArg1<ReadListener> answer = new AnswerArg1<>();
BufferedSubscriber<Object> bufferedSubscriber = new BufferedSubscriber<>();
// mock setup
// receive setReadListener's argument
Mockito
.doAnswer(answer)
.when(servletInputStreamMock).setReadListener(Mockito.any(ReadListener.class));
// return one byte on ServletInputStream.read
when(servletInputStreamMock.read())
.thenThrow(expectedException);
when(servletInputStreamMock.isReady())
.thenReturn(true);
servletInputStreamPublisherAdapter.startReading();
servletInputStreamPublisherAdapter.subscribe(bufferedSubscriber);
// inform about data availability
answer.getArg().onDataAvailable();
// asserts
Assert.assertThat(bufferedSubscriber.getException(), CoreMatchers.equalTo(expectedException));
}