Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Parsing HTTP text file format
    primarykey
    data
    text
    <p>I am new to java just learned it this week, my teacher want me parse a HTTP request saved in text file format. Basically he wanted me to extract<br> just this line "GET /fenway/ HTTP/1.0\r\n" and this "Host: www.redsox.com\r\n" and save it in a text format. My program doesn't work well yet as it contains error. What I did was to read a text file line by line and then enter it in to a function that tries to read the buffer and tokenizes each word and saves it to copyGetWord, then running a while loop to detect if the word "GET" is found it will store getWord to an arraylist.</p> <p>Another thing is that am only allowed to use java for this no perl or python. Also I have tried jnetpcap libraries but have problem installing them so am stuck with text files.</p> <p>Hope anyone can help. </p> <h2>this is a sample text file:</h2> <p>Transmission Control Protocol, Src Port: bridgecontrol (1073), Dst Port: http (80), Seq: 1, Ack: 1, Len: 270 Hypertext Transfer Protocol GET /azur/ HTTP/1.0\r\n Connection: Keep-Alive\r\n User-Agent: Mozilla/4.08 [en] (WinNT; I)\r\n Host: www.google.com\r\n</p> <pre><code>public static void main(String[] args) { System.out.println("Tries to read the samplepcap1.txt, \n"); ReadingFile1 handle = new ReadingFile1(); ArrayList &lt;String&gt; StoreLine = new ArrayList&lt;String&gt;(); try{ FileReader ReadPcap = new FileReader("samplePcapSmall.txt"); BufferedReader bufferPcap = new BufferedReader(ReadPcap); String readBufLine = bufferPcap.readLine(); StoreLine.add(readBufLine); while (readBufLine!=null){ readBufLine = bufferPcap.readLine(); handle.LookForWord(readBufLine); } bufferPcap.close(); } catch (FileNotFoundException e){ System.out.println("\nFile not found"); } catch (IOException e){ System.out.println("Problem reading the file.\n"); } } public String LookForWord(String getWord){ ArrayList &lt;String&gt;MatchingWord = new ArrayList&lt;String&gt;(); StringTokenizer copyGetWord = new StringTokenizer(getWord," "); while (copyGetWord.hasMoreElements()){ if(copyGetWord.nextToken().matches("GET")){ MatchingWord.add(getWord); } } System.out.println("\nMatch: "+MatchingWord); return getWord; } </code></pre> <p>Tries to read the samplepcap1.txt, stores in an ArrayList and Displays ArrayList</p> <pre><code>Match: [] Match: [ GET /fenway/ HTTP/1.0\r\n] Match: [] Match: [] Match: [] Exception in thread "main" java.lang.NullPointerException at java.util.StringTokenizer.&lt;init&gt;(StringTokenizer.java:182) at java.util.StringTokenizer.&lt;init&gt;(StringTokenizer.java:204) at readingfile1.ReadingFile1.LookForWord(ReadingFile1.java:84) at readingfile1.ReadingFile1.main(ReadingFile1.java:62) Java Result: 1 BUILD SUCCESSFUL (total time: 1 second) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload