1 22 23 package com.ice.jni.registry; 24 25 import java.io.PrintWriter ; 26 27 28 36 37 public class 38 RegMultiStringValue extends RegistryValue 39 { 40 String [] data; 41 int dataLen; 42 43 44 public 45 RegMultiStringValue( RegistryKey key, String name ) 46 { 47 super( key, name, RegistryValue.REG_MULTI_SZ ); 48 this.data = null; 49 this.dataLen = 0; 50 } 51 52 public 53 RegMultiStringValue( RegistryKey key, String name, int type ) 54 { 55 super( key, name, type ); 56 this.data = null; 57 this.dataLen = 0; 58 } 59 60 public 61 RegMultiStringValue( RegistryKey key, String name, String [] data ) 62 { 63 super( key, name, RegistryValue.REG_MULTI_SZ ); 64 this.setData( data ); 65 } 66 67 public String [] 68 getData() 69 { 70 return this.data; 71 } 72 73 public int 74 getLength() 75 { 76 return this.dataLen; 77 } 78 79 public void 80 setData( String [] data ) 81 { 82 this.data = data; 83 this.dataLen = data.length; 84 } 85 86 public byte[] 87 getByteData() 88 { 89 int len = this.getByteLength(); 90 91 int ri = 0; 92 byte[] result = new byte[len]; 93 for ( int i = 0 ; i < this.dataLen ; ++i ) 94 { 95 byte[] strBytes = this.data[i].getBytes(); 96 97 for ( int j = 0 ; j < strBytes.length ; ++j ) 98 result[ri++] = strBytes[j]; 99 100 result[ri++] = 0; 101 } 102 103 return result; 104 } 105 106 public int 107 getByteLength() 108 { 109 int len = 0; 110 for ( int i = 0 ; i < this.dataLen ; ++i ) 111 len += this.data[i].length() + 1; 112 113 return len; 114 } 115 116 public void 117 setByteData( byte[] data ) 118 { 119 int start; 120 int count = 0; 121 122 for ( int i = 0 ; i < data.length ; ++i ) 123 { 124 if ( data[i] == 0 ) 125 count++; 126 } 127 128 int si = 0; 129 String [] newData = new String [ count ]; 130 for ( int i = start = 0 ; i < data.length ; ++i ) 131 { 132 if ( data[i] == 0 ) 133 { 134 newData[si] = new String ( data, start, (i - start) ); 135 start = si; 136 } 137 } 138 139 this.setData( newData ); 140 } 141 142 public void 143 export( PrintWriter out ) 144 { 145 byte[] hexData; 146 int dataLen = 0; 147 148 out.println( "\"" + this.getName() + "\"=hex(7):\\" ); 149 150 for ( int i = 0 ; i < this.data.length ; ++i ) 151 { 152 dataLen += this.data[i].length() + 1; 153 } 154 155 ++dataLen; 156 157 int idx = 0; 158 hexData = new byte[ dataLen ]; 159 160 for ( int i = 0 ; i < this.data.length ; ++i ) 161 { 162 int strLen = this.data[i].length(); 163 byte[] strBytes = this.data[i].getBytes(); 164 165 System.arraycopy 166 ( strBytes, 0, hexData, idx, strLen ); 167 168 idx += strLen; 169 170 hexData[ idx++ ] = '\0'; 171 } 172 173 hexData[ idx++ ] = '\0'; 174 175 RegistryValue.exportHexData( out, hexData ); 176 } 177 178 } 179 180 181 182 183 | Popular Tags |