test_class.file: dubbo-common/src/test/java/com/alibaba/dubbo/common/io/StreamUtilsTest.java
test_class.identifier: StreamUtilsTest
test_case.body: @Test
      public void testLimitedInputStream() throws Exception {
          InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
          assertThat(10, is(is.available()));
  
          is = StreamUtils.limitedInputStream(is, 2);
          assertThat(2, is(is.available()));
          assertThat(is.markSupported(), is(true));
  
          is.mark(0);
          assertEquals((int) '0', is.read());
          assertEquals((int) '1', is.read());
          assertEquals(-1, is.read());
  
          is.reset();
          is.skip(1);
          assertEquals((int) '1', is.read());
  
          is.reset();
          is.skip(-1);
          assertEquals((int) '0', is.read());
  
          is.reset();
          byte[] bytes = new byte[2];
          int read = is.read(bytes, 1, 1);
          assertThat(read, is(1));
  
          is.reset();
          StreamUtils.skipUnusedStream(is);
          assertEquals(-1, is.read());
  
          is.close();
      }
test_case.class_method_signature: StreamUtilsTest.testLimitedInputStream()
test_case.full_signature: @Test public void testLimitedInputStream()
test_case.identifier: testLimitedInputStream
test_case.invocations: getResourceAsStream assertThat is available limitedInputStream assertThat is available assertThat markSupported is mark assertEquals read assertEquals read assertEquals read reset skip assertEquals read reset skip assertEquals read reset read assertThat is reset skipUnusedStream assertEquals read close
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLimitedInputStream()
focal_class.file: dubbo-common/src/main/java/com/alibaba/dubbo/common/io/StreamUtils.java
focal_class.identifier: StreamUtils
focal_class.class_method_signature: StreamUtils.StreamUtils()
focal_class.full_signature: private  StreamUtils()
focal_class.identifier: StreamUtils
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  StreamUtils()
focal_class.class_method_signature: StreamUtils.limitedInputStream(final InputStream is, final int limit)
focal_class.full_signature: public static InputStream limitedInputStream(final InputStream is, final int limit)
focal_class.identifier: limitedInputStream
focal_class.modifiers: public static
focal_class.parameters: (final InputStream is, final int limit)
focal_class.return: InputStream
focal_class.signature: InputStream limitedInputStream(final InputStream is, final int limit)
focal_class.class_method_signature: StreamUtils.markSupportedInputStream(final InputStream is, final int markBufferSize)
focal_class.full_signature: public static InputStream markSupportedInputStream(final InputStream is, final int markBufferSize)
focal_class.identifier: markSupportedInputStream
focal_class.modifiers: public static
focal_class.parameters: (final InputStream is, final int markBufferSize)
focal_class.return: InputStream
focal_class.signature: InputStream markSupportedInputStream(final InputStream is, final int markBufferSize)
focal_class.class_method_signature: StreamUtils.markSupportedInputStream(final InputStream is)
focal_class.full_signature: public static InputStream markSupportedInputStream(final InputStream is)
focal_class.identifier: markSupportedInputStream
focal_class.modifiers: public static
focal_class.parameters: (final InputStream is)
focal_class.return: InputStream
focal_class.signature: InputStream markSupportedInputStream(final InputStream is)
focal_class.class_method_signature: StreamUtils.skipUnusedStream(InputStream is)
focal_class.full_signature: public static void skipUnusedStream(InputStream is)
focal_class.identifier: skipUnusedStream
focal_class.modifiers: public static
focal_class.parameters: (InputStream is)
focal_class.return: void
focal_class.signature: void skipUnusedStream(InputStream is)
focal_method.body: public static InputStream limitedInputStream(final InputStream is, final int limit) throws IOException {
          return new InputStream() {
              private int mPosition = 0, mMark = 0, mLimit = Math.min(limit, is.available());
  
              @Override
              public int read() throws IOException {
                  if (mPosition < mLimit) {
                      mPosition++;
                      return is.read();
                  }
                  return -1;
              }
  
              @Override
              public int read(byte b[], int off, int len) throws IOException {
                  if (b == null)
                      throw new NullPointerException();
  
                  if (off < 0 || len < 0 || len > b.length - off)
                      throw new IndexOutOfBoundsException();
  
                  if (mPosition >= mLimit)
                      return -1;
  
                  if (mPosition + len > mLimit)
                      len = mLimit - mPosition;
  
                  if (len <= 0)
                      return 0;
  
                  is.read(b, off, len);
                  mPosition += len;
                  return len;
              }
  
              @Override
              public long skip(long len) throws IOException {
                  if (mPosition + len > mLimit)
                      len = mLimit - mPosition;
  
                  if (len <= 0)
                      return 0;
  
                  is.skip(len);
                  mPosition += len;
                  return len;
              }
  
              @Override
              public int available() {
                  return mLimit - mPosition;
              }
  
              @Override
              public boolean markSupported() {
                  return is.markSupported();
              }
  
              @Override
              public void mark(int readlimit) {
                  is.mark(readlimit);
                  mMark = mPosition;
              }
  
              @Override
              public void reset() throws IOException {
                  is.reset();
                  mPosition = mMark;
              }
  
              @Override
              public void close() throws IOException {
              }
          };
      }
focal_method.class_method_signature: StreamUtils.limitedInputStream(final InputStream is, final int limit)
focal_method.full_signature: public static InputStream limitedInputStream(final InputStream is, final int limit)
focal_method.identifier: limitedInputStream
focal_method.invocations: min available read read skip markSupported mark reset
focal_method.modifiers: public static
focal_method.parameters: (final InputStream is, final int limit)
focal_method.return: InputStream
focal_method.signature: InputStream limitedInputStream(final InputStream is, final int limit)