Java Code Examples for javax.servlet.ServletInputStream#isReady()

The following examples show how to use javax.servlet.ServletInputStream#isReady() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestNonBlockingAPI.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void onDataAvailable() throws IOException {
    ServletInputStream in = ctx.getRequest().getInputStream();
    String s = "";
    byte[] b = new byte[8192];
    int read = 0;
    do {
        read = in.read(b);
        if (read == -1) {
            break;
        }
        s += new String(b, 0, read);
    } while (ignoreIsReady || in.isReady());
    log.info(s);
    body.append(s);
}
 
Example 2
Source File: TestNonBlockingAPI.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void onDataAvailable() throws IOException {
    ServletInputStream in = ctx.getRequest().getInputStream();
    String s = "";
    byte[] b = new byte[8192];
    int read = 0;
    do {
        read = in.read(b);
        if (read == -1) {
            break;
        }
        s += new String(b, 0, read);
    } while (in.isReady());
    log.info("Read [" + s + "]");
    body.append(s);
}
 
Example 3
Source File: SockJsServletRequest.java    From AngularBeans with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDataAvailable() throws IOException {
	ServletInputStream inputStream = request.getInputStream();
	do {
		while (!inputStream.isReady()) {
			//
		}

		byte[] buffer = new byte[1024 * 4];
		int length = inputStream.read(buffer);
		if (length > 0) {
			if (onDataHandler != null) {
				try {
					onDataHandler.handle(Arrays.copyOf(buffer, length));
				} catch (SockJsException e) {
					throw new IOException(e);
				}
			}
		}
	} while (inputStream.isReady());
}
 
Example 4
Source File: AccessLogFilter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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();
    }
  };
}