Added resizeDiskImage capability.

This commit is contained in:
Robert Greene 2003-05-02 02:54:52 +00:00
parent b3716c3195
commit bda3c40749
2 changed files with 25 additions and 0 deletions

View File

@ -266,6 +266,23 @@ public class Disk {
return diskImage.length; return diskImage.length;
} }
/**
* 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.
* @param newSize
*/
protected void resizeDiskImage(int newSize) {
if (newSize < diskImage.length) {
throw new IllegalArgumentException(
"Cannot resize a disk to be smaller than the current size!");
}
byte[] newDiskImage = new byte[newSize];
System.arraycopy(diskImage, 0, newDiskImage, 0, diskImage.length);
diskImage = newDiskImage;
}
/** /**
* Read the block from the disk image. * Read the block from the disk image.
*/ */

View File

@ -354,4 +354,12 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
public FormattedDisk getFormattedDisk() { public FormattedDisk getFormattedDisk() {
return this; return this;
} }
/**
* Resize the disk image to be its full size. Only invole this
* method if a size does not match exception is thrown.
*/
public void resizeDiskImage() {
resizeDiskImage(getFreeSpace() + getUsedSpace());
}
} }