当前位置: 首页>>代码示例>>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;未经允许,请勿转载。