當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadListener類代碼示例

本文整理匯總了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();
    }
  };
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:31,代碼來源:AccessLogFilter.java

示例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();
        }
    });
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:UpgradeServletInputStream.java

示例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();
        }
    };
}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:29,代碼來源:BodyReaderWrapper.java

示例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();
        }
    };
}
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:27,代碼來源:RequestWrapper.java

示例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;
		}
	};
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-gateway,代碼行數:26,代碼來源:ProxyExchange.java

示例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();
        }
    };
}
 
開發者ID:ismartx,項目名稱:summer,代碼行數:27,代碼來源:RequestWrapper.java

示例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);
    }
  });
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:20,代碼來源:AtmosphereServerHttpExchange.java

示例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();
    }
  };
}
 
開發者ID:openbaton,項目名稱:NFVO,代碼行數:25,代碼來源:CustomHttpServletRequestWrapper.java

示例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) {
            //
        }
    };
}
 
開發者ID:kpavlov,項目名稱:spring-hmac-rest,代碼行數:27,代碼來源:CachingRequestWrapper.java

示例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
		}
	};
}
 
開發者ID:javamelody,項目名稱:javamelody,代碼行數:27,代碼來源:TestPayloadNameRequestWrapper.java

示例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;
                }
            };
        }
    });
}
 
開發者ID:bgandon,項目名稱:killbill-simple-tax-plugin,代碼行數:37,代碼來源:ServletMocks.java

示例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);
        }
    });
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:20,代碼來源:AtmosphereServerHttpExchange.java

示例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));
  }
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:41,代碼來源:ServletInputStreamPublisherAdapterTest.java

示例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));
  }
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:29,代碼來源:ServletInputStreamPublisherAdapterTest.java

示例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));
}
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:30,代碼來源:ServletInputStreamPublisherAdapterTest.java


注:本文中的javax.servlet.ReadListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。