arrayfile.java
来自「nachos操作系统框架」· Java 代码 · 共 45 行
JAVA
45 行
// PART OF THE MACHINE SIMULATION. DO NOT CHANGE.package nachos.machine;/** * A read-only <tt>OpenFile</tt> backed by a byte array. */public class ArrayFile extends OpenFileWithPosition { /** * Allocate a new <tt>ArrayFile</tt>. * * @param array the array backing this file. */ public ArrayFile(byte[] array) { this.array = array; } public int length() { return array.length; } public void close() { array = null; } public int read(int position, byte[] buf, int offset, int length) { Lib.assert(offset >= 0 && length >= 0 && offset+length <= buf.length); if (position < 0 || position >= array.length) return 0; length = Math.min(length, array.length-position); System.arraycopy(array, position, buf, offset, length); return length; } public int write(int position, byte[] buf, int offset, int length) { return 0; } private byte[] array;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?