Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Emulating a filesystem in Java for configuration managment?

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Emulating a filesystem in Java for configuration managment?

    Hi there,

    I am looking for a way to emulate a filesystem in Java to manage my configuration. The program has a readline library that I am using to provide a primitive shell for interaction.

    Originally I was trying to do something with hashmaps but that did not go so well since java would not let me use the <?> generic everywhere. So my idea has shifted more to using the FileSystemProvider class to create a fake filesystem that I can store the config inside of. But due to the lack of tutorials / examples I am unable to figure out the URI for a RAM based filesystem. All the examples I have seen are for ZIP based filesystems. The other problem is I want the filesystem to use fake files kinda like pointers to variables or method in my class files rather than actual files in a folder. Can this be done?

    The entire configuration will be saved out to an XML file. I want to use the filesystem just as a means of providing an interface for editing the config.

    Can anyone give me some insight on this?

    Thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    What kind of interface to the "filesystem" are you looking for?
    Sequential reads and writes?
    Random reads and writes?
    Keyed?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    The interface to the filesystem would be shell prompt created by a readline (specifically JLine2 for now) library.

    As far as Sequential or Random writes, I am not sure if this applies. I am not actually trying to make a full blown FS. I am trying to create a pseudo filesystem that will be used to represent the configuration values in my program. In a similar way to how SysFS is to the Linux kernel.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    By interface I meant what kind of methods do you want to have to use the filesystem? What would those methods do? How and why would application code use those methods?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    The initial methods would be simple. For example I have a method that adds a new server to the root of my configuration the method is called from the configFS.addServer(). There is also an opposite to that method which will remove a server from the config. From within each server there is separate config values for things like setIPaddress() and setSSHportNumber.

    How this relates to the filesystem is I want the various parts of the structure to be built as the methods are called. So for example when a new server is called I want a fake directory to be created that the player could "cd" into and modify the various default values for the server. The set methods would be more related to changing values of the fake files. For example if I have a "file" that controls which ssh port to use for the connection I want the method to simply change an int which would reflect the port number.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    So one of the methods would be to implement a "cd". Others would allow changing values of the fake files. I'd assume that would imply creating and deleting files.
    method to simply change an int.
    For that do you mean that one of the files contains an int value that you want to change. Besides changing the values (attributes?? R/O etc) of a file, you also need a way to change a file's contents.

    So far the requirements sound like a normal disk filesystem. Why the need for a new one?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    Yes a file would contain a value. Lets say the file is called "port" and it lives in "/server01/ssh/port". To change it would require using a command like "set port 22" which would change value of the ssh port number to 22 while you are sitting in the ssh directory. Follow me?

    As far as attributes I was thinking about that. At the moment I don't see a reason to add attributes because this is a just a representation of the config. All I could say about that right now is maybe later.

    When you ask "why the need for a new one?" I don't quite follow. The entire FS would just be the representation of an XML config file. The FS structure is make the config easier to work with so as to prevent errors by the user.

    I had considered the idea of making an actual filesystem contained inside a directory that would be considered root but I thought it would make to many files that don't really need to be there.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    set port 22
    That looks like something used on a command line. What would the code for the java method look like? Would there be a method that has a filename and a value as args and writes that value in the file? Would there be different methods for different data types? Would the files be associated with data types so you can't write an int and try to read a String? The files sound like variables.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    Ok... this question has veered off of my original point of asking it.

    The problem is I don't really have any methods to use as examples because as my plan goes I need a structure to hold my data before I build the methods to work on the data.

    What I am trying to really determine is if an actual filesystem in memory is the right direction or not. Since my entire configuration will be stored inside of an XML file.

    I also completely screwed up asking the first question correctly in the first place. What I REALLY MEANT to ask was more in concept to how I could emulate a directory structure in Java. The reason I kept throwing around filesystem in because I was going to use that package initally to implement the structure, later realizing that I could get creative with some maps and such I am pretty sure.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    Are you closer to a solution now?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    Not really...

    The issue I am having is trying to figure out the best way to create the tree. Originally I was going to use the HashMap class for the root tree use the generics <String, ?> which would allow me to make the value almost anything. This would allow me to make something that resembles a directory tree. The problem I am running into is when I got one level down. Eclipse says it cannot instansiate a second instance of HashMap <String, ?> which would resemble the contents of a directory that is sitting at root.

    import java.util.HashMap;
    import java.util.Map;
     
     
    public class Example {
     
    	private Map <String, ?> config;
     
    	public Example() {
     
    		// This will initialize a new configuration on construction.
    		config = new HashMap <> ();
     
    	}
     
    	public void add_directory(String par1) {
     
    		config.put(par1, new HashMap <String, ?> ());
     
    	}
     
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    Did you try Object vs ?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Location
    Columbus, Ohio, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    No I did not. That might work let me try.

    This may sound vague but what is considered and object? pretty much everything right? or are thing like char not objects?

    --- Update ---

    Yep that allowed me to instantiate a hashmap with in a hashmap without an error.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,997
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: Emulating a filesystem in Java for configuration managment?

    but what is considered and object? pretty much everything right
    All classes extend the Object class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Reading DTM (digital terrain managment) files
    By MrShazzyMan in forum Java Theory & Questions
    Replies: 5
    Last Post: December 24th, 2012, 06:48 AM
  2. HOw to find out FileSystem Information
    By kewlkeny in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 30th, 2012, 04:44 AM
  3. configuration of custom error pages in Webserver level
    By dpkcv in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 10th, 2011, 04:29 AM
  4. How to display OS configuration ffrom JSF page?
    By rcbandit2 in forum JavaServer Pages: JSP & JSTL
    Replies: 5
    Last Post: August 4th, 2011, 05:59 PM
  5. CAS Configuration Problem
    By pacificz in forum Java Theory & Questions
    Replies: 1
    Last Post: July 24th, 2010, 12:44 PM