## com.baidubce.util
Class LengthCheckInputStream

    java.lang.Object
      java.io.InputStream
          java.io.FilterInputStream
              com.baidubce.util.LengthCheckInputStream

All Implemented Interfaces:
  Closeable

    @NotThreadSafe
    public class LengthCheckInputStream

extends FilterInputStream

Used to perform length check to ensure the number of bytes read from the underlying input stream is the same as the expected total.

Field Summary
`static boolean` `EXCLUDE_SKIPPED_BYTES`
`static boolean` `INCLUDE_SKIPPED_BYTES`

Fields inherited from class java.io.FilterInputStream
`in`

Constructor Summary
`LengthCheckInputStream(InputStream in, long expectedLength, boolean includeSkipped)` Constructs an input stream that performs length check to ensure the number of bytes read from the underlying input stream is the same as the expected total.

Method Summary
`void` `mark(int readlimit)`
`int` `read()`
`int` `read(byte[] b, int off, int len)`
`void` `reset()`
`long` `skip(long n)`

Methods inherited from class java.io.FilterInputStream
`available, close, markSupported, read`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### INCLUDE_SKIPPED_BYTES

    public static final boolean INCLUDE_SKIPPED_BYTES

See Also:
  Constant Field Values

### EXCLUDE_SKIPPED_BYTES

    public static final boolean EXCLUDE_SKIPPED_BYTES

See Also:
  Constant Field Values

Constructor Detail

### LengthCheckInputStream

    public LengthCheckInputStream(InputStream in,
                                  long expectedLength,
                                  boolean includeSkipped)

  Constructs an input stream that performs length check to ensure the number of bytes read from the underlying input stream is the same as the expected total.

  Parameters:
    `in` - the underlying input stream
    `expectedLength` - the total length of the data in bytes expected to be read from the underlying input stream; must be non-negative.
    `includeSkipped` - true if bytes skipped are to be considered as part of the data length; false otherwise. Typically, this parameter should be set to false for uploading data to BCE, but set to true for receiving data from BCE.

Method Detail

### read

    public int read()
             throws IOException

  Overrides:
    `read` in class `FilterInputStream`
  Throws:
    `BceClientException` - if the data length read has exceeded the expected total, or if the total data length is not the same as the expected total.
    `IOException`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws IOException

  Overrides:
    `read` in class `FilterInputStream`
  Throws:
    `BceClientException` - if the data length read has exceeded the expected total, or if the total data length is not the same as the expected total.
    `IOException`

### mark

    public void mark(int readlimit)

  Overrides:
    `mark` in class `FilterInputStream`

### reset

    public void reset()
               throws IOException

  Overrides:
    `reset` in class `FilterInputStream`
  Throws:
    `IOException`

### skip

    public long skip(long n)
              throws IOException

  Overrides:
    `skip` in class `FilterInputStream`
  Throws:
    `BceClientException` - if `includeSkipped` is true and the data length skipped has exceeded the expected total.
    `IOException`

Copyright © 2016. All rights reserved.