mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-10-24 23:02:27 +00:00
Decision: Separate "writable" interfaces for FileEntry and Directory.
This commit is contained in:
1 parent
16b6f047f0
commit
016549d07e
7 files changed
+79
-57
No files matched your search
+6
-7
@@ -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
|
||||
|
||||
@@ -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 <T> Optional<T> get(Class<T> iface) {
|
||||
return Container.get(iface, headerBlock);
|
||||
|
||||
@@ -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 <T> Optional<T> get(Class<T> iface) {
|
||||
return Container.get(iface, fileStore, entry);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user