summaryrefslogtreecommitdiffstats
path: root/kdejava/koala/org/kde/koala/Marchaller.java
blob: aa013e490469caa8c191d9a6f42ea225cbc3b572 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package org.kde.koala;

import java.io.*;

/**
 * This marchaller can convert between serialized Qt objects and Java objects.
 *
 * (Scooped the code of Stub.java from the javadcop project, and made the operations static and public)
 */
public class Marchaller {
    // accessor methods for the datatypes used ---------------------------

    public static boolean read_bool(DataInputStream is) throws IOException
    {
	return is.readBoolean();
    }

    public static void write_bool(DataOutputStream os, boolean val) throws IOException
    {
	os.writeBoolean(val);
    }

    public static short read_short_int(DataInputStream is) throws IOException
    {
	return is.readShort();
    }

    public static void write_short_int(DataOutputStream os, short val) throws IOException
    {
	os.writeShort(val);
    }

    public static int read_int(DataInputStream is) throws IOException
    {
	return is.readInt();
    }

    public static void write_int(DataOutputStream os, int val) throws IOException
    {
	os.writeInt(val);
    }

    public static int read_long_int(DataInputStream is) throws IOException
    {
	return is.readInt();
    }

    public static void write_long_int(DataOutputStream os, int val) throws IOException
    {
	os.writeInt(val);
    }

    public static float read_float(DataInputStream is) throws IOException
    {
	return is.readFloat();
    }

    public static void write_float(DataOutputStream os, float val) throws IOException
    {
	os.writeFloat(val);
    }

    public static double read_double(DataInputStream is) throws IOException
    {
	return is.readDouble();
    }

    public static void write_double(DataOutputStream os, double val) throws IOException
    {
	os.writeDouble(val);
    }

    public static String read_QString(DataInputStream is) throws IOException
    {
	int len = is.readInt();
	if (len == 0xffffffff)
	    return new String();
	else
	    {
		StringBuffer b = new StringBuffer();
		for (int i=0; i<len/2; ++i)
		    b.append(is.readChar());
		return b.toString();
	    }
    }

    public static void write_QString(DataOutputStream os, String val) throws IOException
    {
	os.writeInt(val.length()*2);
	for (int i=0; i<val.length(); ++i)
	    os.writeChar(val.charAt(i));
    }

    public static String read_QCString(DataInputStream is) throws IOException
    {
	int len = is.readInt();
	StringBuffer b = new StringBuffer();
	for (int i=0; i<len; ++i)
	    b.append((char)is.readByte());
	return b.toString();
    }

    public static void write_QCString(DataOutputStream os, String val) throws IOException
    {
	os.writeInt(val.length()+1);
	for (int i=0; i<val.length(); ++i)
	    os.writeByte(val.charAt(i));
	os.writeByte(0);
    }

    public static String[] read_QStringList(DataInputStream is) throws IOException
    {
	int n = is.readInt();
	String[] result = new String[n];
	for (int i=0; i<n; ++i)
	    result[i] = read_QString(is);
	return result;
    }

    public static void write_QStringList(DataOutputStream os, String[] val) throws IOException
    {
	os.writeInt(val.length);
	for (int i=0; i<val.length; ++i)
	    write_QCString(os, val[i]);
    }
/*
    public static void write_DCOPRef(DataOutputStream os, DCOPRef ref) throws IOException
    {
	write_QCString(os, ref.app());
	write_QCString(os, ref.object());
	write_QCString(os, ref.type());
    }
    public static DCOPRef read_DCOPRef(DataInputStream is) throws IOException
    {
	return new DCOPRef(read_QCString(is), read_QCString(is), read_QCString(is));
    }
*/
    public static void write_QByteArray(DataOutputStream os, byte[] byteArray) throws IOException
    {
      write_int(os, byteArray.length);
      os.write(byteArray);
    }
}