上传字节流，小文件走表单，大文件走分片

@param inputStream
@param size
@param key
@param token
@param params
@param mime
@param checkCrc
@return
@throws QiniuException
@throws IOException
767228
public Response put(InputStream inputStream, long size, String key, String token, StringMap params,
                        String mime, boolean checkCrc) throws QiniuException {
        if (size < 0 || size > configuration.putThreshold) {
            return put(inputStream, key, token, params, mime);
        }
        byte[] data = null;
        try {
            data = IOUtils.toByteArray(inputStream);
        } catch (IOException e) {
            throw new QiniuException(e);
        }
        return put(data, key, token, params, mime, checkCrc);
    }
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);
	}
5782
private void processFile(InputStream is) throws MPXJException
   {
      int line = 1;

      try
      {
         //
         // Test the header and extract the separator. If this is successful,
         // we reset the stream back as far as we can. The design of the
         // BufferedInputStream class means that we can't get back to character
         // zero, so the first record we will read will get "RMHDR" rather than
         // "ERMHDR" in the first field position.
         //
         BufferedInputStream bis = new BufferedInputStream(is);
         byte[] data = new byte[6];
         data[0] = (byte) bis.read();
         bis.mark(1024);
         bis.read(data, 1, 5);

         if (!new String(data).equals("ERMHDR"))
         {
            throw new MPXJException(MPXJException.INVALID_FILE);
         }

         bis.reset();

         InputStreamReader reader = new InputStreamReader(bis, getCharset());
         Tokenizer tk = new ReaderTokenizer(reader);
         tk.setDelimiter('\t');
         List<String> record = new ArrayList<String>();

         while (tk.getType() != Tokenizer.TT_EOF)
         {
            readRecord(tk, record);
            if (!record.isEmpty())
            {
               if (processRecord(record))
               {
                  break;
               }
            }
            ++line;
         }
      }

      catch (Exception ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR + " (failed at line " + line + ")", ex);
      }
   }
1274523
public static InputStream decrypt(InputStream inputStream, byte[] key) {
        checkNotNull(inputStream);
        checkNotNull(key);
        checkArgument(key.length >= 5 && key.length <= 256);
        StreamCipher rc4 = new RC4Engine();
        rc4.init(false, new KeyParameter(key));
        return new CipherInputStream(inputStream, rc4);
    }
334436
private static void __serveStream(HttpServletRequest request, HttpServletResponse response, InputStream is, String path, String mime, int bufferSize, long lastModified) throws IOException {
        Map<String, String> reqHeaders = __getRequestHeaderMap(request);

        String queryString = request.getQueryString();
        if (queryString == null) {
            queryString = "";
        }

        // Calculate etag
        String etag = Integer.toHexString((path + lastModified + queryString + is.available()).hashCode());

        // Support (simple) skipping:
        long startFrom = 0;
        long endAt = -1;

        String range = reqHeaders.get("range");
        if (range != null) {
            if (range.startsWith("bytes=")) {
                range = range.substring("bytes=".length());
                int minus = range.indexOf('-');

                if (minus > 0) {
                    startFrom = __parseLong(range.substring(0, minus), 0);
                    endAt = __parseLong(range.substring(minus + 1), -1);
                }
            }
        }

        response.addHeader("Accept-Ranges", "bytes");

        // Change return code and add Content-Range header when skipping is requested
        long fileLen = is.available();
        if (range != null && startFrom >= 0) {
            if (startFrom >= fileLen) {
                response.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                response.setContentType("text/plain");
                response.addHeader("Content-Range", "bytes 0-0/" + fileLen);
                response.addHeader("ETag", etag);
            } else {
                if (endAt < 0) {
                    endAt = fileLen - 1;
                }

                long newLen = endAt - startFrom + 1;

                if (newLen < 0) {
                    newLen = 0;
                }

                final long dataLen = newLen;

                is.skip(startFrom);

                response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
                response.setContentType(mime);
                __flush(is, response.getOutputStream(), bufferSize);
                response.addHeader("Content-Length", "" + dataLen);
                response.addHeader("Content-Range", "bytes " + startFrom + "-" + endAt + "/" + fileLen);
                response.addHeader("ETag", etag);
            }
        } else {
            if (etag.equals(reqHeaders.get("if-none-match"))) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                response.setContentType(mime);
            } else {
                response.setStatus(HttpServletResponse.SC_OK);
                response.setContentType(mime);
                __flush(is, response.getOutputStream(), bufferSize);
                response.addHeader("Content-Length", "" + fileLen);
                response.addHeader("ETag", etag);
            }
        }

    }
