當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。