+ /**
+ * An {@link Appendable} that can be used to send data over a
+ * {@link SimpleSocket}. You must close it to send the end of block element.
+ *
+ * @author niki
+ *
+ */
+ public class BlockAppendable implements Appendable, Closeable {
+ private SimpleSocket ss;
+
+ /**
+ * Create a new {@link BlockAppendable} for the given
+ * {@link SimpleSocket}.
+ *
+ * @param ss
+ * the {@link SimpleSocket}
+ */
+ public BlockAppendable(SimpleSocket ss) {
+ this.ss = ss;
+ }
+
+ @Override
+ public Appendable append(CharSequence csq) throws IOException {
+ ss.send(csq);
+ return this;
+ }
+
+ @Override
+ public Appendable append(char c) throws IOException {
+ ss.send("" + c);
+ return this;
+ }
+
+ @Override
+ public Appendable append(CharSequence csq, int start, int end)
+ throws IOException {
+ ss.send(csq.subSequence(start, end));
+ return this;
+ }
+
+ @Override
+ public void close() throws IOException {
+ ss.sendBlock();
+ }
+
+ }
+