Class FormattedDisk

java.lang.Object
com.webcodepro.applecommander.storage.FormattedDisk
All Implemented Interfaces:
DirectoryEntry
Direct Known Subclasses:
CpmFormatDisk, DosFormatDisk, GutenbergFormatDisk, NakedosFormatDisk, PascalFormatDisk, ProdosFormatDisk, RdosFormatDisk

public abstract class FormattedDisk extends Object implements DirectoryEntry
Abstract representation of a formatted Apple2 disk (floppy, 800k, hard disk).

Date created: Oct 5, 2002 3:51:44 PM

  • Field Details

    • FILE_DISPLAY_STANDARD

      public static final int FILE_DISPLAY_STANDARD
      This inner class represents the column header information used in the directory display. Note that this needs to be synchronized with the appropriate FileEntry objects.
      See Also:
    • FILE_DISPLAY_NATIVE

      public static final int FILE_DISPLAY_NATIVE
      See Also:
    • FILE_DISPLAY_DETAIL

      public static final int FILE_DISPLAY_DETAIL
      See Also:
  • Constructor Details

    • FormattedDisk

      public FormattedDisk(String filename, ImageOrder imageOrder)
      Constructor for FormattedDisk.
  • Method Details

    • getDiskName

      public abstract String getDiskName()
      Return the name of the disk. Not the physical file name, but "DISK VOLUME #xxx" (DOS 3.3) or "/MY.DISK" (ProDOS).
    • getDirname

      public String getDirname()
      Return a name for this directory.
      Specified by:
      getDirname in interface DirectoryEntry
    • setDiskName

      public void setDiskName(String volumeName)
      Set the name of the disk to volumeName.
    • getFormat

      public abstract String getFormat()
      Identify the operating system format of this disk.
    • getFreeSpace

      public abstract int getFreeSpace()
      Return the amount of free space in bytes.
    • getUsedSpace

      public abstract int getUsedSpace()
      Return the amount of used space in bytes.
    • getBitmapDimensions

      public abstract int[] getBitmapDimensions()
      Get suggested dimensions for display of bitmap. Typically, this will be only used for 5.25" floppies. This can return null if there is no suggestion.
    • getBitmapLength

      public abstract int getBitmapLength()
      Get the length of the bitmap.
    • getDiskUsage

      public abstract FormattedDisk.DiskUsage getDiskUsage()
      Get the disk usage iterator.
    • getBitmapLabels

      public abstract String[] getBitmapLabels()
      Get the labels to use in the bitmap. Note that this should, at a minimum, return an array of String[1] unless the bitmap has not been implemented.
    • getDiskInformation

      public List<FormattedDisk.DiskInformation> getDiskInformation()
      Get disk information. This is intended to be pretty generic - each disk format can build this as appropriate. Each subclass should override this method and add its own detail.
    • getFileColumnHeaders

      public List<FormattedDisk.FileColumnHeader> getFileColumnHeaders(int displayMode)
      Get the standard file column header information. This default implementation is intended only for standard mode.
    • supportsDeletedFiles

      public abstract boolean supportsDeletedFiles()
      Indicates if this disk format supports "deleted" files. Not to be confused with being able to delete a file, this indicates that deleted entries remain in the filesystem after the file has been deleted. There are some filesystems that "compress" the file out of the structure by completely removing the entry instead of marking it deleted (like Apple Pascal).
    • canReadFileData

      public abstract boolean canReadFileData()
      Indicates if this disk image can read data from a file. If not, the reason may be as simple as it has not beem implemented to something specific about the disk.
    • canWriteFileData

      public abstract boolean canWriteFileData()
      Indicates if this disk image can write data to a file. If not, the reason may be as simple as it has not beem implemented to something specific about the disk (such as read-only image).
    • canHaveDirectories

      public abstract boolean canHaveDirectories()
      Identify if this disk format is capable of having directories.
    • canDeleteFile

      public abstract boolean canDeleteFile()
      Indicates if this disk image can delete a file. If not, the reason may be as simple as it has not beem implemented to something specific about the disk.
    • getFileData

      public abstract byte[] getFileData(FileEntry fileEntry)
      Get the data associated with the specified FileEntry. This is just the raw data. Use the FileEntry itself to read data appropriately! For instance, DOS "B" (binary) files store length and address as part of the file itself, but it is not treated as file data.
      See Also:
    • getFile

      public FileEntry getFile(String filename) throws DiskException
      Locate a specific file by filename. Returns a null if specific filename is not located.
      Throws:
      DiskException
    • getFile

      protected FileEntry getFile(List<FileEntry> files, String filename) throws DiskException
      Recursive routine to locate a specific file by filename. Note that in the instance of a system with directories (ie, ProDOS), this really returns the first file with the given filename.
      Throws:
      DiskException
    • format

      public abstract void format()
      Format the disk. Make sure that this is what is intended - there is no backing out!
    • writeBootCode

      protected void writeBootCode()
      Write the AppleCommander boot code to track 0 sector 0 of the disk. This will work for a floppy, but may cause problems for other devices.
    • getLogicalDiskNumber

      public abstract int getLogicalDiskNumber()
      Returns the logical disk number. This can be used to identify between disks when a format supports multiple logical volumes. If a value of 0 is returned, there is not multiple logical volumes to distinguish.
    • getSuggestedFilename

      public abstract String getSuggestedFilename(String filename)
      Returns a valid filename for the given filename. This does not necessarily guarantee a unique filename - just validity of the filename.
    • getSuggestedFiletype

      public abstract String getSuggestedFiletype(String filename)
      Returns a valid filetype for the given filename. The most simple format will just assume a filetype of binary. This method is available for the interface to make an intelligent first guess as to the filetype.
    • getFiletypes

      public abstract String[] getFiletypes()
      Returns a list of possible file types. Since the filetype is specific to each operating system, a simple String is used.
    • needsAddress

      public abstract boolean needsAddress(String filetype)
      Indicates if this filetype requires an address component.
    • getFormattedDisk

      public FormattedDisk getFormattedDisk()
      Get the FormattedDisk associated with this DirectoryEntry. This is useful to interfaces that need to retrieve the associated disk.
      Specified by:
      getFormattedDisk in interface DirectoryEntry
    • resizeDiskImage

      public void resizeDiskImage()
      Resize the disk image to be its full size. Only invoke this method if a size does not match exception is thrown.
    • supportsDiskMap

      public boolean supportsDiskMap()
      Indicates if this FormattedDisk supports a disk map.
    • save

      public void save() throws IOException
      Save a Disk image to its file.
      Throws:
      IOException
    • saveAs

      public void saveAs(String filename) throws IOException
      Save a Disk image as a new/different file.
      Throws:
      IOException
    • getSource

      public Source getSource()
      Returns the source.
    • getFilename

      public String getFilename()
      Returns the filename.
      Returns:
      String
    • setFilename

      public void setFilename(String filename)
      Sets the filename.
    • getOrderName

      public String getOrderName()
      Returns the name of the underlying image order.
      Returns:
      String
    • getPhysicalSize

      public int getPhysicalSize()
      Identify the size of this disk.
    • resizeDiskImage

      protected void resizeDiskImage(int newSize)
      Resize a disk image up to a larger size. The primary intention is to "fix" disk images that have been created too small. The primary culprit is ApplePC HDV images which dynamically grow. Since AppleCommander works with a byte array, the image must grow to its full size.
      Parameters:
      newSize -
    • readBlock

      public byte[] readBlock(int block)
      Read the block from the disk image.
    • writeBlock

      public void writeBlock(int block, byte[] data)
      Write the block to the disk image.
    • readSector

      public byte[] readSector(int track, int sector) throws IllegalArgumentException
      Retrieve the specified sector.
      Throws:
      IllegalArgumentException
    • writeSector

      public void writeSector(int track, int sector, byte[] bytes) throws IllegalArgumentException
      Write the specified sector.
      Throws:
      IllegalArgumentException
    • hasChanged

      public boolean hasChanged()
      Indicates if the disk has changed. Triggered when data is written and cleared when data is saved.
    • isNewImage

      public boolean isNewImage()
      Indicates if the disk image is new. This can be used for Save As processing.
    • getImageOrder

      public ImageOrder getImageOrder()
      Answer with the physical ordering of the disk.
    • setImageOrder

      protected void setImageOrder(ImageOrder imageOrder)
      Set the physical ordering of the disk.
    • changeImageOrder

      public abstract void changeImageOrder(ImageOrder imageOrder)
      Change the physical ordering of the disk. This must be implemented by all subclasses. See AppleUtil for common utility methods. (It is assumed that a disk needs to be copied in the appropriate order - i.e., by track and sector for a DOS type disk or by blocks in a ProDOS type disk.)
    • setFileData

      public abstract void setFileData(FileEntry fileEntry, byte[] fileData) throws DiskFullException
      Writes the raw bytes into the file. This bypasses any special formatting of the data (such as prepending the data with a length and/or an address). Typically, the FileEntry.setFileData method should be used.
      Throws:
      DiskFullException
    • getDiskGeometry

      public abstract DiskGeometry getDiskGeometry()
      Gives an indication on how this disk's geometry should be handled.
    • toNativeFiletype

      public abstract String toNativeFiletype(String prodosFiletype)
      Provides conversation from a given ProDOS file type since as it is common across many archiving tools. This should also allow "native" filetypes to just pass-through. (For example, a "B" in a DOS disk should just return a "B" while a "BAS" would be transformed to a "B" filetype.)
    • toProdosFiletype

      public abstract String toProdosFiletype(String nativeFiletype)
      Provides conversation to a given ProDOS file type since as it is common across many archiving tools.