KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > dcerpc > UnicodeString


1 /* jcifs msrpc client library in Java
2  * Copyright (C) 2006 "Michael B. Allen" <jcifs at samba dot org>
3  * "Eric Glass" <jcifs at samba dot org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package jcifs.dcerpc;
21
22 public class UnicodeString extends rpc.unicode_string {
23
24     boolean zterm;
25
26     public UnicodeString(boolean zterm) {
27         this.zterm = zterm;
28     }
29     public UnicodeString(rpc.unicode_string rus, boolean zterm) {
30         this.length = rus.length;
31         this.maximum_length = rus.maximum_length;
32         this.buffer = rus.buffer;
33         this.zterm = zterm;
34     }
35
36     public UnicodeString(String JavaDoc str, boolean zterm) {
37         this.zterm = zterm;
38
39         int len = str.length();
40         int zt = zterm ? 1 : 0;
41
42         length = maximum_length = (short)((len + zt) * 2);
43         buffer = new short[len + zt];
44
45         int i;
46         for (i = 0; i < len; i++) {
47             buffer[i] = (short)str.charAt(i);
48         }
49         if (zterm) {
50             buffer[i] = (short)0;
51         }
52     }
53
54     public String JavaDoc toString() {
55         int len = length / 2 - (zterm ? 1 : 0);
56         char[] ca = new char[len];
57         for (int i = 0; i < len; i++) {
58             ca[i] = (char)buffer[i];
59         }
60         return new String JavaDoc(ca, 0, len);
61     }
62 }
63
Popular Tags