0

I have a ton of data I pulled from an ARINC 429 bus through wireshark that is just raw data in hex. When I try to open it in notepad, it reads the data as ascii. I'm trying to parse the data and separate it into words. Looking at the data in wireshark, I know that the words start with the hex 0x10 0x42 and end with 0x10 0x03. I can't get java to read the file and separate it into words using those delimiters. I pulled the data out as C arrays and put it here. Here is a sample of the data I'm trying to parse. http://www.filedropper.com/datasample

I have some experience with java, but still relatively new. Any help on how to get java to read this without losing data would be greatly appreciated.

This is what I've tried so far:

public class FileData {
    public static void main(String[] args) {

    String file_name = "C:/Users/dhamilton/Documents/20160816 test flight/this one.txt";

    String[] delimiter = new String[256];
    String[] labels = new String[256];

    for (int j = 0; j < 256; j++) {
        String hex = Integer.toHexString(j);
        delimiter[j] = "0x10, 0x41, 0x" + hex;

        String oct = Integer.toOctalString(j);

        labels[j] = oct;
    }

    try {
        ReadFile file = new ReadFile(file_name);
        String[] aryLines = file.OpenFile();

        //String sure = Integer.toBinaryString(i); //FIX THIS
            //System.out.println(sure);


        for (int i=0; i<aryLines.length; i++) {
            //System.out.println(aryLines[i].length() + "\t" + aryLines[i]);
            for (int p=0; p<255; p++) {
                if (aryLines[i].contains(delimiter[p])) {
                    file.addOne(p);
                }
            }      
        }

        for (int q=0; q<256; q++) {
            if (file.getCounter(q) != 0) {
                System.out.println("Label " + labels[q] + ":\t" + file.getCounter(q));
            }
        }
    }
    catch (IOException e) {
        System.out.println(e.getMessage());
    }

}
}

As well as:

public class ReadFile {
public String path;
public int[] counter = new int[256];


public ReadFile(String file_path) {
    path = file_path;
}

int readLines() throws IOException {
    FileReader file_to_read = new FileReader(path);
    BufferedReader bf = new BufferedReader(file_to_read);

    String aLine;
    int numberOfLines = 0;

    while (( aLine = bf.readLine()) != null) {
        numberOfLines++;
    }
    bf.close();

    return numberOfLines;
}

public String[] OpenFile() throws IOException {

    FileReader fr = new FileReader(path);
    BufferedReader textReader = new BufferedReader (fr);

    int numberOfLines = readLines();

    String[] textData = new String[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
        textData[i] = textReader.readLine();
    }

    textReader.close();

    return textData;

}

public int getCounter(int thatOne) {
    return counter[thatOne];
}

public void addOne(int k) { 
    counter[k]++;
}
}
Joe
  • 11
  • 2
  • add also the errors or state the problems you have with this code. – Elzo Valugi Aug 25 '16 at 13:31
  • Why don't I see the sequence 0x10,0x42 anywhere in your pastebin data? Did you mean 0x10,0x41? Also a lot of the data between 0x10,0x41 and 0x10,0x03 isn't text. If this is a one time thing, why don't you just use the [`strings`](http://superuser.com/questions/124081/is-there-a-windows-equivalent-of-the-unix-strings-command) tool or a hex editor with the ability to extract strings? Those tools don't look for delimiters, rather, they look for sequences of textual characters of a minimum length and dump them out. – Jason C Aug 25 '16 at 15:13

0 Answers0