⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disk.java

📁 Disk simulation program. Simulates file-system with direct access.
💻 JAVA
字号:
public class Disk
{
    public static final int SECTORS_COUNT = 10000;
    public static final int SECTORS_SIZE = 512;
    /**
     * Sectors on the disk
     */
    private int sectorCount;
    /**
     * Characters in a sector
     */
    private int sectorSize;
    /**
     * All disk data is stored here
     */
    private char[][] store;

    /**
     * For default sectorCount and sectorSize
     */
    public Disk()
    {
        this.store = new char[SECTORS_COUNT][SECTORS_SIZE];
        this.sectorCount = SECTORS_COUNT;
        this.sectorSize = SECTORS_SIZE;
    }

    /**
     * Constructor
     *
     * @param sectorCount - sector count
     * @param sectorSize  - sector size
     */
    public Disk(int sectorCount, int sectorSize)
    {
        this.sectorCount = sectorCount;
        this.sectorSize = sectorSize;
        this.store = new char[sectorCount][sectorSize];
    }

    /**
     * Reads sector to buffer
     *
     * @param sectorNumber - sector
     * @param buffer       - buffer
     */
    public void readSector(int sectorNumber, char[] buffer)
    {
        System.arraycopy(store[sectorNumber], 0, buffer, 0, Math.min(store[sectorNumber].length, buffer.length));
    }

    /**
     * Writes buffer to sector
     *
     * @param sectorNumber - sector
     * @param buffer       - buffer
     */
    public void writeSector(int sectorNumber, char[] buffer)
    {
        System.arraycopy(buffer, 0, store[sectorNumber], 0, Math.min(store[sectorNumber].length, buffer.length));
    }

    /**
     * Getter for property 'sectorCount'.
     *
     * @return Value for property 'sectorCount'.
     */
    public int getSectorCount()
    {
        return sectorCount;
    }

    /**
     * Getter for property 'sectorSize'.
     *
     * @return Value for property 'sectorSize'.
     */
    public int getSectorSize()
    {
        return sectorSize;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -