Data structure quextion

Hey,



I asked this question in the forum for my computer science class at school and nobody answered me. . I guess the question was too advanced for the instructor or something? Well maybe someone here can give me a step in the right direction :slight_smile: Here it is:



Hi,



    This is off-topic from the assignment but still related to Java. I am working on a project that enables an interface to store, load, and unload files into one container file. This container file class will be able to support a tree like file structure. Essentially it will represent a mini file system within one file so when I pass a path and file name to a load method, say like, "modelsvehiclesm1a.obj" it will be able to return a reference to the data.



    I am not concerned with the physical means of storing and loading data but the best way to represent the data structure of the internal file system of the container file. The best idea I have is a linked list although would I represent each directory node with another linked list of file header classes? Also after some research I found that the java.io.File is able to create a representation of file and directory names but any example I come across uses the java.io.File in the practical manner to access real files on the HD.



    So again the best way I have thought of is using a linked list of linked lists to represent directory names but thinking on that I can foresee having to check what the object I am dealing with for each iteration, so I just thought I would probe for a simpler solution.



Thanks,

Chris

Is actually storing the file system tree necessary? I am using this kind of archive format in jME3, and I am just storing a table of hashes to entries, there's no concept of trees or anything like that in the code or data structures. After all, you just need to be able to read a file with a certain name, right? If you need to find out all the files in a directory, that's possible too, with directory nodes which contain a list of files inside the directory. This pretty much gives you all the information you would ever need without even having a tree structure in memory.

Your question of necessity is a good one. I decided that implementing a resource file manager with the ability to take directory names would be worthy for code readability and organization. So far I think I am on the right track by creating a linked list of FileHeader classes and within each class is another linked list. So the nested linked list will be a list of files. Here is the beginning of my implementation which is still being worked out, when I finish this it could become a suitable tutorial for the website on implementing a resource file in java for games and such. Heh, or maybe its crap and nobody wants it. .



//////////////////////////////
// Filename: GRFS.java
// Created By: Christopher Brandt
// Purpose: GRFS -- Generic Resource File System --
// To create an interface that allows the storing, loading, and unloading
// of any type of file into a resource container file. The GRFS will ensure
// that the resource container file was not externally modified before loading.
// In addition to ensuring container file integrity the GRFS will provide
// a level of protection for the files contained within from external extraction.
// Created Date:
//////////////////////////////

import java.util.LinkedList;
import java.util.ListIterator;
import java.io.*;

public class GRFS
{
   private ObjectInputStream oisObjInput;
   private ObjectOutputStream oosObjOutput;

   private GRFSHeader topHeader;
   
   private class GRFSHeader implements Serializable
   {
      private final String sSignature = "-- Generic Resource File System --n";
      private float fVersion;
      private int iNumFiles;
      private int iNumDirs;
      
      private long iChecksum;
      
      private LinkedList<FileHeader> listDirectory;
      
      public GRFSHeader()
      {
         this.fVersion = 0.01f;
         this.iNumFiles = 0;
         this.iNumDirs = 0;
         
         this.iChecksum = 0;
         
         this.listDirectory = null;
      }
      
      public GRFSHeader(GRFSHeader copyGRFSHeader)
      {
         this.fVersion = copyGRFSHeader.fVersion;
         this.iNumFiles = copyGRFSHeader.iNumFiles;
         this.iNumDirs = copyGRFSHeader.iNumDirs;
         
         this.iChecksum = copyGRFSHeader.iChecksum;
         this.listDirectory = copyGRFSHeader.listDirectory;
      }
   }
   
   private class FileHeader implements Serializable
   {
      private String sFileName;
      // Size of file in bytes
      private long lSize;
      private long lOffset;
      
      private LinkedList<FileHeader> listFileHeader;
      
      public FileHeader()
      {
         lSize = 0;
         lOffset = 0;
         
         listFileHeader = null;
      }
   }



Thanks for reading.
Chris