判断分片尺寸是否在规定的范围内，抛出参数异常，目前的有效值为64KB ~ 10MB

@param sliceSize 分片大小, 单位Byte
@throws ParamException
554237
public static void AssertSliceInRange(int sliceSize) throws ParamException {
        int maxSliceSize = 10 * 1024 * 1024; // 10MB
        int minSliceSize = 64 * 1024; // 64KB
        if (sliceSize > maxSliceSize || sliceSize < minSliceSize) {
            throw new ParamException("sliceSize legal value is [64KB, 100MB]");
        }
    }
1337648
public void allocate(long size) throws IOException, ServerException {
        Command cmd = new Command("ALLO", String.valueOf(size));
        Reply reply = null;
        try {
            reply = controlChannel.execute(cmd);
        } catch (UnexpectedReplyCodeException urce) {
            throw ServerException.embedUnexpectedReplyCodeException(urce);
        } catch (FTPReplyParseException rpe) {
            throw ServerException.embedFTPReplyParseException(rpe);
        }
    }
752103
@Override
    protected void ensureAvailableBytes(int size)
    {
        if (offset + size > bufferSize)
        {
            try
            {
                int availableBytes = (int) (fileChannel.size() - fileChannel.position());
                ByteBuffer byteBuffer = ByteBuffer.allocate(Math.min(availableBytes, offset));
                int readBytes = fileChannel.read(byteBuffer);
                if (readBytes == availableBytes)
                {
                    fileChannel.close();
                    fileChannel = null;
                }
                assert readBytes > 0 : "已到达文件尾部！";
                byteBuffer.flip();
                byte[] bytes = byteBuffer.array();
                System.arraycopy(this.bytes, offset, this.bytes, offset - readBytes, bufferSize - offset);
                System.arraycopy(bytes, 0, this.bytes, bufferSize - readBytes, readBytes);
                offset -= readBytes;
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        }
    }
845170
@Override
    public long getFileSize() {
        try {
            final rh_protoClient client = getRpcClient(OncRpcProtocols.ONCRPC_UDP);
            try {
                return BlockingWrapper.execute(() -> client.getFileSize_1());
            } finally {
                client.close();
            }
        } catch (OncRpcException | IOException | InterruptedException | RuntimeException ex) {
            LOG.log(Level.SEVERE, "getFileSize RPC call failed", ex);
            throw new RuntimeException("RPC call failed", ex);
        }
    }
986646
static void checkDirectMemCapacity(final int k, final long n, final long memCapBytes) {
    final int reqBufBytes = getUpdatableStorageBytes(k, n);

    if (memCapBytes < reqBufBytes) {
      throw new SketchesArgumentException("Possible corruption: Memory capacity too small: "
          + memCapBytes + " < " + reqBufBytes);
    }
  }
740167
public function getHumanReadableSize($size, $unit = null, $decemals = 2)
    {
        $byteUnits = [' B', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'];
        if (!is_null($unit) && !in_array($unit, $byteUnits)) {
            $unit = null;
        }
        $extent = 1;
        foreach ($byteUnits as $rank) {
            if ((is_null($unit) && ($size < $extent <<= 10)) || ($rank == $unit)) {
                break;
            }
        }

        return number_format($size / ($extent >> 10), $decemals).$rank;
    }
456672
@Override
    public final IntStream limit(long maxSize) {
        if (maxSize < 0)
            throw new IllegalArgumentException(Long.toString(maxSize));
        return SliceOps.makeInt(this, 0, maxSize);
    }
342834
public static int getChunkSize(BoxUploadSession uploadSession, int partNumber, long fileSize) {
        if (partNumber == uploadSession.getTotalParts() - 1) {
            return (int) (fileSize - partNumber * uploadSession.getPartSize());
        }
        return uploadSession.getPartSize();
    }
1167752
@Override
	public void releaseMemory(int toRelease) throws IOException {
		checkArgument(toRelease > 0);

		for (ResultSubpartition subpartition : subpartitions) {
			toRelease -= subpartition.releaseMemory();

			// Only release as much memory as needed
			if (toRelease <= 0) {
				break;
			}
		}
	}
1016428
static public int getByteSize() {
    int size = 0;
    size += 16;
    size += 16;
    size += 24;
    size += 24;
    size += 20;
    size += 3;
    size += 5;
    size += 36;
    size += 64;
    size += 64;
    size = size/8;
    return size;
  }
172869
public void getBytes(int lengthToCopy, byte[] copyArray, int copyOffset) {
        if (lengthToCopy > 0) {
            System.arraycopy(_buffer, _offset, copyArray, copyOffset, lengthToCopy);
            skip(lengthToCopy);
        }

    }
1052496
public static function upload_slice_impl($filePath, $bucket, $fileid, $userid = 0, $magicContext, $sliceSize, $session, $params) {
         $filePath = realpath($filePath);
         
         if (!file_exists($filePath)) {
             self::setMessageInfo(-1, "file not exixts");                        
             return false;
         }
         
         $fileSize = filesize($filePath);  
         
        $expired = time() + self::EXPIRED_SECONDS;
        $url = self::generateResUrl($bucket, $userid, $fileid);
        $sign = Auth::getAppSignV2($bucket, $fileid, $expired);
        if(false === $sign)
        {
            return false;
        }
        
        $sha1 = hash_file('sha1', $filePath);

        $info = self::upload_slice_init(
               $url, $sign,$sha1,
                 $fileSize,$sliceSize,$session,$magicContext);
        if(false === $info)
        {
            return false;
        }
        
        if(isset($info['slice_size']))
        {
            self::$_sliceSize = $info['slice_size'];
        }
        else
        {
            self::$_sliceSize = $sliceSize;
        }
        
        $retryTimes = 0;
        $newInfo = array();
        while(!isset($info['url']) && isset($info['session']))
        {  
            $newInfo = self::upload_slice_data($filePath, $info, $sign, $url);
            if(false === $newInfo)
            { 
                $retryTimes++;
                if($retryTimes >= self::MAX_RETRY_TIMES)
                {
                    $info = false;
                    break;
                }
                continue;
            }                                  

            $retryTimes = 0;

            $info = $newInfo;
            if(isset($newInfo['offset']))
            {
                $info['offset'] = $newInfo['offset'] + self::$_sliceSize;
            }                      
        }
        
        $messageInfo = self::getMessageInfo();
        
        if(false === $info)
        {
            return false;
        }
        
        $data = array(
                'url' => $info['url'],
                'downloadUrl' => $info['download_url'],
                'fileid' => $info['fileid'],
            );
          
        self::setMessageInfo(0, "upload slice success");

        return $data;
        
    }
40595
public static long getNumSector(String requestSize, String sectorSize) {
    Double memSize = Double.parseDouble(requestSize);
    Double sectorBytes = Double.parseDouble(sectorSize);
    Double nSectors = memSize / sectorBytes;
    Double memSizeKB = memSize / 1024;
    Double memSizeGB = memSize / (1024 * 1024 * 1024);
    Double memSize100GB = memSizeGB / 100;

    // allocation bitmap file: one bit per sector
    Double allocBitmapSize = nSectors / 8;

    // extend overflow file: 4MB, plus 4MB per 100GB
    Double extOverflowFileSize = memSize100GB * 1024 * 1024 * 4;

    // journal file: 8MB, plus 8MB per 100GB
    Double journalFileSize = memSize100GB * 1024 * 1024 * 8;

    // catalog file: 10bytes per KB
    Double catalogFileSize = memSizeKB * 10;

    // hot files: 5bytes per KB
    Double hotFileSize = memSizeKB * 5;

    // quota users file and quota groups file
    Double quotaUsersFileSize = (memSizeGB * 256 + 1) * 64;
    Double quotaGroupsFileSize = (memSizeGB * 32 + 1) * 64;
    Double metadataSize = allocBitmapSize + extOverflowFileSize + journalFileSize
        + catalogFileSize + hotFileSize + quotaUsersFileSize + quotaGroupsFileSize;

    Double allocSize = memSize + metadataSize;
    Double numSectors = allocSize / sectorBytes;

    System.out.println(numSectors.longValue() + 1); // round up
    return numSectors.longValue() + 1;
  }
837810
public long sizeInBytes()
    {
        long n = 0;
        for (CacheBucket bucket : cache.asMap().values())
            for (RandomAccessReader reader : bucket.queue)
                n += reader.getTotalBufferSize();
        return n;
    }
328210
public static Flux<ByteBuf> split(final ByteBuf whole, final int chunkSize) {
        return Flux.generate(whole::readerIndex, (readFromIndex, synchronousSync) -> {
            final int writerIndex = whole.writerIndex();
            //
            if (readFromIndex >= writerIndex) {
                synchronousSync.complete();
                return writerIndex;
            } else {
                int readSize = Math.min(writerIndex - readFromIndex, chunkSize);
                // Netty slice operation will not increment the ref count.
                //
                // Here we invoke 'retain' on each slice, since
                // consumer of the returned Flux stream is responsible for
                // releasing each chunk as it gets consumed.
                //
                synchronousSync.next(whole.slice(readFromIndex, readSize).retain());
                return readFromIndex + readSize;
            }
        });
    }
179438
func (s Slice) ByteSize() (ValueLength, error) {
	h := s.head()
	// check if the type has a fixed length first
	l := fixedTypeLengths[h]
	if l != 0 {
		// return fixed length
		return ValueLength(l), nil
	}

	// types with dynamic lengths need special treatment:
	switch s.Type() {
	case Array, Object:
		if h == 0x13 || h == 0x14 {
			// compact Array or Object
			return readVariableValueLength(s, 1, false), nil
		}

		vpackAssert(h > 0x00 && h <= 0x0e)
		return ValueLength(readIntegerNonEmpty(s[1:], widthMap[h])), nil

	case String:
		vpackAssert(h == 0xbf)
		// long UTF-8 String
		return ValueLength(1 + 8 + readIntegerFixed(s[1:], 8)), nil

	case Binary:
		vpackAssert(h >= 0xc0 && h <= 0xc7)
		return ValueLength(1 + ValueLength(h) - 0xbf + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xbf))), nil

	case BCD:
		if h <= 0xcf {
			// positive BCD
			vpackAssert(h >= 0xc8 && h < 0xcf)
			return ValueLength(1 + ValueLength(h) - 0xc7 + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xc7))), nil
		}

		// negative BCD
		vpackAssert(h >= 0xd0 && h < 0xd7)
		return ValueLength(1 + ValueLength(h) - 0xcf + ValueLength(readIntegerNonEmpty(s[1:], uint(h)-0xcf))), nil

	case Custom:
		vpackAssert(h >= 0xf4)
		switch h {
		case 0xf4, 0xf5, 0xf6:
			return ValueLength(2 + readIntegerFixed(s[1:], 1)), nil
		case 0xf7, 0xf8, 0xf9:
			return ValueLength(3 + readIntegerFixed(s[1:], 2)), nil
		case 0xfa, 0xfb, 0xfc:
			return ValueLength(5 + readIntegerFixed(s[1:], 4)), nil
		case 0xfd, 0xfe, 0xff:
			return ValueLength(9 + readIntegerFixed(s[1:], 8)), nil
		}
	}

	return 0, WithStack(InternalError)
}
642288
public int getSize() {
		if (size < 0) {
			size = 0;
			for (byte[] cache: start) {
				size += new RemoteOneFileCache(cache).getSize();
			}
			for (byte[] cache: end) {
				size += new RemoteOneFileCache(cache).getSize();
			}
		}
		return size;
	}