public static OctetString fromHexString(String hexString) { return fromHexString(hexString, DEFAULT_HEX_DELIMITER); }
public static OctetString fromHexString(String hexString) { return fromHexString(hexString, DEFAULT_HEX_DELIMITER); }
public static OctetString fromHexString(String hexString) { return fromHexString(hexString, DEFAULT_HEX_DELIMITER); }
private static OctetString createOctetString(String s) { if (StringUtils.isBlank(s)) { return null; } OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
private static OctetString createOctetString(String s) { OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
private static OctetString createOctetString(String s) { if (StringUtils.isBlank(s)) { return null; } OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
private OctetString createOctetString(String s) { if (s == null) { return null; } OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
private static OctetString createOctetString(String s) { OctetString octetString; if (s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else { octetString = new OctetString(s); } return octetString; }
/** * Create an OctetString from a String value. * @param s * the string value to convert. If it starts with <code>0x</code> its * trailing value will be interpreted as a hex string with colon (:) * separator. * @param defaultString * an optional default if <code>s</code> is <code>null</code>. * @return * an OctetString or <code>null</code> if <code>s</code> is * <code>null</code>. * @since 1.10.2 */ public static OctetString createOctetString(String s, String defaultString) { OctetString octetString = null; if (s == null) { s = defaultString; } if ((s != null) && s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else if (s != null) { octetString = new OctetString(s); } return octetString; }
/** * Create an OctetString from a String value. * * @param s * the string value to convert. If it starts with <code>0x</code> its * trailing value will be interpreted as a hex string with colon (:) * separator. * @param defaultString * an optional default if <code>s</code> is <code>null</code>. * * @return an OctetString or <code>null</code> if <code>s</code> is * <code>null</code>. * @since 1.10.2 */ public static OctetString createOctetString(String s, String defaultString) { OctetString octetString = null; if (s == null) { s = defaultString; } if ((s != null) && s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else if (s != null) { octetString = new OctetString(s); } return octetString; }
/** * Create an OctetString from a String value. * @param s * the string value to convert. If it starts with <code>0x</code> its * trailing value will be interpreted as a hex string with colon (:) * separator. * @param defaultString * an optional default if <code>s</code> is <code>null</code>. * @return * an OctetString or <code>null</code> if <code>s</code> is * <code>null</code>. * @since 1.10.2 */ public static OctetString createOctetString(String s, String defaultString) { OctetString octetString = null; if (s == null) { s = defaultString; } if ((s != null) && s.startsWith("0x")) { octetString = OctetString.fromHexString(s.substring(2), ':'); } else if (s != null) { octetString = new OctetString(s); } return octetString; }
/** * Converts an SNMP string representation into a {@link Date} object, * and applies time zone conversion to provide the time on the local machine, ie PSM server. * * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain * a timezone offset in 3 extra bytes * @param sysInfoTimeZone Must be supplied if actAlarmDateAndTime is just local time (with no timezone) * @param swVersion Must be supplied if actAlarmDateAndTime is just local time (with no timezone) * @return adjusted {@link Date} or a simple conversion if other fields are null. */ public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone, String swVersion) { if (StringUtils.isBlank(actAlarmDateAndTime)) { return null; } GregorianCalendar decodedDateAndTimeCal = btiMakeCalendar(OctetString.fromHexString(actAlarmDateAndTime)); if ((sysInfoTimeZone == null) || (swVersion == null)) { return decodedDateAndTimeCal.getTime(); } TimeZone javaTimeZone = getTimeZone(); decodedDateAndTimeCal.setTimeZone(javaTimeZone); GregorianCalendar localTime = new GregorianCalendar(); localTime.setTimeInMillis(decodedDateAndTimeCal.getTimeInMillis()); return localTime.getTime(); }
if (match) { bs.setValue( OctetString.fromHexString( valueString.substring( 0, OctetString.fromHexString( valueString, HEX_SEPARATOR
return; final OctetString message = OctetString.fromHexString(msg, ':'); byte[] packet = message.getValue(); logger.debug("Received message from "+addr+
return Long.valueOf(value); case TYPE_OCTET_STRING: return OctetString.fromHexString(value, ':'); default: return value;
return new Long(value); case TYPE_OCTET_STRING: return OctetString.fromHexString(value, ':'); default: return value;
return new Long(value); case TYPE_OCTET_STRING: return OctetString.fromHexString(value, ':'); default: return value;
public static Profile buildProfile(String managers, String engineId, String username, OID authProtocol, String authPassphrase, OID privProtocol, String privacyPassphrase, int securityLevel, String oid, int version) { Profile profile = new Profile(managers, oid, version); profile.engineId = OctetString.fromHexString(engineId); profile.username = new OctetString(username); profile.authProtocol = authProtocol; profile.authPassphrase = new OctetString(authPassphrase); profile.privProtocol = privProtocol; profile.privacyPassphrase = new OctetString(privacyPassphrase); profile.securityLevel = securityLevel; return profile; } }
public VariableBinding parseVariableBinding(String text) throws ParseException { String[] tokens = text.split(SEPARATOR, 3); if (tokens.length != 3) { throw new ParseException("Invalid format: "+ text, 0); } OID oid = new OID(oidFormat.parse(tokens[0])); String typeName = tokens[1]; String valueString = tokens[2]; if (typeName.equals(TYPE_NAME_4_OCTETSTRING_IN_HEX)) { OctetString os = (OctetString)parse(SMIConstants.SYNTAX_OCTET_STRING, ""); os.setValue(OctetString.fromHexString(valueString).getValue()); return new VariableBinding(oid, os); } else if (typeName.equals(AbstractVariable.getSyntaxString(BER.BITSTRING))) { BitString bs = (BitString)parse(BER.BITSTRING, ""); bs.setValue(BitString.fromHexString(valueString).getValue()); return new VariableBinding(oid, bs); } else { return new VariableBinding( oid, parse(AbstractVariable.getSyntaxFromString(typeName), valueString) ); } }
static PDU snmpMessageToHumanReadable(String s) throws IOException { final OctetString message = OctetString.fromHexString(s, ':'); final Address address = new UdpAddress(); final TransportMapping transportMapping = (address instanceof UdpAddress) ? new DefaultUdpTransportMapping((UdpAddress) address) : new DefaultTcpTransportMapping((TcpAddress) address); final MessageDispatcher messageDispatcher = new MessageDispatcherImpl(); SecurityProtocols.getInstance().addDefaultProtocols(); final SnmpMessageAnalyzer snmpMessageAnalyzer = new SnmpMessageAnalyzer(); final CommandResponder commandResponder = snmpMessageAnalyzer; messageDispatcher.addCommandResponder(commandResponder); messageDispatcher.addMessageProcessingModel(new MPv1()); messageDispatcher.addMessageProcessingModel(new MPv2c()); messageDispatcher.addMessageProcessingModel(new MPv3()); messageDispatcher.processMessage(transportMapping, address, ByteBuffer.wrap(message.getValue())); PDU result = snmpMessageAnalyzer.msg; snmpMessageAnalyzer.msg = null; return result; }