code: int read(InputStream is, int contentLength) {
          if (is != null) {
              try {
                  int capacity = (contentLength > 0) ? (contentLength + 4096) : 16384;
                  ByteArrayOutputStream buffer = new ByteArrayOutputStream(capacity);
                  int nRead;
                  byte[] data = new byte[16384];
                  while ((nRead = is.read(data, 0, data.length)) != -1) {
                      buffer.write(data, 0, nRead);
                  }
                  buffer.flush();
  
                  read(buffer.toByteArray());
              } catch (IOException e) {
                  Logger.d(TAG, "Error reading data from stream", e);
              }
          } else {
              status = STATUS_OPEN_ERROR;
          }
  
          try {
              if (is != null) {
                  is.close();
              }
          } catch (IOException e) {
              Logger.d(TAG, "Error closing stream", e);
          }
  
          return status;
      }
docs: Reads GIF image from stream.
  
  @param is containing GIF file.
  @return read status code (0 = no errors).