Class Disk

  • Direct Known Subclasses:
    FormattedDisk

    public class Disk
    extends java.lang.Object
    Abstract representation of an Apple2 disk (floppy, 800k, hard disk).

    Date created: Oct 3, 2002 10:59:47 PM

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Disk.FilenameFilter
      Specifies a filter to be used in determining filetypes which are supported.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        Disk​(java.lang.String filename)
      Construct a Disk and load the specified file.
        Disk​(java.lang.String filename, boolean knownProDOSOrder)
      Construct a Disk and load the specified file.
        Disk​(java.lang.String filename, int startBlocks)
      Construct a Disk and load the specified file.
        Disk​(java.lang.String filename, int startBlocks, boolean knownProDOSOrder)
      Construct a Disk and load the specified file.
      protected Disk​(java.lang.String filename, ImageOrder imageOrder)
      Construct a Disk with the given byte array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String[] getAllExtensions()
      Get the supported file extensions supported by the Disk interface.
      ByteArrayImageLayout getDiskImageManager()
      Returns the diskImageManager.
      java.lang.String getFilename()
      Returns the filename.
      static Disk.FilenameFilter[] getFilenameFilters()
      Get the supported file filters supported by the Disk interface.
      FormattedDisk[] getFormattedDisks()
      Determine type of disk, and return the appropriate FormattedDisk object.
      ImageOrder getImageOrder()
      Answer with the physical ordering of the disk.
      java.lang.String getOrderName()
      Returns the name of the underlying image order.
      int getPhysicalSize()
      Identify the size of this disk.
      boolean hasChanged()
      Indicates if the disk has changed.
      protected boolean is140KbDisk()
      Answers true if this disk image is within the expected 140K disk size.
      boolean is2ImgOrder()
      Indicate if this disk is a 2IMG disk.
      protected boolean is800KbDisk()
      Answers true if this disk image is within the expected 800K disk size.
      boolean isBXY()
      Indicate if this disk is a ShrinkIt-compressed binary II archive.
      boolean isCompressed()
      Indicate if this disk is GZIP compressed.
      boolean isCpmFormat()
      Test the disk format to see if this is a CP/M formatted disk.
      boolean isDC42()  
      boolean isDosFormat()
      Test the disk format to see if this is a DOS 3.3 formatted disk.
      boolean isDosOrder()
      Indicate if this disk is DOS ordered (T0,S0 - T35,S15).
      boolean isNakedosFormat()
      Test the disk format to see if this is a NakedOS formatted disk.
      boolean isNewImage()
      Indicates if the disk image is new.
      boolean isNibbleOrder()
      Indicate if this disk is a nibbilized disk..
      boolean isOzDosFormat()
      Test the disk format to see if this is a OzDOS formatted disk.
      boolean isPascalFormat()
      Test the disk format to see if this is a Pascal formatted disk.
      boolean isProdosFormat()
      Test the disk format to see if this is a ProDOS formatted disk.
      boolean isProdosOrder()
      Indicate if this disk is ProDOS ordered (beginning with block 0).
      boolean isRdos33Format()
      Test the disk format to see if this is a RDOS 33 formatted disk.
      boolean isRdosFormat()
      Test the disk format to see if this is a RDOS formatted disk.
      boolean isSDK()
      Indicate if this disk is a ShrinkIt-compressed disk image.
      boolean isSHK()
      Indicate if this disk is a ShrinkIt-compressed package.
      boolean isUniDosFormat()
      Test the disk format to see if this is a UniDOS formatted disk.
      boolean isWPFormat()
      Test the disk format to see if this is a WP formatted disk.
      void makeDosOrder()
      Change underlying image order to DOS ImageOrder.
      void makeProdosOrder()
      Change to a different ImageOrder.
      byte[] readBlock​(int block)
      Read the block from the disk image.
      byte[] readSector​(int track, int sector)
      Retrieve the specified sector.
      protected void resizeDiskImage​(int newSize)
      Resize a disk image up to a larger size.
      void save()
      Save a Disk image to its file.
      void saveAs​(java.lang.String filename)
      Save a Disk image as a new/different file.
      void setFilename​(java.lang.String filename)
      Sets the filename.
      protected void setImageOrder​(ImageOrder imageOrder)
      Set the physical ordering of the disk.
      static int sizeToFit​(long bytes)
      Find the standard sized disk that will fit the requested number of bytes.
      int testImageOrder()
      Test the image order to see if we can recognize a file system.
      void writeBlock​(int block, byte[] data)
      Write the block to the disk image.
      void writeSector​(int track, int sector, byte[] bytes)
      Write the specified sector.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Disk

        protected Disk​(java.lang.String filename,
                       ImageOrder imageOrder)
        Construct a Disk with the given byte array.
      • Disk

        public Disk​(java.lang.String filename)
             throws java.io.IOException
        Construct a Disk and load the specified file. Read in the entire contents of the file.
        Throws:
        java.io.IOException
      • Disk

        public Disk​(java.lang.String filename,
                    boolean knownProDOSOrder)
             throws java.io.IOException
        Construct a Disk and load the specified file. Read in the entire contents of the file.
        Throws:
        java.io.IOException
      • Disk

        public Disk​(java.lang.String filename,
                    int startBlocks)
             throws java.io.IOException
        Construct a Disk and load the specified file. Read in the entire contents of the file.
        Throws:
        java.io.IOException
      • Disk

        public Disk​(java.lang.String filename,
                    int startBlocks,
                    boolean knownProDOSOrder)
             throws java.io.IOException
        Construct a Disk and load the specified file. Read in the entire contents of the file.
        Throws:
        java.io.IOException
    • Method Detail

      • getFilenameFilters

        public static Disk.FilenameFilter[] getFilenameFilters()
        Get the supported file filters supported by the Disk interface. This is due to the fact that FilenameFilter is an inner class of Disk - without an instance of the class, the filters cannot be created.
      • getAllExtensions

        public static java.lang.String[] getAllExtensions()
        Get the supported file extensions supported by the Disk interface. This is used by the Swing UI to populate the open file dialog box.
      • testImageOrder

        public int testImageOrder()
        Test the image order to see if we can recognize a file system. Returns: 0 on recognition; -1 on failure.
      • save

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

        public void saveAs​(java.lang.String filename)
                    throws java.io.IOException
        Save a Disk image as a new/different file.
        Throws:
        java.io.IOException
      • getDiskImageManager

        public ByteArrayImageLayout getDiskImageManager()
        Returns the diskImageManager.
        Returns:
        ByteArrayImageLayout diskImageManager The disk Image Manager of this disk
      • getFilename

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

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

        public java.lang.String getOrderName()
        Returns the name of the underlying image order.
        Returns:
        String
      • isCompressed

        public boolean isCompressed()
        Indicate if this disk is GZIP compressed.
      • isSDK

        public boolean isSDK()
        Indicate if this disk is a ShrinkIt-compressed disk image.
      • isSHK

        public boolean isSHK()
        Indicate if this disk is a ShrinkIt-compressed package.
      • isBXY

        public boolean isBXY()
        Indicate if this disk is a ShrinkIt-compressed binary II archive.
      • isProdosOrder

        public boolean isProdosOrder()
        Indicate if this disk is ProDOS ordered (beginning with block 0).
      • isDosOrder

        public boolean isDosOrder()
        Indicate if this disk is DOS ordered (T0,S0 - T35,S15).
      • is2ImgOrder

        public boolean is2ImgOrder()
        Indicate if this disk is a 2IMG disk. This is ProDOS ordered, but with a header on the disk.
      • isNibbleOrder

        public boolean isNibbleOrder()
        Indicate if this disk is a nibbilized disk..
      • 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 java.lang.IllegalArgumentException
        Retrieve the specified sector.
        Throws:
        java.lang.IllegalArgumentException
      • writeSector

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

        public boolean isProdosFormat()
        Test the disk format to see if this is a ProDOS formatted disk.
      • isDosFormat

        public boolean isDosFormat()
        Test the disk format to see if this is a DOS 3.3 formatted disk. This is a little nasty - since 800KB and 140KB images have different characteristics. This just tests 140KB images.
      • isUniDosFormat

        public boolean isUniDosFormat()
        Test the disk format to see if this is a UniDOS formatted disk. UniDOS creates two logical disks on an 800KB physical disk. The first logical disk takes up the first 400KB and the second logical disk takes up the second 400KB.
      • isOzDosFormat

        public boolean isOzDosFormat()
        Test the disk format to see if this is a OzDOS formatted disk. OzDOS creates two logical disks on an 800KB physical disk. The first logical disk takes the first half of each block and the second logical disk takes the second half of each block.
      • isNakedosFormat

        public boolean isNakedosFormat()
        Test the disk format to see if this is a NakedOS formatted disk.
      • isPascalFormat

        public boolean isPascalFormat()
        Test the disk format to see if this is a Pascal formatted disk. Pascal disks may be either 140K or 800K.
      • isCpmFormat

        public boolean isCpmFormat()
        Test the disk format to see if this is a CP/M formatted disk. Check the first 256 bytes of the CP/M directory for validity.
      • is140KbDisk

        protected boolean is140KbDisk()
        Answers true if this disk image is within the expected 140K disk size. Can vary if a header has been applied or if this is a nibblized disk image.
      • is800KbDisk

        protected boolean is800KbDisk()
        Answers true if this disk image is within the expected 800K disk size. Can vary if a 2IMG header has been applied.
      • isRdosFormat

        public boolean isRdosFormat()
        Test the disk format to see if this is a RDOS formatted disk.
      • isRdos33Format

        public boolean isRdos33Format()
        Test the disk format to see if this is a RDOS 33 formatted disk.
      • isWPFormat

        public boolean isWPFormat()
        Test the disk format to see if this is a WP formatted disk.
      • isDC42

        public boolean isDC42()
      • 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.
      • makeDosOrder

        public void makeDosOrder()
        Change underlying image order to DOS ImageOrder. Assumes this is a 140k disk image.
        See Also:
        ImageOrder
      • makeProdosOrder

        public void makeProdosOrder()
        Change to a different ImageOrder. Remains in ProDOS format but the underlying order can change.
        See Also:
        ImageOrder
      • sizeToFit

        public static int sizeToFit​(long bytes)
        Find the standard sized disk that will fit the requested number of bytes.
        Returns:
        int size of the disk if it will satisfy the request, -1 otherwise