本文整理汇总了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;
}
}
示例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);
}