Hi Frank, Thanks a lot. In my case, I will let user input a charset that will match the charset defined in MIB specification first. For example, they might input "gb2312". Then I will generate a new text just like new String(variable.getValue(),"gb2312"); I guess this will meet my needs. Thanks again.
Eternal 2009/1/6 <[email protected]> > Hi, > > I have already written it: the MIB specification > has to define which character set is used for > a variable binding. > > To get the OctetString value never use toString(). > Instead use getValue()/toByteArray(). > > Best regards, > Frank > > > > Hi Frank, > > I took a look at the toString() method of OctetString that is like below. > public String toString() { > if (isPrintable()) { > return new String(value); > } > return toHexString(); > } > > public boolean isPrintable() { > for (int i=0; i<value.length; i++) { > char c = (char)value[i]; > if ((Character.isISOControl(c) || > ((value[i] & 0xFF) >= 0x80)) && (!Character.isWhitespace(c))) { > return false; > } > } > return true; > } > > So if the value byte array contains Chinese chars, it will not display the > correct Chinese chars and will display the hexadecimal values. You know, in > order to display the Chinese chars correctly, I have to do some encoding > converting just like this. > new String(((OctetString) vb[i].getVariable()).toByteArray(), "gb2312"); > After done that, the chinese chars will be correctly displayed. Therefore, > I guess if the value byte array contains Japanese chars, I will also have to > use a Japanese charset to reconstruct the text. Same process will be needed > for other chars such as German, French and so on. > > My problem is that I am writing a snmp trap receive client and I can't know > which chars the snmp trap sender(such as cisco router and some kinds of > firewall) will use by advance. So in this case, I have to guess which > charsets the snmp trap sender are using. Do you have any suggestion for this > case? Thanks. > > > Eternal > > > > > 2009/1/2 Frank Fock <[email protected]> > >> Hi, >> >> OctetString does not "use" any encoding. As the name >> suggests, it represents an octet string which is >> a (binary) string of 8-bit bytes. >> >> If you convert an OctetString to a String, UTF-8 is >> used by default (Java does that). You are responsible >> to use the correct format as specified in the >> corresponding MIB specification of the object. >> >> Regards, >> Frank >> >> >> karunakaran s.l wrote: >> >>> Hi All, >>> >>> I want to know the snmp4j's "OctetString" uses the UTF >>> encoding >>> or not. >>> >>> If it uses the UTF Encoding means what is encoding type (8 or 16). If not >>> using UTF encoding means is any other way of using UTF Encoding for >>> setting >>> the MO Values of type OctetString. (Example: UTF encoding for >>> sysLocation). >>> >>> Please clarify this as soon as possible. >>> >>> >>> Thanks >>> Karunakaran >>> _______________________________________________ >>> SNMP4J mailing list >>> [email protected] >>> http://lists.agentpp.org/mailman/listinfo/snmp4j >>> >> >> -- >> AGENT++ >> http://www.agentpp.com >> http://www.mibexplorer.com >> http://www.mibdesigner.com >> >> >> >> _______________________________________________ >> SNMP4J mailing list >> [email protected] >> http://lists.agentpp.org/mailman/listinfo/snmp4j >> > > _______________________________________________ SNMP4J mailing list [email protected] http://lists.agentpp.org/mailman/listinfo/snmp4j
