001: /*
002: ** Java native interface to the Windows Registry API.
003: ** Copyright (c) 1997 by Timothy Gerard Endres
004: **
005: ** This program is free software.
006: **
007: ** You may redistribute it and/or modify it under the terms of the GNU
008: ** General Public License as published by the Free Software Foundation.
009: ** Version 2 of the license should be included with this distribution in
010: ** the file LICENSE, as well as License.html. If the license is not
011: ** included with this distribution, you may find a copy at the FSF web
012: ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
013: ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
014: **
015: ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
016: ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
017: ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
018: ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
019: ** REDISTRIBUTION OF THIS SOFTWARE.
020: **
021: */
022:
023: package com.ice.jni.registry;
024:
025: import java.io.PrintWriter;
026:
027: /**
028: * The RegMultiStringValue class represents a multiple
029: * string, or string array, value in the registry
030: * (REG_MULTI_SZ).
031: *
032: * @see com.ice.jni.registry.Registry
033: * @see com.ice.jni.registry.RegistryKey
034: */
035:
036: public class RegMultiStringValue extends RegistryValue {
037: String[] data;
038: int dataLen;
039:
040: public RegMultiStringValue(RegistryKey key, String name) {
041: super (key, name, RegistryValue.REG_MULTI_SZ);
042: this .data = null;
043: this .dataLen = 0;
044: }
045:
046: public RegMultiStringValue(RegistryKey key, String name, int type) {
047: super (key, name, type);
048: this .data = null;
049: this .dataLen = 0;
050: }
051:
052: public RegMultiStringValue(RegistryKey key, String name,
053: String[] data) {
054: super (key, name, RegistryValue.REG_MULTI_SZ);
055: this .setData(data);
056: }
057:
058: public String[] getData() {
059: return this .data;
060: }
061:
062: public int getLength() {
063: return this .dataLen;
064: }
065:
066: public void setData(String[] data) {
067: this .data = data;
068: this .dataLen = data.length;
069: }
070:
071: public byte[] getByteData() {
072: int len = this .getByteLength();
073:
074: int ri = 0;
075: byte[] result = new byte[len];
076: for (int i = 0; i < this .dataLen; ++i) {
077: byte[] strBytes = this .data[i].getBytes();
078:
079: for (int j = 0; j < strBytes.length; ++j)
080: result[ri++] = strBytes[j];
081:
082: result[ri++] = 0;
083: }
084:
085: return result;
086: }
087:
088: public int getByteLength() {
089: int len = 0;
090: for (int i = 0; i < this .dataLen; ++i)
091: len += this .data[i].length() + 1;
092:
093: return len;
094: }
095:
096: public void setByteData(byte[] data) {
097: int start;
098: int count = 0;
099:
100: for (int i = 0; i < data.length; ++i) {
101: if (data[i] == 0)
102: count++;
103: }
104:
105: int si = 0;
106: String[] newData = new String[count];
107: for (int i = start = 0; i < data.length; ++i) {
108: if (data[i] == 0) {
109: newData[si] = new String(data, start, (i - start));
110: start = si;
111: }
112: }
113:
114: this .setData(newData);
115: }
116:
117: public void export(PrintWriter out) {
118: byte[] hexData;
119: int dataLen = 0;
120:
121: out.println("\"" + this .getName() + "\"=hex(7):\\");
122:
123: for (int i = 0; i < this .data.length; ++i) {
124: dataLen += this .data[i].length() + 1;
125: }
126:
127: ++dataLen;
128:
129: int idx = 0;
130: hexData = new byte[dataLen];
131:
132: for (int i = 0; i < this .data.length; ++i) {
133: int strLen = this .data[i].length();
134: byte[] strBytes = this .data[i].getBytes();
135:
136: System.arraycopy(strBytes, 0, hexData, idx, strLen);
137:
138: idx += strLen;
139:
140: hexData[idx++] = '\0';
141: }
142:
143: hexData[idx++] = '\0';
144:
145: RegistryValue.exportHexData(out, hexData);
146: }
147:
148: }
|