aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/xml
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-04 15:09:50 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-04 15:09:50 +0100
commit0d80d88736926d06e97f22f9ecc63d4fb696751c (patch)
treed61669953ae47a0c96dcc5dc814bc0f49527c547 /src/de/gultsch/chat/xml
parent14a171b088363d8e39b547eecc181570c4289428 (diff)
reworked account managment. now status display actually works
Diffstat (limited to 'src/de/gultsch/chat/xml')
-rw-r--r--src/de/gultsch/chat/xml/TagWriter.java51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/de/gultsch/chat/xml/TagWriter.java b/src/de/gultsch/chat/xml/TagWriter.java
index 35f27477..401a6eee 100644
--- a/src/de/gultsch/chat/xml/TagWriter.java
+++ b/src/de/gultsch/chat/xml/TagWriter.java
@@ -3,12 +3,37 @@ package de.gultsch.chat.xml;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import android.util.Log;
public class TagWriter {
- OutputStreamWriter writer;
+ private OutputStreamWriter outputStream;
+ private LinkedBlockingQueue<String> writeQueue = new LinkedBlockingQueue<String>();
+ private Thread writer = new Thread() {
+ public boolean shouldStop = false;
+ @Override
+ public void run() {
+ while(!shouldStop) {
+ try {
+ String output = writeQueue.take();
+ outputStream.write(output);
+ outputStream.flush();
+ } catch (IOException e) {
+ Log.d("xmppService", "error writing to stream");
+ } catch (InterruptedException e) {
+
+ }
+ }
+ }
+ };
+
public TagWriter() {
@@ -16,31 +41,29 @@ public class TagWriter {
public TagWriter(OutputStream out) {
this.setOutputStream(out);
+ writer.start();
}
public void setOutputStream(OutputStream out) {
- this.writer = new OutputStreamWriter(out);
+ this.outputStream = new OutputStreamWriter(out);
+ if (!writer.isAlive()) writer.start();
}
- public TagWriter beginDocument() throws IOException {
- writer.write("<?xml version='1.0'?>");
+ public TagWriter beginDocument() {
+ writeQueue.add("<?xml version='1.0'?>");
return this;
}
- public TagWriter writeTag(Tag tag) throws IOException {
- writer.write(tag.toString());
+ public TagWriter writeTag(Tag tag) {
+ writeQueue.add(tag.toString());
return this;
}
-
- public void flush() throws IOException {
- writer.flush();
- }
- public void writeString(String string) throws IOException {
- writer.write(string);
+ public void writeString(String string) {
+ writeQueue.add(string);
}
- public void writeElement(Element element) throws IOException {
- writer.write(element.toString());
+ public void writeElement(Element element) {
+ writeQueue.add(element.toString());
}
}