#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    First array values < second array values


    Java:
    Two arrays
    first: [2,9,19]
    second: [13,24]

    I want to be able to link
    2 <---> 13
    9 <---> 13
    19 <---> 24

    So that a value in the first array will always be associated with a value that is higher than it in the second array. I'm using it for file start/end offsets in a byte[] for data carving purposes.

    int firstPos = 0;
    int secondPos = 0;

    try
    {
    for (int i = secondPos; i < second.length; i++)
    {
    while ( second[secondPos] > first[firstPos] )
    {
    System.out.println(first[firstPos] + "<---->" + second[secondPos]);
    firstPos ++;
    }
    } // end for
    } // end try
    catch (Exception aoob)
    {
    System.out.println("An exception: " + aoob);
    // array index out of bounds
    }

    This only allows 2<---> 13 and 9<---> 13
    The exception kicks in before 19<--->24 can be viewed
    How can 19 <--->24 be viewed?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0
    I've done a work around using:

    int startPos = 0;

    try
    {
    for (int i = 0; i < second.length; i ++)
    {
    while (first[startPos] < second[i])
    {
    // code to carve data
    System.out.println("Data carve from offset " + first[startPos]
    + " <----> " + second[i]);

    if ( startPos < first.length )
    {
    startPos ++;
    }
    } // end while
    } // end for
    } // end try
    catch (ArrayIndexOutOfBoundsException aie)
    {
    // code to add the final carved data
    System.out.println("\nIf duplicated will be removed by code:");
    System.out.println("Data carve from offset " + first[first.length -1] + " <----> " + second[second.length -1]);
    System.out.println("(An Exception " + aie + ")");
    }

    ====

    I know it is ugly code, is there a way of making it neater? I plan to store offsets in a HashMap <Object(start; end), Boolean forCarve > so duplicate offsets will be ignored.

IMN logo majestic logo threadwatch logo seochat tools logo