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 testMarkSupportedInputStream() throws Exception {
          InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
          assertEquals(10, is.available());
  
          is = new PushbackInputStream(is);
          assertEquals(10, is.available());
          assertFalse(is.markSupported());
  
          is = StreamUtils.markSupportedInputStream(is);
          assertEquals(10, is.available());
  
          is.mark(0);
          assertEquals((int) '0', is.read());
          assertEquals((int) '1', is.read());
  
          is.reset();
          assertEquals((int) '0', is.read());
          assertEquals((int) '1', is.read());
          assertEquals((int) '2', is.read());
  
          is.mark(0);
          assertEquals((int) '3', is.read());
          assertEquals((int) '4', is.read());
          assertEquals((int) '5', is.read());
  
          is.reset();
          assertEquals((int) '3', is.read());
          assertEquals((int) '4', is.read());
  
          is.mark(0);
          assertEquals((int) '5', is.read());
          assertEquals((int) '6', is.read());
  
          is.reset();
          assertEquals((int) '5', is.read());
          assertEquals((int) '6', is.read());
          assertEquals((int) '7', is.read());
          assertEquals((int) '8', is.read());
          assertEquals((int) '9', is.read());
          assertEquals(-1, is.read());
          assertEquals(-1, is.read());
  
          is.mark(0);
          assertEquals(-1, is.read());
          assertEquals(-1, is.read());
  
          is.reset();
          assertEquals(-1, is.read());
          assertEquals(-1, is.read());
      }
test_case.class_method_signature: StreamUtilsTest.testMarkSupportedInputStream()
test_case.full_signature: @Test public void testMarkSupportedInputStream()
test_case.identifier: testMarkSupportedInputStream
test_case.invocations: getResourceAsStream assertEquals available assertEquals available assertFalse markSupported markSupportedInputStream assertEquals available mark assertEquals read assertEquals read reset assertEquals read assertEquals read assertEquals read mark assertEquals read assertEquals read assertEquals read reset assertEquals read assertEquals read mark assertEquals read assertEquals read reset assertEquals read assertEquals read assertEquals read assertEquals read assertEquals read assertEquals read assertEquals read mark assertEquals read assertEquals read reset assertEquals read assertEquals read
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMarkSupportedInputStream()
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 markSupportedInputStream(final InputStream is, final int markBufferSize) {
          if (is.markSupported()) {
              return is;
          }
  
          return new InputStream() {
              byte[] mMarkBuffer;
  
              boolean mInMarked = false;
              boolean mInReset = false;
              boolean mDry = false;
              private int mPosition = 0;
              private int mCount = 0;
  
              @Override
              public int read() throws IOException {
                  if (!mInMarked) {
                      return is.read();
                  } else {
                      if (mPosition < mCount) {
                          byte b = mMarkBuffer[mPosition++];
                          return b & 0xFF;
                      }
  
                      if (!mInReset) {
                          if (mDry) return -1;
  
                          if (null == mMarkBuffer) {
                              mMarkBuffer = new byte[markBufferSize];
                          }
                          if (mPosition >= markBufferSize) {
                              throw new IOException("Mark buffer is full!");
                          }
  
                          int read = is.read();
                          if (-1 == read) {
                              mDry = true;
                              return -1;
                          }
  
                          mMarkBuffer[mPosition++] = (byte) read;
                          mCount++;
  
                          return read;
                      } else {
                          // mark buffer is used, exit mark status!
                          mInMarked = false;
                          mInReset = false;
                          mPosition = 0;
                          mCount = 0;
  
                          return is.read();
                      }
                  }
              }
  
              /**
               * NOTE: the <code>readlimit</code> argument for this class
               *  has no meaning.
               */
              @Override
              public synchronized void mark(int readlimit) {
                  mInMarked = true;
                  mInReset = false;
  
                  // mark buffer is not empty
                  int count = mCount - mPosition;
                  if (count > 0) {
                      System.arraycopy(mMarkBuffer, mPosition, mMarkBuffer, 0, count);
                      mCount = count;
                      mPosition = 0;
                  }
              }
  
              @Override
              public synchronized void reset() throws IOException {
                  if (!mInMarked) {
                      throw new IOException("should mark befor reset!");
                  }
  
                  mInReset = true;
                  mPosition = 0;
              }
  
              @Override
              public boolean markSupported() {
                  return true;
              }
  
              @Override
              public int available() throws IOException {
                  int available = is.available();
  
                  if (mInMarked && mInReset) available += mCount - mPosition;
  
                  return available;
              }
          };
      }
focal_method.class_method_signature: StreamUtils.markSupportedInputStream(final InputStream is, final int markBufferSize)
focal_method.full_signature: public static InputStream markSupportedInputStream(final InputStream is, final int markBufferSize)
focal_method.identifier: markSupportedInputStream
focal_method.invocations: markSupported read read read arraycopy available
focal_method.modifiers: public static
focal_method.parameters: (final InputStream is, final int markBufferSize)
focal_method.return: InputStream
focal_method.signature: InputStream markSupportedInputStream(final InputStream is, final int markBufferSize)