Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Splitting the file based on tokenizer using Java

I have a file which has multiple ST* sets. Is there a way to tokenize to get these sets into string Builder or any of the similar kind? I dont want to loop through each and every line to combine all the lines of the ST sets. The idea is once I get the ST sets then I can combine the header(ISA+GS) and ST with trialer(IEA+GE) to form one proper recordset. PFA  is the file.

I am planning to start with getting all the file into one string builder using the following code and then proceed stripping off the pieces I need to rebuild the set desired. PFA also the individual sets desired. Please note I have the code to generate the individual sets but I need it withough reading though and looping through each line. Need some kind of tokenizer.

 
InputStream is = new FileInputStream("manifest.mf");
BufferedReader buf = new BufferedReader(new InputStreamReader(is));
        
String line = buf.readLine();
StringBuilder sb = new StringBuilder();
        
while(line != null){
   sb.append(line).append("\n");
   line = buf.readLine();
}
        
String fileAsString = sb.toString();
System.out.println("Contents : " + fileAsString);

Open in new window

file-a.txt
output-1.txt
output-2.txt
output-3.txt
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The idea is once I get the ST sets then I can combine the header(ISA+GS) and ST with trialer(IEA+GE) to form one proper recordset. PFA  is the file.
I'm confused - i thought you'd got this basic requirement sorted out in your previous questions?
Avatar of kalyangkm

ASKER

unfortunately my end to end solution which also has to upload the files to a FTP server can’t be achieved in the same program without using a place holder. the tool in which I will be deploying this code requires the payload to be captured and then FTPed at the same time. It won’t work if I generate the output files into a place holder like project path or desktop etc.

and hence I am looking at the option of grouping the desired output structure so that I can use something like an input stream/output stream incombination with FTPclient class storeFile method to upload the file. and ofcourse if there are multiple outputs I have to do the same.
That doesn't really answer my observation. Before you even begin to deal with the target, you need to deal with parsing the source. Are you actually saying that with all the answers you've had, you haven't had one that parses and holds the source in memory?
yes, exactly.
What you need is a parser to put all parts of the transmission into one object, but i can't do anything now i'm afraid outside Live.
it’s fine, please do when you are back
ASKER CERTIFIED SOLUTION
Avatar of kalyangkm
kalyangkm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes but it's not really as i described - IOW not object oriented so will be less extensible and maintainable - if the requirement never alters you should be OK
Hi CEHJ,

I would be interested in the approach you are mentioning. If you want I can open another question.