From 931dba77472db768d00f3f9f16e927c2b587008e Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Mon, 23 Dec 2002 21:05:32 +0000 Subject: [PATCH] Modiifed to read and write file entry from disk; added write type functions - delete, setFileData *save*, setFilename, etc. --- .../applecommander/storage/DosFileEntry.java | 178 ++++++++++++++++-- 1 file changed, 162 insertions(+), 16 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/DosFileEntry.java b/src/com/webcodepro/applecommander/storage/DosFileEntry.java index 58a3286..0049a7e 100644 --- a/src/com/webcodepro/applecommander/storage/DosFileEntry.java +++ b/src/com/webcodepro/applecommander/storage/DosFileEntry.java @@ -30,16 +30,60 @@ import java.util.List; * @author: Rob Greene */ public class DosFileEntry implements FileEntry { - private byte[] fileEntry; + /** + * Indicates the length in bytes of the DOS file entry field. + */ + public static final int FILE_DESCRIPTIVE_ENTRY_LENGTH = 35; + /** + * Holds the disk the FileEntry is attached to. + */ private DosFormatDisk disk; + /** + * Track of the FileEntry location. + */ + private int track; + /** + * Sector of the FileEntry location. + */ + private int sector; + /** + * Offset into sector of FileEntry location. + */ + private int offset; /** * Constructor for DosFileEntry. */ - public DosFileEntry(byte[] fileEntry, DosFormatDisk disk) { + public DosFileEntry(DosFormatDisk disk, int track, int sector, int offset) { super(); - this.fileEntry = fileEntry; this.disk = disk; + this.track = track; + this.sector = sector; + this.offset = offset; + } + + /** + * Read the FileEntry from the disk image. + */ + protected byte[] readFileEntry() { + byte[] sectorData = disk.readSector(track, sector); + byte[] fileEntry = new byte[FILE_DESCRIPTIVE_ENTRY_LENGTH]; + System.arraycopy(sectorData, offset, fileEntry, 0, fileEntry.length); + return fileEntry; + } + + /** + * Write the FileEntry to the disk image. + */ + protected void writeFileEntry(byte[] fileEntry) { + if (fileEntry.length != FILE_DESCRIPTIVE_ENTRY_LENGTH) { + throw new IllegalArgumentException( + "A DOS 3.3 file entry must be " + FILE_DESCRIPTIVE_ENTRY_LENGTH + + " bytes long!"); + } + byte[] sectorData = disk.readSector(track, sector); + System.arraycopy(fileEntry, 0, sectorData, offset, fileEntry.length); + disk.writeSector(track, sector, sectorData); } /** @@ -47,12 +91,16 @@ public class DosFileEntry implements FileEntry { * @see com.webcodepro.applecommander.storage.FileEntry#getFilename() */ public String getFilename() { - byte[] filename = new byte[30]; - System.arraycopy(fileEntry, 3, filename, 0, filename.length); - for (int i=0; i