当前位置: 首页>>代码示例>>Java>>正文


Java Arrays.checkOffsetAndCount方法代码示例

本文整理汇总了Java中java.util.Arrays.checkOffsetAndCount方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.checkOffsetAndCount方法的具体用法?Java Arrays.checkOffsetAndCount怎么用?Java Arrays.checkOffsetAndCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Arrays的用法示例。


在下文中一共展示了Arrays.checkOffsetAndCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFully

import java.util.Arrays; //导入方法依赖的package包/类
/**
 * Reads exactly 'byteCount' bytes from 'in' (into 'dst' at offset 'offset'), and throws
 * EOFException if insufficient bytes are available.
 *
 * Used to implement {@link java.io.DataInputStream#readFully(byte[], int, int)}.
 */
public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
    if (byteCount == 0) {
        return;
    }
    if (in == null) {
        throw new NullPointerException("in == null");
    }
    if (dst == null) {
        throw new NullPointerException("dst == null");
    }
    Arrays.checkOffsetAndCount(dst.length, offset, byteCount);
    while (byteCount > 0) {
        int bytesRead = in.read(dst, offset, byteCount);
        if (bytesRead < 0) {
            throw new EOFException();
        }
        offset += bytesRead;
        byteCount -= bytesRead;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Streams.java

示例2: write

import java.util.Arrays; //导入方法依赖的package包/类
/**
 * Writes data for the current entry to the underlying stream.
 *
 * @throws IOException
 *                If an error occurs writing to the stream
 */
@Override
public void write(byte[] buffer, int offset, int byteCount) throws IOException {
    Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
    if (currentEntry == null) {
        throw new ZipException("No active entry");
    }
    /*final long totalBytes = crc.tbytes + byteCount;
    if ((totalBytes > Zip64.MAX_ZIP_ENTRY_AND_ARCHIVE_SIZE) && !currentEntryNeedsZip64) {
        throw new IOException("Zip entry size (" + totalBytes +
                " bytes) cannot be represented in the zip format (needs Zip64)." +
                " Set the entry length using ZipEntry#setLength to use Zip64 where necessary.");
    }*/
    if (currentEntry.getMethod() == STORED) {
        out.write(buffer, offset, byteCount);
    } else {
        out.write(buffer, offset, byteCount);
    }
    // crc.update(buffer, offset, byteCount);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:TinkerZipOutputStream.java


注:本文中的java.util.Arrays.checkOffsetAndCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。