How to design basic skeleton of java for testing of tab separated text file containing 1 lakh record [closed]

StackOverflow https://stackoverflow.com/questions/19050308

  •  29-06-2022
  •  | 
  •  

Question

i have a text file which contains 100000 line as below

be3c152f6f6bcd5 AL9 60  51.7458349055774    -0.191050898942398  F

be3c15cd5   AL9 30  51.79055774 -0.191050898942398  M

now i have to create a design where i need to read all this and based on test condition needs to generate the output in same file format which i read

i was thinking this to implement by

  1. reading all lines of input file
  2. keeping them in List<some pojo>

now this pojo will have reference to all condition and generate the o\p

my question is loop readline 1 l00000 times and generate the pojo is good or not ?Also in the final o\p folder for each test case condition i have to convert this List<pojo to text format as above what we read.

please let me know some better way.

Was it helpful?

Solution 2

It's a simple problem for parsing records.

You don't want each line in a List; you want the POJO containing the data after you tokenize each line.

Here's pseudo-code:

  1. Open file
  2. Loop over all lines in file
  3. Tokenize each line and populate POJO
  4. Add POJO to List
  5. Close file
  6. Perform any operations you wish on POJOs
  7. Output POJO List in desired format

If it's just tab delimited, perhaps you can use a library that already deals with .csv files.

OTHER TIPS

Read line, process line, write line. No need to keep them all in memory.

I assume, the test conditions only depend on one line at a time:

You should stream the data both in and out. After processing the first line - which consists of reading and parsing - check the conditions. If the line should be kept in the output, you can now stream it to the (different) output file. If it should be deleted, you can just ignore it and skip to the next line of the input.

It sounds like a good idea to create an Element which has the different columns of the file as fields. You could then overwrite to String to generate the desired output and a Constructor which takes the String in the input Format to parse it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top