本文整理匯總了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);
}