當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayUtils.checkOffsetAndCount方法代碼示例

本文整理匯總了Java中com.lody.virtual.helper.utils.ArrayUtils.checkOffsetAndCount方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtils.checkOffsetAndCount方法的具體用法?Java ArrayUtils.checkOffsetAndCount怎麽用?Java ArrayUtils.checkOffsetAndCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lody.virtual.helper.utils.ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils.checkOffsetAndCount方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import com.lody.virtual.helper.utils.ArrayUtils; //導入方法依賴的package包/類
/**
 * java.io thinks that a read at EOF is an error and should return -1, contrary to traditional
 * Unix practice where you'd read until you got 0 bytes (and any future read would return -1).
 */
public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
    ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
    if (byteCount == 0) {
        return 0;
    }
    try {
        int readCount = Os.read(fd, bytes, byteOffset, byteCount);
        if (readCount == 0) {
            return -1;
        }
        return readCount;
    } catch (ErrnoException errnoException) {
        if (errnoException.errno == OsConstants.EAGAIN) {
            // We return 0 rather than throw if we try to read from an empty non-blocking pipe.
            return 0;
        }
        throw new IOException(errnoException);
    }
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:24,代碼來源:FileBridge.java

示例2: write

import com.lody.virtual.helper.utils.ArrayUtils; //導入方法依賴的package包/類
/**
 * java.io always writes every byte it's asked to, or fails with an error. (That is, unlike
 * Unix it never just writes as many bytes as happens to be convenient.)
 */
public static void write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
    ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
    if (byteCount == 0) {
        return;
    }
    try {
        while (byteCount > 0) {
            int bytesWritten = Os.write(fd, bytes, byteOffset, byteCount);
            byteCount -= bytesWritten;
            byteOffset += bytesWritten;
        }
    } catch (ErrnoException errnoException) {
        throw new IOException(errnoException);
    }
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:20,代碼來源:FileBridge.java


注:本文中的com.lody.virtual.helper.utils.ArrayUtils.checkOffsetAndCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。