From 016549d07e846d030d3cbac49c29c057b6de3956 Mon Sep 17 00:00:00 2001 From: a2geek Date: Fri, 18 Sep 2026 17:22:49 -0500 Subject: [PATCH] Decision: Separate "writable" interfaces for FileEntry and Directory. --- .../storage/DiskFileStoreAdapter.java | 13 +++--- .../archive/shrinkit/ShrinkitFileEntry.java | 15 ------ .../archive/zip/ZipFileEntry.java | 15 ------ .../applecommander/filestore/Directory.java | 3 +- .../applecommander/filestore/FileEntry.java | 18 -------- .../filestore/WritableDirectory.java | 26 +++++++++++ .../filestore/WritableFileEntry.java | 46 +++++++++++++++++++ 7 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 lib/ac-api/src/main/java/org/applecommander/filestore/WritableDirectory.java create mode 100644 lib/ac-api/src/main/java/org/applecommander/filestore/WritableFileEntry.java diff --git a/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/DiskFileStoreAdapter.java b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/DiskFileStoreAdapter.java index ace226de..3575a1b1 100644 --- a/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/DiskFileStoreAdapter.java +++ b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/DiskFileStoreAdapter.java @@ -28,14 +28,13 @@ import com.webcodepro.applecommander.storage.os.prodos.ProdosDirectoryEntry; import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk; import com.webcodepro.applecommander.storage.os.rdos.RdosFormatDisk; import org.applecommander.capability.Capability; -import org.applecommander.filestore.Directory; -import org.applecommander.filestore.DisplayColumn; +import org.applecommander.filestore.*; import org.applecommander.filestore.FileEntry; -import org.applecommander.filestore.FileStore; import org.applecommander.usage.BlockUsage; import org.applecommander.usage.DiskUsage; import org.applecommander.usage.SectorUsage; import org.applecommander.util.Container; +import org.applecommander.util.DataBuffer; import java.util.ArrayList; import java.util.BitSet; @@ -174,7 +173,7 @@ public class DiskFileStoreAdapter implements FileStore { * The DiskFileEntryAdapter is a shim that allows a FileEntry to be mapped into the * new/evolving FileEntry interface(s). */ - public static class DiskFileEntryAdapter implements FileEntry { + public static class DiskFileEntryAdapter implements WritableFileEntry { private final DiskFileStoreAdapter adapter; private final DiskDirectoryAdapter parent; private final com.webcodepro.applecommander.storage.FileEntry fileEntry; @@ -213,15 +212,15 @@ public class DiskFileStoreAdapter implements FileStore { throw new RuntimeException("Not supported by the legacy AppleCommander."); } @Override - public void setDataFork(byte[] fileData) { + public void setDataFork(DataBuffer fileData) { try { - fileEntry.setFileData(fileData); + fileEntry.setFileData(fileData.asBytes()); } catch (DiskFullException e) { throw new RuntimeException(e); } } @Override - public void setResourceFork(byte[] data) { + public void setResourceFork(DataBuffer data) { throw new RuntimeException("Not supported by the legacy AppleCommander."); } @Override diff --git a/lib/ac-api/src/main/java/org/applecommander/archive/shrinkit/ShrinkitFileEntry.java b/lib/ac-api/src/main/java/org/applecommander/archive/shrinkit/ShrinkitFileEntry.java index b5d06a90..1245139e 100644 --- a/lib/ac-api/src/main/java/org/applecommander/archive/shrinkit/ShrinkitFileEntry.java +++ b/lib/ac-api/src/main/java/org/applecommander/archive/shrinkit/ShrinkitFileEntry.java @@ -61,11 +61,6 @@ public class ShrinkitFileEntry implements FileEntry { return headerBlock.getFilename(); } - @Override - public void setName(String name) { - throw new UnsupportedOperationException(); - } - @Override public long getSize() { return headerBlock.getUncompressedSize(); @@ -197,16 +192,6 @@ public class ShrinkitFileEntry implements FileEntry { return decompress(headerBlock.getResourceForkThreadRecord()); } - @Override - public void setDataFork(byte[] data) { - throw new UnsupportedOperationException(); - } - - @Override - public void setResourceFork(byte[] data) { - throw new UnsupportedOperationException(); - } - @Override public Optional get(Class iface) { return Container.get(iface, headerBlock); diff --git a/lib/ac-api/src/main/java/org/applecommander/archive/zip/ZipFileEntry.java b/lib/ac-api/src/main/java/org/applecommander/archive/zip/ZipFileEntry.java index 2b3df2b2..c22bf6a8 100644 --- a/lib/ac-api/src/main/java/org/applecommander/archive/zip/ZipFileEntry.java +++ b/lib/ac-api/src/main/java/org/applecommander/archive/zip/ZipFileEntry.java @@ -65,11 +65,6 @@ public class ZipFileEntry implements FileEntry { return entry.getName(); } - @Override - public void setName(String name) { - throw new UnsupportedOperationException(); - } - @Override public long getSize() { return entry.getSize(); @@ -133,16 +128,6 @@ public class ZipFileEntry implements FileEntry { throw new UnsupportedOperationException(); } - @Override - public void setDataFork(byte[] data) { - throw new UnsupportedOperationException(); - } - - @Override - public void setResourceFork(byte[] data) { - throw new UnsupportedOperationException(); - } - @Override public Optional get(Class iface) { return Container.get(iface, fileStore, entry); diff --git a/lib/ac-api/src/main/java/org/applecommander/filestore/Directory.java b/lib/ac-api/src/main/java/org/applecommander/filestore/Directory.java index 409db917..1892b496 100644 --- a/lib/ac-api/src/main/java/org/applecommander/filestore/Directory.java +++ b/lib/ac-api/src/main/java/org/applecommander/filestore/Directory.java @@ -24,11 +24,10 @@ import java.util.Optional; import java.util.stream.Collectors; /** - * A DirectoryEntry represents a directory in a FileStore. Note that even + * A Directory represents a directory in a FileStore. Note that even * FileStores that don't naturally support a directory do contain a root directory, * so there will be a directory associated to each FileStore. */ -// TODO FUTURE should create file be deferred to a container operation? Not everything will support file creation. public interface Directory { /** * Get the parent directory. If this is the root directory, it returns empty. diff --git a/lib/ac-api/src/main/java/org/applecommander/filestore/FileEntry.java b/lib/ac-api/src/main/java/org/applecommander/filestore/FileEntry.java index e04b3a4e..fd258ea7 100644 --- a/lib/ac-api/src/main/java/org/applecommander/filestore/FileEntry.java +++ b/lib/ac-api/src/main/java/org/applecommander/filestore/FileEntry.java @@ -45,11 +45,6 @@ public interface FileEntry extends Container { * Note that depending on context, this may be a computed field. */ String getName(); - /** - * Allows the name of this entry to be changed (depending on the {@link Capability} - * allowed by the underlying {@link FileStore}). - */ - void setName(String name); /** * Returns the size, in bytes, of this item. * It may be approximate (based off a sector count, for instance). @@ -73,17 +68,4 @@ public interface FileEntry extends Container { // TODO should resource form reading and writing be deferred to a container operation? // ... Then we don't need capability (which is our test) and we don't have to implement no-op functions. byte[] getResourceFork(); - /** - * Store the file's data. - * This does not include any metadata that may be embedded with the file. - */ - // TODO should write capability be deferred to a resource as well? - void setDataFork(byte[] data); - /** - * Store the resource fork data. - * This may not be supported and may throw an exception. - * @see Capability - */ - // TODO ditto... - void setResourceFork(byte[] data); } diff --git a/lib/ac-api/src/main/java/org/applecommander/filestore/WritableDirectory.java b/lib/ac-api/src/main/java/org/applecommander/filestore/WritableDirectory.java new file mode 100644 index 00000000..a8cc1564 --- /dev/null +++ b/lib/ac-api/src/main/java/org/applecommander/filestore/WritableDirectory.java @@ -0,0 +1,26 @@ +/* + * AppleCommander - An Apple ][ image utility. + * Copyright (C) 2026 by Robert Greene and others + * 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 org.applecommander.filestore; + +/// A WritableDirectory is a Directory that allows file creation. +public interface WritableDirectory { + /// Create a file. By definition, any file created is a WritableFileEntry. + WritableFileEntry createFile(); +} diff --git a/lib/ac-api/src/main/java/org/applecommander/filestore/WritableFileEntry.java b/lib/ac-api/src/main/java/org/applecommander/filestore/WritableFileEntry.java new file mode 100644 index 00000000..0689a133 --- /dev/null +++ b/lib/ac-api/src/main/java/org/applecommander/filestore/WritableFileEntry.java @@ -0,0 +1,46 @@ +/* + * AppleCommander - An Apple ][ image utility. + * Copyright (C) 2026 by Robert Greene and others + * 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 org.applecommander.filestore; + +import org.applecommander.capability.Capability; +import org.applecommander.util.Container; +import org.applecommander.util.DataBuffer; + +/** + * A WritableFileEntry represents a single, writable file on disk. + */ +public interface WritableFileEntry extends FileEntry, Container { + /** + * Allows the name of this entry to be changed (depending on the {@link Capability} + * allowed by the underlying {@link FileStore}). + */ + void setName(String name); + /** + * Store the file's data. + * This does not include any metadata that may be embedded with the file. + */ + void setDataFork(DataBuffer data); + /** + * Store the resource fork data. + * This may not be supported and may throw an exception. + * @see Capability + */ + void setResourceFork(DataBuffer data); +}