• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

BufferedReader...

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Request is to receive e-mail ( via Lotus notes database), I get a handle to it in java application, and get the value from the BODY field. The Vector vecBody = ndoc.getItemValue("Body"); line returns a vector with the entire value of the email in the first element of the vector ( note the e-mail has multiple lines - it is actually text that represents a PO).

Now, I simply want to write one line at a time to a relational database table. Yes, this sounds strange, but one record will be the first line of PO e-mail, another record will be second line of PO e-mail, etc. Hey, I didn't design it, just trying to do it.

I am new to java... I have the below code that gets me all the way to having the text of e-mail in vector, but from there I don't know exactly what to do. Java experts told me to use BufferedReader... but it looks like they only take in actual file names. I don't have file, I have a vector full of text with carriage returns in it.

Any idea how I should do this? Any comments appreciated. Thank you.
- jamie

package EmailParser;


import java.io.*;
import java.util.Vector;
import lotus.domino.*;

//import com.util.AppProperties;
//import com.util.ApplicationInitializationException;
//import empSyncNotify.ProcessController;



/**
* @author haynesj
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class EmailParser extends AgentBase{

/**
* Developer: Jamie Haynes
* Date:9/29/2005
* Purpose:This Java program will be called by an rpg program.
* Java program will get a handle to specific, unprocessed
* e-mails in the target notes db using the 'EMailsNewView' view.
* Program shall loop through all documents.
* If a document does not have the text �Shipping Information:� within the
* first four lines of �Body� field, then Program shall create text field
* named �Processed� and set it to �YES� and save the document and loop to next
* document in collection.
* Program shall parse through �Body� field of each e-mail containing the
* text �Shipping Information:� within the first four lines and
*1.write one record only containing the document�s �From� field while trimming
*all �<� and �>� and blank spaces from beginning and end of string to PO821F
*2.write one record for every line in document�s �Body� field to PO821F while
*trimming all spaces from beginning and end of line.
*Program shall call RPG program ( PO821R ).
*On successful return of RPG program, program shall make the e-mail as processed by
*creating a text field named �Processed� and setting its value to �YES�.
*On unsuccessful return of RPG program, program shall simply loop to next available
*e-mail in collection.
*Program shall continue looping through all documents until end of collection while
*logging update and error information for each e-mail to emailparserlog.text.

* References:process\process.nsf on AMADB01 (notes database)
* Work Request:2005311
*/
private final String NOTES_TEST_SERVER_IP = "XXXXX";
private final String NOTES_LIVE_SERVER_IP = "XXXXX";
private final String PROCESS_REP_ID_DZIN = "XXXXX";
private final String NOTES_USER = "XXXX";
private final String NOTES_WORD = "XXXXX";

private Session nsess;
private boolean bIsTestRun;
private Database ndbProcessDB ; //Process database...

// Constructor
public EmailParser(){};

public static void main(String[] args) {
System.out.println( "Start program from java application..." );

EmailParser controller = new EmailParser();

try{
// Initialize logging data...
// controller.init();
controller.bIsTestRun = true;
// Set the nsess session property in setSession if we don't already have it...
controller.setSession();
// get Process db and assign to ndbProcessDB.
controller.getEmpDb();
// Return collection of notesdocuments to process.
DocumentCollection nClxn = controller.getUnProcessedDocs();
if ( nClxn.getCount() > 0){
System.out.println("Total documents retrieved = " + nClxn.getCount() );
// Loop through documents...
Document ndoc = nClxn.getFirstDocument();
int ndocCtr = 1; // count number of documents in entire collection as we loop through them.
int POCtr = 0; // count unprocessed documents that are considered POs.
int nonPOCtr = 0; // count unprocessed documents that are NOT considered POs.

while (ndoc != null) {
System.out.println("ndocCtr = " + ndocCtr );

// get contents of Body field...
Vector vecBody = ndoc.getItemValue("Body");
if (controller.isPO(vecBody)){
POCtr++;
int x;
System.out.println("Controller says isPO = true.");
// Now write this docment to AS/400 one line at a time
// and then call rpg program to process...



???
BufferedReader d = new BufferedReader(new InputStreamReader(vecBody));


}else{
nonPOCtr++;
ndoc.replaceItemValue( "Processed", "YES" );
ndoc.save(true,false);
}
System.out.println("getting next ndoc...");
ndoc = nClxn.getNextDocument();
ndocCtr++ ;
}//close while
ndoc = null;
System.out.println("POs = " + POCtr );
System.out.println("NONPOs = " + nonPOCtr );
}// end if

nClxn = null;

}catch (NotesException ne){
ne.printStackTrace();
//}catch (IOException io){
//System.out.println("IOException.");
//io.printStackTrace();
}finally {
controller.cleanUp();
}
System.out.println("The End.");

}
[ October 12, 2005: Message edited by: Jamie Haynes ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what exactly does the vector contain? Does it contain only one element, a String, which contains the entire PO?

You can use java.io.StringReader to read from a String, and you can wrap the StringReader with a BufferedReader to read it line by line.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic