Exemple #1
0
 public InputStreamWrapper(InputStream is, byte[] boundary) {
   _wrapped = is;
   _boundary = Arrays.copyOf(BOUNDARY_PREFIX, BOUNDARY_PREFIX.length + boundary.length);
   System.arraycopy(boundary, 0, _boundary, BOUNDARY_PREFIX.length, boundary.length);
   _lookAheadBuf = new byte[_boundary.length];
   _lookAheadLen = 0;
 }
Exemple #2
0
    private int readInternal(byte b[], int off, int len) throws IOException {
      if (len < _lookAheadLen) {
        System.arraycopy(_lookAheadBuf, 0, b, off, len);
        _lookAheadLen -= len;
        System.arraycopy(_lookAheadBuf, len, _lookAheadBuf, 0, _lookAheadLen);
        return len;
      }

      if (_lookAheadLen > 0) {
        System.arraycopy(_lookAheadBuf, 0, b, off, _lookAheadLen);
        off += _lookAheadLen;
        len -= _lookAheadLen;
        int r = Math.max(_wrapped.read(b, off, len), 0) + _lookAheadLen;
        _lookAheadLen = 0;
        return r;
      } else {
        return _wrapped.read(b, off, len);
      }
    }