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