[SNMP4J] issue with OctetString.isPrintable

Frank Fock fock at agentpp.com
Sun Apr 3 22:14:30 CEST 2011


Hi,

I will try to fix that for the
next 1.x and 2.x release.

Best regards,
Frank

On 01.04.2011 17:08, Miller, Mark wrote:
> We have uncovered an issue with OctetString.isPrintable().  For the
> OctetString for 1C:32:41:1C:4E:38 iisPrintable is returning true but 1C
> is not a printable character it is the File Seperator character.  I
> think the issue is that OctetString.isPrintable assumes that all white
> space characters are printable but 1C is a whitespace character
> according to the Java Character class but it is not printable.
>
>
>
> I have written a short program to demonstrate:
>
> import org.snmp4j.smi.OctetString;
>
>
>
> public class OctetStringPrintableTest {
>
>
>
>      public static void main(String[] args) {
>
>          String hexString = "1C:32:41:1C:4E:38";
>
>          OctetString octetString = OctetString.fromHexString(hexString);
>
>          if (octetString.isPrintable()) {
>
>              System.out.println(String.format("HexString %s is printable
> as an octetString %s", hexString, octetString.toString()));
>
>          } else {
>
>              System.out.println(String.format("HexString %s is not
> printable as an octetString", hexString));
>
>          }
>
>          byte firstByte = octetString.get(0);
>
>          char firstChar = (char)firstByte;
>
>          if (Character.isISOControl(firstChar)) {
>
>              System.out.println("1C isISOControl");
>
>          } else {
>
>              System.out.println("1C not isISOControl");
>
>          }
>
>          if (Character.isWhitespace(firstChar)) {
>
>              System.out.println("1C isWhitespace");
>
>          } else {
>
>              System.out.println("1C not isWhitespace");
>
>          }
>
>      }
>
> }
>
>
>
> The output is:
>
> HexString 1C:32:41:1C:4E:38 is printable as an octetString 
2A
N8
>
> 1C isISOControl
>
> 1C isWhitespace
>
>
>
> Thanks in advance,
>
> Mark
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list