diff --git a/src/main/java/com/webcodepro/applecommander/storage/Disk.java b/src/main/java/com/webcodepro/applecommander/storage/Disk.java index 41896ec..fb01ffc 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/Disk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/Disk.java @@ -369,10 +369,10 @@ public class Disk { /** * Determine type of disk, and return the appropriate - * FormattedDisk object. Returns null if none are - * recognized. + * FormattedDisk object. Throws an Exception if none is recognized. + * @throws DiskUnrecognizedException */ - public FormattedDisk[] getFormattedDisks() { + public FormattedDisk[] getFormattedDisks() throws DiskUnrecognizedException { if (isProdosFormat()) { return new FormattedDisk[] { new ProdosFormatDisk(filename, imageOrder) }; @@ -407,7 +407,7 @@ public class Disk { return new FormattedDisk[] { new GutenbergFormatDisk(filename, imageOrder) }; } - return null; + throw new DiskUnrecognizedException(filename); } /** diff --git a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java index 56d74ec..f4c4681 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java @@ -267,14 +267,8 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry { * Locate a specific file by filename. * Returns a null if specific filename is not located. */ - public FileEntry getFile(String filename) { - List files; - try { - files = getFiles(); - } catch (DiskException e) { - // FIXME how to warn the User about this? - files = new ArrayList<>(); - } + public FileEntry getFile(String filename) throws DiskException { + List files = getFiles(); return getFile(files, filename.trim()); } @@ -283,19 +277,15 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry { * Note that in the instance of a system with directories (ie, ProDOS), * this really returns the first file with the given filename. */ - protected FileEntry getFile(List files, String filename) { + protected FileEntry getFile(List files, String filename) throws DiskException { FileEntry theFileEntry = null; if (files != null) { for (int i=0; i 0)) { // Add a final directory separator if the user didn't supply one @@ -331,19 +331,15 @@ public class ac { } FormattedDisk[] formattedDisks = disk.getFormattedDisks(); for (int i = 0; i < formattedDisks.length; i++) { - try { - FormattedDisk formattedDisk = formattedDisks[i]; - writeFiles(formattedDisk.getFiles(), directory); - } catch (DiskException e) { - // FIXME How to warn user about the problem? - } + FormattedDisk formattedDisk = formattedDisks[i]; + writeFiles(formattedDisk.getFiles(), directory); } } /** * Recursive routine to write directory and file entries. */ - static void writeFiles(List files, String directory) throws IOException { + static void writeFiles(List files, String directory) throws IOException, DiskException { Iterator it = files.iterator(); while (it.hasNext()) { FileEntry entry = (FileEntry) it.next(); @@ -360,11 +356,7 @@ public class ac { output.write(buf, 0, buf.length); output.close(); } else if (entry.isDirectory()) { - try { - writeFiles(((DirectoryEntry) entry).getFiles(),directory+entry.getFilename()+File.separator); - } catch (DiskException e) { - // FIXME How to warn user about the problem? - } + writeFiles(((DirectoryEntry) entry).getFiles(),directory+entry.getFilename()+File.separator); } } } @@ -375,7 +367,7 @@ public class ac { * file with the given filename. * @deprecated */ - static FileEntry getEntry(List files, String fileName) { + static FileEntry getEntry(List files, String fileName) throws DiskException { FileEntry entry = null; if (files != null) { for (int i = 0; i < files.size(); i++) { @@ -384,13 +376,11 @@ public class ac { if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) { return entry; } - if (entry.isDirectory()) try { + if (entry.isDirectory()) { entry = getEntry(((DirectoryEntry) entry).getFiles(), fileName); if (entry != null) { return entry; } - } catch (DiskException e) { - // FIXME How to warn user about the problem? } } } @@ -433,7 +423,7 @@ public class ac { * system with directories (e.g. ProDOS), this really returns the first file * with the given filename. */ - static void showFiles(List files, String indent, int display) { + static void showFiles(List files, String indent, int display) throws DiskException { for (int i = 0; i < files.size(); i++) { FileEntry entry = (FileEntry) files.get(i); if (!entry.isDeleted()) { @@ -446,12 +436,8 @@ public class ac { System.out.println(); } if (entry.isDirectory()) { - try { - showFiles(((DirectoryEntry) entry).getFiles(), - indent + " ", display); //$NON-NLS-1$ - } catch (DiskException e) { - // FIXME How to warn user about the problem? - } + showFiles(((DirectoryEntry) entry).getFiles(), + indent + " ", display); //$NON-NLS-1$ } } } @@ -459,7 +445,7 @@ public class ac { /** * Display information about each disk in args. */ - static void getDiskInfo(String[] args) throws IOException { + static void getDiskInfo(String[] args) throws IOException, DiskException { for (int d = 1; d < args.length; d++) { Disk disk = new Disk(args[d]); FormattedDisk[] formattedDisks = disk.getFormattedDisks(); @@ -513,7 +499,7 @@ public class ac { * Pascal disks; others ignored. Proposed by David Schmidt. */ public static void setDiskName(String imageName, String volName) - throws IOException { + throws IOException, DiskException { Disk disk = new Disk(imageName); if (!disk.isSDK() && !disk.isDC42()) { FormattedDisk[] formattedDisks = disk.getFormattedDisks();