summaryrefslogtreecommitdiff
path: root/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java')
-rwxr-xr-xsrc/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java
new file mode 100755
index 0000000..bb22108
--- /dev/null
+++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java
@@ -0,0 +1,72 @@
+/*
+ D-Bus Java Implementation
+ Copyright (c) 2005-2006 Matthew Johnson
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of either the GNU Lesser General Public License Version 2 or the
+ Academic Free Licence Version 2.1.
+
+ Full licence texts are included in the COPYING file with this program.
+*/
+package org.freedesktop.dbus;
+
+import java.io.BufferedOutputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
+import cx.ath.matthew.debug.Debug;
+import cx.ath.matthew.unix.USOutputStream;
+import cx.ath.matthew.utils.Hexdump;
+
+public class MessageWriter
+{
+ private OutputStream out;
+ private boolean isunix;
+ public MessageWriter(OutputStream out)
+ {
+ this.out = out;
+ this.isunix = false;
+ try {
+ if (out instanceof USOutputStream)
+ this.isunix = true;
+ } catch (Throwable t) {
+ }
+ if (!this.isunix)
+ this.out = new BufferedOutputStream(this.out);
+ }
+ public void writeMessage(Message m) throws IOException
+ {
+ if (Debug.debug) {
+ Debug.print(Debug.INFO, "<= "+m);
+ }
+ if (null == m) return;
+ if (Debug.debug) Debug.print(Debug.INFO, "m in not null"); // pego
+ if (null == m.getWireData()) {
+ if (Debug.debug) Debug.print(Debug.WARN, "Message "+m+" wire-data was null!");
+ return;
+ }
+ if (Debug.debug) Debug.print(Debug.INFO, "wire data in not null"); // pego
+ if (isunix) {
+ if (Debug.debug) {
+ Debug.print(Debug.INFO, "Writing all "+m.getWireData().length+" buffers simultaneously to Unix Socket");
+ for (byte[] buf: m.getWireData())
+ Debug.print(Debug.INFO, "("+buf+"):"+ (null==buf? "": Hexdump.format(buf)));
+ }
+ ((USOutputStream) out).write(m.getWireData());
+ } else
+ for (byte[] buf: m.getWireData()) {
+ if (Debug.debug)
+ Debug.print(Debug.INFO, "("+buf+"):"+ (null==buf? "": Hexdump.format(buf)));
+ if (null == buf) break;
+ out.write(buf);
+ if (Debug.debug) Debug.print(Debug.INFO, "After write()"); // pego
+ }
+ out.flush();
+ if (Debug.debug) Debug.print(Debug.INFO, "After flush()"); // pego
+ }
+ public void close() throws IOException
+ {
+ if (Debug.debug) Debug.print(Debug.INFO, "Closing Message Writer");
+ out.close();
+ }
+}