[jdom-interest] outputter w/ socket streams

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Mar 9 00:54:56 PST 2001


Hi,

When outputting to a Writer object, XMLOutputter does NOT call flush() when 
it's done (whereas is does for OutputStreams).
Thus, in your case, if the resulting XML document size is smaller than 8KB you 
won't see any output.
Why 8KB? 8KB is the default size of the cache managed by BufferedWriter that 
PrintWriter (out in your code) uses when wrapping OutputStreams.

So... try calling out.flush() after XMLOutputter is done (good) or set your 
PrintWriter in auto-flush mode (not so good).

Hope this helps,

Laurent

Scott Jeppensen wrote:

> I am having problems  outputting my XML doc through an outputstream. With
> the code supplied below, I know the doc is reaching the outputter because if
> I use:
> outputter.output(doc,System.out);
> then the XML prints out fine...if I use:
> outputter.out(doc, out);
> then nothing....no errors, no excpetions, etc...
> Here is the JDOM part of my code(using JDOM b6):
> 
> class flashClientThread extends Thread {
> 	private Socket clientSocket = null;
> 	public String clientIP;
> 	public PrintWriter out;
> 	public BufferedReader in;
> 	public InputStreamReader inP;
> 	int i;
> 	int end;
> 	int begin;
> 	public String contact = null;
> 	
> 	public flashClientThread(Socket clientSocket) {
> 		super("flashClientThread");
> 		this.clientSocket = clientSocket;
> 		
> 	} 
> 	
> 	public void run() {
> 		clientIP = clientSocket.getInetAddress().getHostAddress();
> 		try 
> 		{   
> 			inP = new
> InputStreamReader(clientSocket.getInputStream());
> 			in = new BufferedReader(inP);
> 			out = new
> PrintWriter(clientSocket.getOutputStream(), true);
> 			SAXBuilder builder = new SAXBuilder();
> 			Document doc;
> 			String inputLine;
> 			int streamResult, i;
> 
> 			char buf[] = new char[1];
> 			do{
> 				inputLine = "";
> 				do{
> 					streamResult = in.read(buf,0,1);
> 					if(buf[0] !='\u0000'){
> 						inputLine += buf[0];
> 					}
> 				} while (buf[0] !='\u0000');
> 
> 				if (inputLine.length() > 1)	{
> 					try{
> 						doc = builder.build(new
> StringReader(inputLine));
> 						flashServ.disburse(doc);
> 					} catch (Exception e) {
> 						e.printStackTrace();
> 
> 					}
> 				}
> 
> 			} while(true);
> 		} catch (Exception e) {
> 	}
> }
> 	
> // Prints XML String
> 
> 	public void send(Document message) {
> 		try{
> 			XMLOutputter outputter = new XMLOutputter();
> 			outputter.output(message,out);
> 		} catch (Exception e){
> 			e.printStackTrace();
> 		}
> 	}
> }
> 
> Thanks in advance,
> Scott
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


-- 

                  wWw
                 (o o)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic           | Tel: +33 (0)1 55.91.21.93  (Direct line)
Atos Origin               |      +33 (0)1 55.91.20.00
Intégration - e-Business  | Fax: +33 (0)1 55.91.22.31
Les Miroirs - Bat. C      |
18, avenue d'Alsace       |
F-92926 La Defense Cedex  | e-Mail: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------

"Your mouse has moved, Windows must be restarted for changes to take
  effect."




More information about the jdom-interest mailing list