1 answer

Sample from my tcpprobe.dat file to use for testing (Ignore that giant gap its all supposed...

Question:

So, now you are asked to write a Java program to process topprobe.dat in the following way: • It deletes the last line contai

Sample from my tcpprobe.dat file to use for testing (Ignore that giant gap its all supposed to be one block):

*Note* xxxxx=51811, yyyyy = 51812, zzzzz = 51810 according to the data below

33.530532341 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef44c9e 0x7ef3db7e 21 15 185856 193 29312
33.542474133 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef457ee 0x7ef3e126 21 15 185856 193 29312
33.554576589 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef457ee 0x7ef3e6ce 21 15 185856 194 29312
33.566356665 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef4633e 0x7ef3ec76 21 15 185856 194 29312
33.578419057 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef4633e 0x7ef3f21e 21 15 185856 195 29312

33.818567133 10.10.1.2:51812 10.10.2.2:5001 32 0x27767e39 0x2775eb29 27 19 336000 195 29312
33.830336654 10.10.1.2:51812 10.10.2.2:5001 32 0x27768989 0x2775f0d1 27 19 336000 195 29312
33.854344478 10.10.1.2:51812 10.10.2.2:5001 32 0x27768989 0x2775f679 27 19 336000 196 29312
33.878463548 10.10.1.2:51812 10.10.2.2:5001 32 0x277694d9 0x277601c9 27 19 336000 196 29312
33.902536919 10.10.1.2:51812 10.10.2.2:5001 32 0x2776a029 0x27760d19 27 19 336000 196 29312
33.926261724 10.10.1.2:51812 10.10.2.2:5001 32 0x2776ab79 0x27761869 27 19 336000 196 29312
33.950479934 10.10.1.2:51812 10.10.2.2:5001 32 0x2776b6c9 0x277623b9 27 19 336000 197 29312
33.962389651 10.10.1.2:51810 10.10.2.2:5001 32 0x38f9ae1 0x38f1e71 22 16 272256 192 29312
33.974309947 10.10.1.2:51810 10.10.2.2:5001 32 0x38f9ae1 0x38f2419 22 16 272256 193 29312
33.986437149 10.10.1.2:51810 10.10.2.2:5001 32 0x38fa631 0x38f29c1 22 16 272256 194 29312
33.998376239 10.10.1.2:51810 10.10.2.2:5001 32 0x38fa631 0x38f2f69 22 16 272256 194 29312
34.010376480 10.10.1.2:51810 10.10.2.2:5001 32 0x38fb181 0x38f3511 22 16 272256 195 29312
34.022182438 10.10.1.2:51810 10.10.2.2:5001 32 0x38fb181 0x38f3ab9 22 16 272256 196 29312
34.034363788 10.10.1.2:51810

Can someone please write this java code. I rate if the code compiles and gives the correct output. Thank you in advance!!

So, now you are asked to write a Java program to process topprobe.dat in the following way: • It deletes the last line containing incomplete data; • It replaces all white space delimiters on all lines with commas; • And it separates the three TCP flows based on their source port numbers (the source IP addresses are useless here because all three TCP flows were from the same IP) and spills them out into three separate files. Name your Java program Process_TCPProbe_yourinitial.java which must run in the following way: java Process_TCPProbe_yourinitial topprobe.dat topprobe_xxxxx_comma.dat topprobe_yyyy y_comma.dat topprobe_zzzzz_comma.dat The program takes four arguments: one raw data file as input and three output files. Of course, please replace the placeholder xxxxx , yyyyy , and zzzzz with the actual source port numbers in your data file. The following is a sample of one of the output files for your reference: 93.324970324,10.10.1.2:51205,10.10.2.2:5001,32,0x72e71882,0x72e6a762,20,15,341760,165 ,29312 93.337148466,10.10.1.2:51205,10.10.2.2:5001,32,0x72e71882,0x72e6ad0a, 20,15,341760,165 ,29312 93.349120821,10.10.1.2:51205, 10.10.2.2:5001,32,0x72e723d2,0x72e6b2b2,20,15,341760,166 ,29312

Answers

***Please upvote if you liked the answer***

Screenshot of the Java code:-

import java.io. BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java

Demo:-

Input:-

0 O X topprobe.dat - Notepad File Edit Format View Help 33.530532341 10.10.1.2:51811 10.10.2.2:5001 32 Ox7ef44c9e Ox7ef3db7e

Output of the file tcpprobe_51810_comma.data:-

x topprobe_51810_comma.dat - Notepad File Edit Format View Help 33.962389651,10.10.1.2:51810,10.10.2.2:5001, 32,0x38f9ae1, 0x

Java code to copy:-

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Process_TCPProbe_YourInitial{

   public static void main(String[] args) throws IOException {
      
       //Extracting the port numbers from the file names passed in the arguments
       String portNumber1 = args[1].substring(9, 14);
       String portNumber2 = args[2].substring(9, 14);
       String portNumber3 = args[3].substring(9, 14);
              
       int i = 0;
       Scanner s = new Scanner(new FileReader(args[0]));
       //Initialising array of contents with length equals to number of lines in the input file
       String[] contents = new String[18];      
       while(true)
       {
           if (i == 18)
               break;//Skipping the last line of the file
           //Replaces the whitespace with comma and stores in the string array
           contents[i] = s.nextLine().replace(" ", ",");
          
           i++;  
       }
      
       BufferedWriter bw1 = new BufferedWriter(new FileWriter(args[1]));
       BufferedWriter bw2 = new BufferedWriter(new FileWriter(args[2]));
       BufferedWriter bw3 = new BufferedWriter(new FileWriter(args[3]));
       //Iterating the array of contents using a for each loop
       for(String each:contents)
       {
           //Writing the string to the corresponding file which matches with the portNumber
           //along with a new line
           if (each.contains(portNumber1))
           {
               bw1.write(each);
               bw1.newLine();
              
           }
           else if(each.contains(portNumber2))
           {
               bw2.write(each);
               bw2.newLine();
              
           }
           else if(each.contains(portNumber3))
           {
               bw3.write(each);
               bw3.newLine();
              
           }
       }
       //This is necessary to finally output the text from the buffer to the corresponding file
       bw1.flush();
       bw2.flush();
       bw3.flush();
      
       //Closing all the file reading and writing handles
       bw1.close();
       bw2.close();
       bw3.close();
       s.close();
   }

}

.

Similar Solved Questions

1 answer
Cycle-1 is a fast-growing start-up firm that manufactures bicycles. The following income statement is available for...
Cycle-1 is a fast-growing start-up firm that manufactures bicycles. The following income statement is available for October: $384,00 Sales revenue (688 units @ $64e per unit) Less Manufacturing costs Variable costs Depreciation (fixed) Marketing and administrative costs Fixed costs (cash) Depreciati...
1 answer
How do you solve #x/5 = (2x+1)/20#?
How do you solve #x/5 = (2x+1)/20#?...
1 answer
Summarise the rationale and results of: Ludwig, M., Tobin, V.A., Callahan, M.F., Papadaki, E., Becker, A., Engelmann, M....
Summarise the rationale and results of: Ludwig, M., Tobin, V.A., Callahan, M.F., Papadaki, E., Becker, A., Engelmann, M. and Leng, G., 2013. Intranasal application of vasopressin fails to elicit changes in brain immediate early gene expression, neural activity and behavioural performance of rats.pp....
1 answer
QUESTION 7 The appropriate section in the statement of cash flows for reporting the net income...
QUESTION 7 The appropriate section in the statement of cash flows for reporting the net income is: o Operating activities, O Financing activities. O Investing activities. O Schedule of noncash investing or financing activity O This is not reported on the statement of cash flows. QUESTION 8 The appro...
1 answer
Recently, an Uber driver lost control and killed his passengers. The driver was drunk. Should Uber...
Recently, an Uber driver lost control and killed his passengers. The driver was drunk. Should Uber be liable for the conduct of its driver in this situation? Why or why not?...
1 answer
Jose 7 4 10. The Academic Dean of NCC believes there may be a positive linear...
Jose 7 4 10. The Academic Dean of NCC believes there may be a positive linear relationship between the number of recitations attended by a student during a semester, and the grade received in the course. The following table gives a sample of 12 students' number of recitations attended and their ...
1 answer
1. All students with last name starting with "A" P-1 who is at risk for HIV...
1. All students with last name starting with "A" P-1 who is at risk for HIV P-2 what are some possible preventive methods P-3 give some details about a special population affected by HIV...
1 answer
Are hospitals competing on the basis of price, quality, or both? Should hospitals and other health...
Are hospitals competing on the basis of price, quality, or both? Should hospitals and other health care facilities make a profit? Why or why not? please with reference...
1 answer
CengageNOW2 Online X 16 Below is A Table For Thx Q Chapter 23 Sence X Chapter...
CengageNOW2 Online X 16 Below is A Table For Thx Q Chapter 23 Sence X Chapter 26 Trefore ment/take AssignmentMain.doinvokerassignments&takeAssignmentSessionLocator assignment-takeinprogress=false 1 Mens Clothing Ch. Calculator Below is a table for the present value of $1 at compound interest. 0....
1 answer
The assignment is based on the case study “Starbucks’ Strategy in the Specialty Coffee Market”. QUESTION...
The assignment is based on the case study “Starbucks’ Strategy in the Specialty Coffee Market”. QUESTION 1: [30] Starbucks is planning on opening more stores in South Africa. You are requested to do an analysis of the South African macro environment and Starbuck’s market envi...
1 answer
Using this exhibit as the population, change the starting point and sampling interval for your sampling. How do the res...
Using this exhibit as the population, change the starting point and sampling interval for your sampling. How do the resulting samples reflect the original population? BIT 8.1 Population Class Year 2nd 1st 3rd 4th Percent of Population 40% 30% 20% 10% 30% 100% 20% 30% 20% The above exhibit shows a...
1 answer
The following is readily deprotonated to act as a nucleophile in a micheal reaction(shown in the...
The following is readily deprotonated to act as a nucleophile in a micheal reaction(shown in the deprotonated form) Provide to resonance structures that account for stabilization, each structure will only have one formal charge...
4 answers
Celeste multiplied 44 x 5 =202
Celeste multiplied 44 x 5 =202. Is her product reasonable?Explain why or why not?...
1 answer
Let {?(?),?≥0} be the counting process for a Poisson process with rate ?. Calculate the temporal...
Let {?(?),?≥0} be the counting process for a Poisson process with rate ?. Calculate the temporal covariance, Cov(?(?),?(?+?))....
1 answer
Please need the correct answer and the rationales A nur se is cariną tor a client...
please need the correct answer and the rationales A nur se is cariną tor a client with hyperparathyroidism. The nurse identifies the most appropriate nursing intervention for this client? A) Pad side rails as a seizure pre caution B Increase fluid intake to 3-4L daily C)Maintain bedrest to ...
1 answer
25 UNIT 25 REVIEW Check Your Recall 1 label the following parts of the kidney on...
25 UNIT 25 REVIEW Check Your Recall 1 label the following parts of the kidney on Figure 25.17 a Mare calen Renal capsule Minor caly Renal artery Renal cortes Renaland ESSAS A55555562563000 VVVV BU 25.17 Right kidney, frontal section...
1 answer
Linear momentum and collisions
a pool player imparts an impusle of 3.2 N.s to a stationary 0.25-kg cue ball with a cue stick.What is the speed of the ball jus after impact?...