Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-31-2008, 11:09 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Question data file structure
I just burnt out, been working on this ten days and have 1,800 lines of code. Am beginning to spin on how to store the data. I have one file I am generating test runs from, doing decent at it. I have placed markers in the data to find the five or ten fields with regexes, slow for a few hours but arrived at a design pattern that I just replicated for each of the fields. Somewhat clumsy but it works.

All the data that matters is vewable by client, and may be any of ascii / UTF-8 \u0020 through \u007e but regexes seem to be feed-forward only and make indeterminate conditions trying to arrive at patterns that regex functions well with that are not likely to be entered by user interface. I have a specialized class I rebuilt earlier today that makes field / value access cleanly all in one place in the code base. I am considering some sort of binary character and a dedicated data file buried in the folder tree. Moments ago I wrote the following test code:
Code:
public class test
{
    private static transient final java.lang.Character ETB= new java.lang.Character('\u001c');// end of transmission block
    private static transient final java.lang.Character GS = new java.lang.Character('\u001d');// group separator
    private static transient final java.lang.Character RS = new java.lang.Character('\u001e');// record separator
    private static transient final java.lang.Character US = new java.lang.Character('\u001f');// unit seprator
    String etb = new String("// end of transmission block ");
    String gs  = new String("// group separator ");
    String rs  = new String("// record separator ");
    String us  = new String("// unit seprator ");
    public static void main(String[] args)
    {
        // C:\\Documents and Settings\\All Users\\Documents\\Reports
        try
        {
            test tes= new test();
            java.io.FileWriter fw = new java.io.FileWriter("__blanked for posting__");//
            fw.write(US);
            fw.write(tes.etb,0,tes.etb.length());
            fw.write(GS);
            fw.write(tes.gs,0,tes.gs.length());
            fw.write(RS);
            fw.write(tes.rs,0,tes.rs.length());
            fw.write(US);
            fw.write(tes.us,0,tes.us.length());
            fw.flush();fw.close();
        }
        catch(java.lang.Throwable t){System.out.println(t.toString());}
    }
}
and opened the file with a text editor. Bad Bean if people who use this open the file with a Word Processor, just the sort of thing that could happen. Ideally, I would cleanly separate the data storage from display, but if I do not make the data readable with standard text editors, crash recover becomes bloated with all the places in the code that have to allow for that moment, I would rather have a jump-gap measure that gets over the moment and leads to open ended improvement.

Not to be demeaning, user is a twit. I have to allow for this.

I do not mind writing a great deal of code if it will deal with this, weak encipherment is appealing but makes data recovery a "get it right the first time." issue.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-05-2009, 09:53 PM
Steve11235's Avatar
Senior Member
 
Join Date: Dec 2008
Posts: 798
Rep Power: 1
Steve11235 is on a distinguished road
Default
I may not fully understand what you need to do, so if I whiff, just ignore me...

I suggest separating your fields with tab characters '\t' and data rows with new lines. I assume your user is on Windows, so that is "\r\n".

Make sure you always write out the full number of tabs, even if there is no data at the end of the line.

To recover the data, read a certain number of lines back into a String. You can read them all at once if the output file is not too large. Use String.split("\\r\\n") (escape the backslashes) to get an array of String, one for each record. On each record, use String.split("\\t") to get an array of String for each field. This is a very easy way to recover the data.

Your user can open the file using Excel. You can output a row of column headings in the first record if you want.

If you have multiple types of records, you can use the same approach, just make the first field a record type indicator, so you know what to expect when you read it back in.

I hope that helps...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-07-2009, 04:16 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default
I just went through an interview with client on the whole challenge, they are currently using an approach which is in the arena of your solution, I could code Java to work within the context ( I'm formulating preliminary concepting - whiffs are to be expected ) of excel, access and sql ... the ... uh ... several issues.

My thinking at the moment and when I wrote the above is to somehow disentangle data storage / recovery so far from conventional approaches that I have already commented out cr/lf from the static fields ( in my Java source code for several base classes )

To be sure, you understand what it is I am trying to do. And as well, my current "for my own use" implementation that I am already using relyed on a solution done within the framework your solution exists in.

There are performance problems with that approach, we are going to bust out of the loop entirely - I am going for some get-going code tonight that does it like java.io.DataOutput does it, eg a String has two bytes as the first field, indicating the length of the String.

What I am going for is some sort of "all binary" control fields that give data-typing, field sizes and so on,... and as a consequence of interview today with client, will just skip *all* the excel stuff and so on, including all the database based solutions, writing tabular data using JTables.

There are numerous issuse that are easy for me to overlook, gimme some whifs.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stack data structure in Java Java Tip java.lang 0 04-16-2008 10:34 PM
Doubly-linked list with data structure Java Tip java.lang 0 04-16-2008 10:30 PM
Queue data structure Java Tip java.lang 0 04-14-2008 08:35 PM
Help with a Graph Data Structure and the Shortest Path rhm54 New To Java 1 03-21-2008 03:14 PM
data structure code vgvt New To Java 1 01-17-2008 02:49 PM


All times are GMT +2. The time now is 02:54 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org