Commit 011f3d57 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added #deliverRawText(String). JM-6


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1373 b35dd754-fafc-0310-a699-88a17e54d16e
parent e9fcc7c8
...@@ -126,6 +126,19 @@ public interface Connection { ...@@ -126,6 +126,19 @@ public interface Connection {
*/ */
public void deliver(Packet packet) throws UnauthorizedException; public void deliver(Packet packet) throws UnauthorizedException;
/**
* Delivers raw text to this connection. This is a very low level way for sending
* XML stanzas to the client. This method should not be used unless you have very
* good reasons for not using {@link #deliver(org.xmpp.packet.Packet)}.<p>
*
* This method avoids having to get the writer of this connection and mess directly
* with the writer. Therefore, this method ensures a correct delivery of the stanza
* even if other threads were sending data concurrently.
*
* @param text the XML stanzas represented kept in a String.
*/
public void deliverRawText(String text);
/** /**
* Returns true if the connected client is a flash client. Flash clients need * Returns true if the connected client is a flash client. Flash clients need
* to receive a special character (i.e. \0) at the end of each xml packet. Flash * to receive a special character (i.e. \0) at the end of each xml packet. Flash
......
...@@ -39,14 +39,14 @@ import java.util.Iterator; ...@@ -39,14 +39,14 @@ import java.util.Iterator;
*/ */
public class SocketConnection implements Connection { public class SocketConnection implements Connection {
private Map listeners = new HashMap();
private Socket socket;
/** /**
* The utf-8 charset for decoding and encoding XMPP packet streams. * The utf-8 charset for decoding and encoding XMPP packet streams.
*/ */
private String charset = "UTF-8"; public static final String CHARSET = "UTF-8";
private Map listeners = new HashMap();
private Socket socket;
private Writer writer; private Writer writer;
...@@ -77,7 +77,7 @@ public class SocketConnection implements Connection { ...@@ -77,7 +77,7 @@ public class SocketConnection implements Connection {
this.secure = isSecure; this.secure = isSecure;
this.socket = socket; this.socket = socket;
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), CHARSET));
this.deliverer = deliverer; this.deliverer = deliverer;
xmlSerializer = new XMLWriter(writer); xmlSerializer = new XMLWriter(writer);
} }
...@@ -265,6 +265,28 @@ public class SocketConnection implements Connection { ...@@ -265,6 +265,28 @@ public class SocketConnection implements Connection {
} }
} }
public void deliverRawText(String text) {
if (!isClosed()) {
boolean errorDelivering = false;
synchronized (writer) {
try {
writer.write(text);
if (flashClient) {
writer.write('\0');
}
writer.flush();
}
catch (IOException e) {
Log.debug("Error delivering raw text" + "\n" + this.toString(), e);
errorDelivering = true;
}
}
if (errorDelivering) {
close();
}
}
}
/** /**
* Notifies all close listeners that the connection has been closed. * Notifies all close listeners that the connection has been closed.
* Used by subclasses to properly finish closing the connection. * Used by subclasses to properly finish closing the connection.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment