• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: design choices..

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem which has to deal with a file. The file has header information (about length of record etc) and then actual records. The header information is written using dataoutputstream. But the actual records after that are in the character (ASCI) format.
Now I have to do various operations on this file like:
1. Add record (at the end)
2. Delete record (from anywhere )
3. Search a particular record
5. Modify any field of any given record.
4. Lock a particular record.
I tried with RandomAccessFiles. Searching and adding the record is working fine. But I am not sure if I can lock a particular record if I use this randomaccessfile.
Also I am doing manipulations at byte level. (reading one record at a time, and each field in a separate array and then working on each array depending upon the requirement)
Is there any other/better way to do this? I guess I am not fully utilizing the java’s foundation classes.
Will this cause a problem if I have to make this service available at the server and use the RMI architecture to allow clients to do those operations?
I am quite confused as there are so many ways of dealing with file in JAVA. IS NIO is the best way to do this?
Detail answer is much appreciated.
Thanks in advance.
Manoj
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No replies so far? Very poor!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manoj
But I am not sure if I can lock a particular record if I use this randomaccessfile.

File level locking is not required. From memory, the current set of specifications state that while your application is running, no other applications will be accessing the data file.
So all you need to do is perform logical locking within your Data class. Keep track within the Data class of which records are currently locked, and dont allow other clients to lock them.
Also I am doing manipulations at byte level. (reading one record at a time, and each field in a separate array and then working on each array depending upon the requirement)

Sounds OK.
Is there any other/better way to do this? I guess I am not fully utilizing the java�s foundation classes.

Don't get too worried about that. The examiners (apparently) are lookiing for a reasonable design that works and that can be easily maintained. This is explained more clearly in the "words to live by" in the JavaRanch SCJD FAQ. So you don't have to worry about whether you are using every possible class that Sun have developed. If your code is simple to read and understand, and gets the job done, then you should be OK. (The exception of course, is if you develop code that duplicates an existing class that Sun have already developed, but I don't think you are in that category at present).
I am quite confused as there are so many ways of dealing with file in JAVA. IS NIO is the best way to do this?

You can use NIO if you like, but it is not essential. In fact, you do not even have to use Java 1.4 if you don't want to. Best thing for you to do is to try using NIO. Just write some simple classes to see how you can use it. Then decide for yourself if there is anything that it gives you that your current methodology doesnt.
Regards, Andrew
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Thanks a lot for the detial answer. I will consider these guidelines while designing my application. And will sure try on NIO to see if it is for me
Thanks for your help
manoj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic