KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > net > XMLSocketWriter


1 package org.jivesoftware.messenger.net;
2
3 import org.jivesoftware.util.XMLWriter;
4
5 import java.net.Socket JavaDoc;
6 import java.io.Writer JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 /**
10  * XMLWriter whose writer is actually sending data on a socket connection. Since sending data over
11  * a socket may have particular type of errors this class tries to deal with those errors.
12  */

13 public class XMLSocketWriter extends XMLWriter {
14
15     private Socket JavaDoc socket;
16
17     public XMLSocketWriter(Writer writer, Socket JavaDoc socket) {
18         super( writer, DEFAULT_FORMAT );
19         this.socket = socket;
20     }
21
22     /**
23      * Flushes the underlying writer making sure that if the connection is dead then the thread
24      * that is flushing does not end up in an endless wait.
25      *
26      * @throws IOException if an I/O error occurs while flushing the writer.
27      */

28     public void flush() throws IOException JavaDoc {
29         // Register that we have started sending data
30
SocketSendingTracker.getInstance().socketStartedSending(socket);
31         try {
32             super.flush();
33         }
34         finally {
35             // Register that we have finished sending data
36
SocketSendingTracker.getInstance().socketFinishedSending(socket);
37         }
38     }
39 }
40
Popular Tags