1 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 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 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 (ca, 0, len); 61 } 62 } 63 | Popular Tags |