Strategy for read and rewind file for unordered data

Discussion in 'Java' started by iksrazal@terra.com.br, Aug 25, 2005.

  1. Guest

    Hi all,

    I have to create an element tree as follows:

    Data A
    |
    |
    Data B
    |
    |
    Data C

    There can be multiple Data A, each of which can have many Data B, and
    each Data B can have many Data C. There is no order in the file in
    which Data A, Data B, Data C can appear - only a marker 'Data A', for
    example at the beginning of a line. The file size is two megs - but %90
    percent is ignored. There are multiple files, but the data is seperate
    and should have no dependency clashes.

    My first thought is to do it as such:

    RandomAccessFile raf = new RandomAccessFile("BSS0","r");
    InputStream in = new FileInputStream(raf.getFD());
    BufferedReader reader = new BufferedReader ( new InputStreamReader ( in
    ) );
    while ((line = reader.readLine()) != null) {
    // find data A
    Scanner sc = new Scanner(line);
    }
    // now, rewind raf
    raf.seek(0);

    repeat finding Data B which matches data A, and Data C which matches
    Data B.

    In essence re-reading the same file several times.

    The other thing is the collection. How would one map a Data A
    one-to-many relationship to Data B, which has a one-to-many
    relationship with Data C?

    I'm just getting started, but I'd appreciate any ideas.
    iksrazal
     
    , Aug 25, 2005
    #1
    1. Advertising

  2. Roedy Green Guest

    On 25 Aug 2005 13:18:41 -0700, wrote or quoted :

    >There can be multiple Data A, each of which can have many Data B, and
    >each Data B can have many Data C. There is no order in the file in
    >which Data A, Data B, Data C can appear - only a marker 'Data A', for
    >example at the beginning of a line. The file size is two megs - but %90
    >percent is ignored. There are multiple files, but the data is seperate
    >and should have no dependency clashes.


    How about a serialised tree file with just the links in it as an index
    file. You read this in its entirety into RAM.

    It has pointers in it, offsets in the random access file, where to
    find the bulk data for the corresponding node.

    You can then access the data of the node in a single read.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com
     
    Roedy Green, Aug 26, 2005
    #2
    1. Advertising

  3. Guest

    Roedy Green escreveu:

    > How about a serialised tree file with just the links in it as an index
    > file. You read this in its entirety into RAM.
    >
    > It has pointers in it, offsets in the random access file, where to
    > find the bulk data for the corresponding node.
    >
    > You can then access the data of the node in a single read.


    Hi Roedy,

    Hmm. Not sure I understand "serialised tree file". I looked
    unsuccesfully in your glossary for "tree file" - I think what you mean
    is sort of a composite pattern based b-tree. Googling for "java tree
    file" didn't turn up much.

    I know about memory-mapped files, is that what you meant? I know how
    offsets work with RandonAccessFile, is there a memory based equivalent?


    Thanks for the reply,
    iksrazal
     
    , Aug 26, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rajorshi  Biswas
    Replies:
    3
    Views:
    390
    Rajorshi Biswas
    Jul 20, 2006
  2. rainny
    Replies:
    2
    Views:
    494
    Roedy Green
    Mar 9, 2009
  3. Kuhl

    Rewind file offset

    Kuhl, Apr 10, 2009, in forum: C Programming
    Replies:
    4
    Views:
    521
    Richard Bos
    Apr 13, 2009
  4. Lynn McGuire

    rewind writing to a text file

    Lynn McGuire, Dec 4, 2010, in forum: C++
    Replies:
    7
    Views:
    588
    Default User
    Dec 7, 2010
  5. Alan Davies
    Replies:
    7
    Views:
    239
    Alan Davies
    Nov 27, 2003
Loading...

Share This Page