@@ -0,0 +1,1918 @@
+package me.lexjoy.utils.io;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0Apublic class ReadHelper %7B%0A%0A  public static final int DEFAULT_BUFFER_SIZE = 1024;%0A%0A  public static final int DEFAULT_CHECK_MILLISECONDS = 100;%0A%0A  public ReadHelper() %7B%0A    this(DEFAULT_BUFFER_SIZE, DEFAULT_CHECK_MILLISECONDS);%0A  %7D%0A%0A  public ReadHelper(int bufferSize, int checkMillis) %7B%0A    this.setBufferSize(bufferSize);%0A    this.setCheckDuration(checkMillis);%0A  %7D%0A%0A  public ReadHelper setBufferSize(int bufferSize) %7B%0A    if (bufferSize %3C= 0) %7B%0A      bufferSize = DEFAULT_BUFFER_SIZE;%0A    %7D%0A    this.bufferSize = bufferSize;%0A    return this;%0A  %7D%0A%0A  public ReadHelper setCheckDuration(int checkMillis) %7B%0A    this.checkMillis = checkMillis;%0A    return this;%0A  %7D%0A%0A  public byte%5B%5D read(InputStream is) throws IOException %7B%0A    if (is == null) %7B%0A      return null;%0A    %7D%0A    ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A    final int BUFFER_SIZE = this.bufferSize;%0A    final int CHECK_DURATION = this.checkMillis;%0A    final boolean HAS_CHECK = CHECK_DURATION %3E= 0;%0A    byte%5B%5D buffer = new byte%5BBUFFER_SIZE%5D;%0A    int readCount;%0A%0A    try %7B%0A      while (true) %7B%0A        readCount = is.read(buffer);%0A  %0A        if (readCount %3E BUFFER_SIZE %7C%7C readCount %3C 0) %7B%0A          throw new IOException(%22invalid read size%22);%0A        %7D%0A        baos.write(buffer, 0, readCount);%0A%0A        if (HAS_CHECK) %7B%0A          try %7B%0A            Thread.sleep(CHECK_DURATION);%0A          %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A          %7D%0A        %7D%0A  %0A        if (is.available() %3C= 0) %7B%0A          break;%0A        %7D%0A      %7D%0A      return baos.toByteArray();%0A%0A    %7D catch (IOException e) %7B%0A      throw e;%0A%0A    %7D finally %7B%0A%0A      try %7B%0A        baos.close();%0A      %7D catch (IOException e) %7B%0A        e.printStackTrace();%0A      %7D%0A    %7D%0A  %7D%0A%0A  private int bufferSize;%0A  private int checkMillis;%0A%0A%7D%0A

Create ReadHelper.java