1006924
private Collection<? extends java.security.cert.CRL>
        parseX509orPKCS7CRL(InputStream is)
        throws CRLException, IOException
    {
        Collection<X509CRLImpl> coll = new ArrayList<>();
        byte[] data = readOneBlock(is);
        if (data == null) {
            return new ArrayList<>(0);
        }
        try {
            PKCS7 pkcs7 = new PKCS7(data);
            X509CRL[] crls = pkcs7.getCRLs();
            // CRLs are optional in PKCS #7
            if (crls != null) {
                return Arrays.asList(crls);
            } else {
                // no crls provided
                return new ArrayList<>(0);
            }
        } catch (ParsingException e) {
            while (data != null) {
                coll.add(new X509CRLImpl(data));
                data = readOneBlock(is);
            }
        }
        return coll;
    }
725903
public static void skip(long size, InputStream input) throws IOException {
        while (size > 0) {
            size -= input.skip(size);
        }
    }
1028880
public void prefetch(String bucket, String key) throws QiniuException {
        String resource = encodedEntry(bucket, key);
        String path = String.format("/prefetch/%s", resource);
        Response res = ioPost(bucket, path);
        if (!res.isOK()) {
            throw new QiniuException(res);
        }
        res.close();
    }
299525
function lockCrc(inputStr){

		res = 0xff;
		inputHex = new Buffer(inputStr,'hex');

		//start from the second byte 
		for (i = 1; i<= inputHex.length; i++) {
			res = res ^ inputHex[i];
		}
		//add padding
		reshex = (res+0x100).toString(16).substr(-2);
//		console.log(reshex);

		return(inputStr+reshex);
}
1172405
public static void main(String[] args)
    throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
    try {
      /* play.min.io for test and development. */
      MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
                                                "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

      /* Amazon S3: */
      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
      //                                           "YOUR-SECRETACCESSKEY");

      // Create new PostPolicy object for 'my-bucketname', 'my-objectname' and 7 days expire time from now.
      PostPolicy policy = new PostPolicy("my-bucketname", "my-objectname", DateTime.now().plusDays(7));
      // 'my-objectname' should be 'image/png' content type
      policy.setContentType("image/png");
      Map<String,String> formData = minioClient.presignedPostPolicy(policy);

      // Print a curl command that can be executable with the file /tmp/userpic.png and the file will be uploaded.
      System.out.print("curl -X POST ");
      for (Map.Entry<String,String> entry : formData.entrySet()) {
        System.out.print(" -F " + entry.getKey() + "=" + entry.getValue());
      }
      System.out.println(" -F file=@/tmp/userpic.png https://play.min.io:9000/my-bucketname");
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
83520
public static void main(String[] args)
    throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
    try {
      /* play.min.io for test and development. */
      MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
                                                "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

      /* Amazon S3: */
      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
      //                                           "YOUR-SECRETACCESSKEY");

      // Check whether 'my-bucketname' exist or not.
      boolean found = minioClient.bucketExists("my-bucketname");
      if (found) {
        // List objects from 'my-bucketname'
        Iterable<Result<Item>> myObjects = minioClient.listObjects("my-bucketname");
        for (Result<Item> result : myObjects) {
          Item item = result.get();
          System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
        }
      } else {
        System.out.println("my-bucketname does not exist");
      }
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
533745
private void copyStream(InputStream inputStream) throws IOException {
		OutputStream outputStream = null;
		try {
			outputStream = getContext().getOutputStream();
			byte[] buffer = new byte[65535];
			int bufferLen;
			int totalLen = 0;
			while ((bufferLen = inputStream.read(buffer)) > 0) {
				outputStream.write(buffer, 0, bufferLen);
				totalLen += bufferLen;
			}
			getContext().getResponse().setContentLength(totalLen);
		} finally {
			if (outputStream != null) {
				outputStream.flush();
			}
		}
	}
914889
public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException,
      InvalidEndpointException, InvalidPortException, InvalidBucketNameException,
      InsufficientDataException, NoResponseException, ErrorResponseException, InternalException,
      InvalidArgumentException, IOException, XmlPullParserException {
    /* play.min.io for test and development. */
    MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
        "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");
    /* Amazon S3: */
    // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com",
    // "YOUR-ACCESSKEYID",
    // "YOUR-SECRETACCESSKEY");

    String objectName = "my-objectname";
    String bucketName = "my-bucketname";

    File file = new File("my-filename");
    InputStream pis = new BufferedInputStream(new ProgressStream("Uploading... ",
                                                                 ProgressBarStyle.ASCII,
                                                                 new FileInputStream(file)));
    minioClient.putObject(bucketName, objectName, pis, pis.available(), "application/octet-stream");
    pis.close();
    System.out.println("my-objectname is uploaded successfully");
  }
61840
public static void main(String[] args)
    throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
    try {
      /* play.min.io for test and development. */
      MinioClient minioClient = new MinioClient("https://play.min.io:9000", "Q3AM3UQ867SPQQA43P2F",
                                                "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

      /* Amazon S3: */
      // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
      //                                           "YOUR-SECRETACCESSKEY");

      StringBuilder builder = new StringBuilder();
      builder.append("{\n");
      builder.append("    \"Statement\": [\n");
      builder.append("        {\n");
      builder.append("            \"Action\": [\n");
      builder.append("                \"s3:GetBucketLocation\",\n");
      builder.append("                \"s3:ListBucket\"\n");
      builder.append("            ],\n");
      builder.append("            \"Effect\": \"Allow\",\n");
      builder.append("            \"Principal\": \"*\",\n");
      builder.append("            \"Resource\": \"arn:aws:s3:::my-bucketname\"\n");
      builder.append("        },\n");
      builder.append("        {\n");
      builder.append("            \"Action\": \"s3:GetObject\",\n");
      builder.append("            \"Effect\": \"Allow\",\n");
      builder.append("            \"Principal\": \"*\",\n");
      builder.append("            \"Resource\": \"arn:aws:s3:::my-bucketname/myobject*\"\n");
      builder.append("        }\n");
      builder.append("    ],\n");
      builder.append("    \"Version\": \"2012-10-17\"\n");
      builder.append("}\n");
      minioClient.setBucketPolicy("my-bucketname", builder.toString());
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
204221
public static void consumeInputStream(InputStream inputStream,
            String charsetName, Consumer<String> consumer) {
        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(inputStream, charsetName))) {
            for (String line = br.readLine(); line != null;
                    line = br.readLine())
                consumer.accept(line);
        } catch (IOException e) {
            JMExceptionManager.handleExceptionAndThrowRuntimeEx(log, e,
                    "consumeInputStream", inputStream, charsetName, consumer);
        }
    }
716280
public void setInputStream(InputStream inputStream, long inputStreamLength) {
		// close last file when set a new inputStream
		if (this.isUploadFile){
			try{
				this.inputStream.close();
			}
			catch (Exception e){
			}
		}

		if (inputStream instanceof FDSProgressInputStream){
			this.inputStream = (FDSProgressInputStream) inputStream;
		}
		else {
			this.inputStream = new FDSProgressInputStream(inputStream, this.progressListener);
		}
		if (this.progressListener != null){
			this.progressListener.setTransferred(0);
			this.progressListener.setTotal(inputStreamLength);
		}
		this.isUploadFile = false;
		this.inputStreamLength = inputStreamLength;
	}
714063
static public int getBlockCrc(DataNode datanode, ReplicaToRead ri,
      int namespaceId, Block block) throws IOException {

    InputStream rawStreamIn = null;
    DataInputStream streamIn = null;
    int blockCrc = 0;

    try {
      int bytesPerCRC;
      int checksumSize;

      bytesPerCRC = ri.getBytesPerChecksum();
      int checksumType = ri.getChecksumType();
      if (checksumType != DataChecksum.CHECKSUM_CRC32) {
        throw new IOException("File Checksum now is only supported for CRC32");
      }
      DataChecksum dataChecksum = DataChecksum.newDataChecksum(checksumType,
          bytesPerCRC);
      checksumSize = dataChecksum.getChecksumSize();
      
      rawStreamIn = ri.getBlockInputStream(datanode, 0);
      streamIn = new DataInputStream(new BufferedInputStream(rawStreamIn,
          FSConstants.BUFFER_SIZE));
      IOUtils.skipFully(streamIn, BlockInlineChecksumReader.getHeaderSize());

      long lengthLeft = ((FileInputStream) rawStreamIn).getChannel().size()
          - BlockInlineChecksumReader.getHeaderSize();
      if (lengthLeft == 0) {
        blockCrc = (int) dataChecksum.getValue();
      } else {
        byte[] buffer = new byte[checksumSize];
        boolean firstChecksum = true;

        while (lengthLeft > 0) {
          long dataByteLengh;

          if (lengthLeft >= bytesPerCRC + checksumSize) {
            lengthLeft -= bytesPerCRC + checksumSize;
            dataByteLengh = bytesPerCRC;
          } else if (lengthLeft > checksumSize) {
            dataByteLengh = lengthLeft - checksumSize;
            lengthLeft = 0;
          } else {
            // report to name node the corruption.
            DataBlockScanner.reportBadBlocks(block, namespaceId, datanode);
            throw new IOException("File for namespace " + namespaceId
                + " block " + block + " seems to be corrupted");
          }

          IOUtils.skipFully(streamIn, dataByteLengh);
          IOUtils.readFully(streamIn, buffer, 0, buffer.length);
          int intChecksum = DataChecksum.getIntFromBytes(buffer, 0);
          if (firstChecksum) {
            blockCrc = intChecksum;
            firstChecksum = false;
          } else {
            blockCrc = CrcConcat.concatCrc(blockCrc, intChecksum,
                (int) dataByteLengh);
          }
        }
      }

      if (LOG.isDebugEnabled()) {
        LOG.debug("block=" + block + ", bytesPerCRC=" + bytesPerCRC
            + ", crc=" + blockCrc);
      }
      return blockCrc;
    } finally {
      IOUtils.closeStream(streamIn);
      IOUtils.closeStream(rawStreamIn);
    }

  }