/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2002 by Robert Greene * robgreene at users.sourceforge.net * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.webcodepro.applecommander.storage; import java.util.ArrayList; import java.util.List; /** * Manages a disk that is in the ProDOS format. *

* Date created: Oct 3, 2002 11:45:25 PM * @author: Rob Greene */ public class ProdosFormatDisk extends FormattedDisk { /** * The standard ProDOS file entry length. */ public static final int ENTRY_LENGTH = 0x27; /** * Hold on to the volume directory header. */ private ProdosVolumeDirectoryHeader volumeHeader; /** * Use this inner interface for managing the disk usage data. * This offloads format-specific implementation to the implementing class. */ private class ProdosDiskUsage implements DiskUsage { private int location = -1; private transient byte[] data = null; public boolean hasNext() { return location == -1 || location < volumeHeader.getTotalBlocks() - 1; } public void next() { location++; } /** * Get the free setting for the bitmap at the current location. */ public boolean isFree() { if (location == -1) { throw new IllegalArgumentException("Invalid dimension for isFree! Did you call next first?"); } if (data == null) { int volumeBitmapBlock = volumeHeader.getBitMapPointer(); int volumeBitmapBlocks = volumeHeader.getTotalBlocks(); int blocksToRead = (volumeBitmapBlocks / 4096) + 1; // Read in the entire volume bitmap: data = new byte[blocksToRead * BLOCK_SIZE]; for (int i=0; i fileData.length) { // end of file int bytesToCopy = fileData.length - offset; if (blockNumber != 0) System.arraycopy(blockData, 0, fileData, offset, bytesToCopy); offset+= bytesToCopy; } else { if (blockNumber != 0) System.arraycopy(blockData, 0, fileData, offset, blockData.length); offset+= blockData.length; } } return offset; } }