读取指定流从某处开始的内容，此函数有一定的风险，如果流对应的内容过大，则会造成OOM

@param inputStream
@param offset 读取的开始偏移
@param length 读取的长度
@return 读取的内容
@throws Exception
480135
public static String getFileContent(InputStream inputStream, long offset, int length)
            throws Exception {
        byte[] fileContent = getFileContentByte(inputStream, offset, length);
        return new String(fileContent, Charset.forName("ISO-8859-1"));
    }
324122
public static String readFromInputStream(InputStream inputStream) {
        try {
            return IOUtils.toString(inputStream, Charset.forName("utf-8")).trim();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
1304294
public int read(long fileOffset, byte []buffer, int offset, int length)
    throws IOException
  {
    log.info("random-read(0x" + Long.toHexString(fileOffset) + "," + 
             length + ")");
    
    return _file.read(fileOffset, buffer, offset, length);
  }
206193
public static String read(InputStream is, int off, int len) throws IOException {
        byte[] bs = new byte[len];
        is.read(bs, off, len);
        return new String(bs);
    }
857395
@Override
  public int read(byte[] buffer, int offset, int length) throws IOException
  {
    int b = -1;

    if (_isPartDone)
      return -1;

    int i = 0;
    // Need the last peek or would miss the initial '\n'
    while (_peekOffset + 1 < _peekLength && length > 0) {
      buffer[offset + i++] = _peek[_peekOffset++];
      length--;
    }

    while (i < length && (b = read()) >= 0) {
      boolean hasCr = false;

      if (b == '\r') {
        hasCr = true;
        b = read();

        // XXX: Macintosh?
        if (b != '\n') {
          buffer[offset + i++] = (byte) '\r';
          _peek[0] = (byte) b;
          _peekOffset = 0;
          _peekLength = 1;
          continue;
        }
      }
      else if (b != '\n') {
        buffer[offset + i++] = (byte) b;
        continue;
      }

      int j;
      for (j = 0;
           j < _boundaryLength && (b = read()) >= 0 && _boundaryBuffer[j] == b;
           j++) {
      }

      if (j == _boundaryLength) {
        _isPartDone = true;
        if ((b = read()) == '-') {
          if ((b = read()) == '-') {
            _isDone = true;
            _isComplete = true;
          }
        }

        for (; b > 0 && b != '\r' && b != '\n'; b = read()) {
        }
        if (b == '\r' && (b = read()) != '\n') {
          _peek[0] = (byte) b;
          _peekOffset = 0;
          _peekLength = 1;
        }

        return i > 0 ? i : -1;
      }

      _peekLength = 0;
      if (hasCr && i + 1 < length) {
        buffer[offset + i++] = (byte) '\r';
        buffer[offset + i++] = (byte) '\n';
      }
      else if (hasCr) {
        buffer[offset + i++] = (byte) '\r';
        _peek[_peekLength++] = (byte) '\n';
      }
      else {
        buffer[offset + i++] = (byte) '\n';
      }

      int k = 0;
      while (k < j && i + 1 < length)
        buffer[offset + i++] = _boundaryBuffer[k++];

      while (k < j)
        _peek[_peekLength++] = _boundaryBuffer[k++];

      _peek[_peekLength++] = (byte) b;
      _peekOffset = 0;
    }

    if (i <= 0) {
      _isPartDone = true;
      if (b < 0)
        _isDone = true;
      return -1;
    }
    else {
      return i;
    }
  }
347650
public long write(final InputStream in) throws IOException
	{
		if(in == null) throw new NullPointerException();
		
		final long sizeStart = size;
		while(true) {
			final int n = in.read(buffer, pos, buffer.length - pos);
			if(n < 0) break;
			pos += n;
			size += n;
			if(pos == buffer.length) flushBuffer();
		}
		return(size - sizeStart);
	}
757263
@Nullable
    public static String readUTF(@NotNull final InputStream stream) throws IOException {
        final DataInputStream dataInput = new DataInputStream(stream);
        if (stream instanceof ByteArraySizedInputStream) {
            final ByteArraySizedInputStream sizedStream = (ByteArraySizedInputStream) stream;
            final int streamSize = sizedStream.size();
            if (streamSize >= 2) {
                sizedStream.mark(Integer.MAX_VALUE);
                final int utfLen = dataInput.readUnsignedShort();
                if (utfLen == streamSize - 2) {
                    boolean isAscii = true;
                    final byte[] bytes = sizedStream.toByteArray();
                    for (int i = 0; i < utfLen; ++i) {
                        if ((bytes[i + 2] & 0xff) > 127) {
                            isAscii = false;
                            break;
                        }
                    }
                    if (isAscii) {
                        return fromAsciiByteArray(bytes, 2, utfLen);
                    }
                }
                sizedStream.reset();
            }
        }
        try {
            String result = null;
            StringBuilder builder = null;
            for (; ; ) {
                final String temp;
                try {
                    temp = dataInput.readUTF();
                    if (result != null && result.length() == 0 &&
                        builder != null && builder.length() == 0 && temp.length() == 0) {
                        break;
                    }
                } catch (EOFException e) {
                    break;
                }
                if (result == null) {
                    result = temp;
                } else {
                    if (builder == null) {
                        builder = new StringBuilder();
                        builder.append(result);
                    }
                    builder.append(temp);
                }
            }
            return (builder != null) ? builder.toString() : result;
        } finally {
            dataInput.close();
        }
    }
1338096
function (offset, length) {

                if (arguments.length === 1) {
                    length = arguments[0];
                    offset = this.offset;
                }

                if (length < 0 || offset + length > this.length) {
                    error.raise(10001, this.length, offset + length);
                }

                var buffer = [];
                for (var i = 0; i < length; ++i) {
                    buffer.push(this.view.getUint8(offset + i));
                }

                this.offset = offset + length;
                return buffer;
            }
1229260
public int peek(int offset) throws IOException {
        if(this.count < 0) {
            return EOF;
        }

        if(offset < 0) {
            throw new java.lang.IllegalArgumentException("offset must be >= 0");
        }

        /**
         * 实际请求位置
         */
        int i = this.index + offset;

        if(i < this.count) {
            return this.buffer[i];
        }

        /**
         * �?��读取新数�?         * 先将旧的数据移动到buffer的起始位�?         */
        if(this.index > 0) {
            if(this.count - this.index > 0) {
                System.arraycopy(this.buffer, this.index, this.buffer, 0, this.count - this.index);
            }
            this.count = this.count - this.index;
            this.index = 0;
        }

        /**
         * 如果请求位置超出了buffer容量
         */
        if(offset > this.buffer.length) {
            /**
             * 扩容, 确保容量超过请求位置
             * 新的容量大小是当前bufferSize的�?�?             */
            int bufferSize = (offset / this.buffer.length + 1) * this.buffer.length;
            char[] cbuf = new char[bufferSize];
            System.arraycopy(this.buffer, 0, cbuf, 0, this.count);
            this.buffer = cbuf;
        }

        /**
         * 读取新数�?         */
        int length = this.reader.read(this.buffer, this.count, this.buffer.length - this.count);

        if(length > 0) {
            this.count = this.count + length;
        }

        if(offset < this.count) {
            return this.buffer[offset];
        }
        return EOF;
    }
966565
public void write(char text[], int offset, int length) {
        if ((offset < 0) || (offset > text.length) || (length < 0) || ((offset + length) > text.length) || ((offset + length) < 0)) {
            throw new IndexOutOfBoundsException();
        }
        else if (length == 0) {
            return;
        }
        buffer.append(text, offset, length);
    }
1334014
private InputStream getInputStream(String url) throws Exception {
        HttpGet getMethod = new HttpGet(url);
        DefaultHttpClient client = new DefaultHttpClient(m_cManager);
        client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT_SECONDS * 1000);
        UsernamePasswordCredentials creds = getCreds(url);
        if (creds != null) {
            client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
            client.addRequestInterceptor(new PreemptiveAuth());
        }
        client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
        HttpInputStream in = new HttpInputStream(client, getMethod);
        if (in.getStatusCode() != 200) {
            try {
                in.close();
            } catch (Exception e) {
            }
            throw new IOException("HTTP request failed.  Got status code "
                    + in.getStatusCode()
                    + " from remote server while attempting to GET " + url);
        } else {
            return in;
        }
    }
1321038
@Override
  public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      if (_is == null) {
        if (_s == null) {
          return -1;
        }
        
        _is = _s.getInputStream();
      }

      int readLength = _is.read(buf, offset, length);

      if (readLength >= 0) {
        _totalReadBytes += readLength;
      }

      return readLength;
    } catch (InterruptedIOException e) {
      e.printStackTrace();
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      e.printStackTrace();
      if (_throwReadInterrupts) {
        throw e;
      }

      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
      else {
        log.finer(e.toString());
      }
      // server/0611
      /*
      try {
        close();
      } catch (IOException e1) {
      }
      */
    }

    return -1;
  }
214393
public static byte[] unGzip(InputStream in, int length) throws UtilException {
		GZIPInputStream gzi = null;
		FastByteArrayOutputStream bos = null;
		try {
			gzi = (in instanceof GZIPInputStream) ? (GZIPInputStream)in : new GZIPInputStream(in);
			bos = new FastByteArrayOutputStream(length);
			IoUtil.copy(gzi, bos);
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(gzi);
		}
		//返回必须在关闭gos后进行，因为关闭时会自动执行finish()方法，保证数据全部写出
		return bos.toByteArray();
	}
432365
public static byte[] readStream(InputStream in) {
        if(in == null){
            return null;
        }
        ByteArrayOutputStream out = null;
        try {
            out = new ByteArrayOutputStream();
            byte[] buf = new byte[1024 * 8];
            int length = 0;
            while((length = in.read(buf)) != -1){
                out.write(buf, 0, length);
            }
            return out.toByteArray();

        } catch (IOException e) {
            throw new IORuntimeException(e);

        } finally {
            closeQuietly(in);
            closeQuietly(out);
        }
    }
652136
public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
    return wrap(ByteBuffer.wrap(byteArray, offset, length));
  }
424140
public static byte[] readBytes(byte b[], int offset, int length) {
    byte[] retValue = new byte[length];
    System.arraycopy(b, offset, retValue, 0, length);
    return retValue;
  }
134780
private int ensureBuffer(int offset, int length) throws IOException {
		final int lastPos = offset + length - 1;
		final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE;
		final int currentSize = this.buffer.length;

		if (desiredSize > currentSize) {
			final byte[] readBuffer = new byte[desiredSize - currentSize];
			final int count = this.in.read(readBuffer);

			if (count > 0) {
				final byte[] newBuffer = new byte[currentSize + count];
				System.arraycopy(this.buffer, 0, newBuffer, 0, currentSize);
				System.arraycopy(readBuffer, 0, newBuffer, currentSize, count);
				this.buffer = newBuffer;
			}
			return (lastPos < this.buffer.length) ? length : length - (lastPos - this.buffer.length + 1);
		}
		return length;
	}