本文整理汇总了Java中org.snmp4j.asn1.BER类的典型用法代码示例。如果您正苦于以下问题:Java BER类的具体用法?Java BER怎么用?Java BER使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BER类属于org.snmp4j.asn1包,在下文中一共展示了BER类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: decodeBER
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
BER.MutableByte type = new BER.MutableByte();
byte[] value = BER.decodeString(inputStream, type);
if (type.getValue() != BER.IPADDRESS) {
throw new IOException("Wrong type encountered when decoding Counter: "+
type.getValue());
}
if (value.length != 4) {
if ( (value.length == 8) && Boolean.getBoolean("org.opennms.snmp.workarounds.allow64BitIpAddress") ) {
byte[] tempValue = { 0,0,0,0 };
for (int i = 0; i < 4; i++) {
tempValue[i] = value[i];
}
value = tempValue;
if (log().isDebugEnabled()) {
log().debug("Working around misencoded IpAddress (8 bytes, truncating to 4); likely dealing with a buggy Net-SNMP agent");
}
} else {
throw new IOException("IpAddress encoding error, wrong length: " +
value.length);
}
}
this.setInetAddress(InetAddress.getByAddress(value));
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:IpAddressNetSnmp64bitBugAware.java
示例2: setOIDEncodingToByteArray
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @param sObjectID
* @param bBerDataType
* @param sValue
* @return byte[]
* @throws Exception */
public static byte[] setOIDEncodingToByteArray (String sObjectID , byte bBerDataType , String sValue) throws Exception {
boolean localDebug = Boolean.FALSE;
if (localDebug|debug) {
logger.debug("BERService.setOIDEncodingToByteArray(s,b,s) - OID: " + sObjectID + " -> Value: " + sValue);
}
sObjectID = NetSNMP.toDottedOID(sObjectID);
if (bBerDataType == HEX) {
return HexString.toByteArray(setOIDEncoding ( sObjectID , BER.OCTETSTRING , HexString.toByteArray(sValue)));
} else {
return HexString.toByteArray(setOIDEncoding ( sObjectID , bBerDataType , sValue));
}
}
开发者ID:Comcast,项目名称:Oscar,代码行数:25,代码来源:BERService.java
示例3: isNumberDataType
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @param iBerDataType
* @return boolean
*/
public static boolean isNumberDataType (int iBerDataType) {
boolean boolStatus = false;
if ((iBerDataType == BER.COUNTER) ||
(iBerDataType == BER.COUNTER32) ||
(iBerDataType == BER.COUNTER64) ||
(iBerDataType == BER.GAUGE) ||
(iBerDataType == BER.GAUGE32) ||
(iBerDataType == BER.INTEGER) ||
(iBerDataType == BER.INTEGER32) ||
(iBerDataType == BER.TIMETICKS)) {
boolStatus = true;
}
return boolStatus;
}
开发者ID:Comcast,项目名称:Oscar,代码行数:23,代码来源:BERService.java
示例4: berStringDataTypeToByte
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
* @param sDataType
* @return byte */
public static byte berStringDataTypeToByte (String sDataType) {
if (COUNTER32.equalsIgnoreCase(sDataType)) {
return BER.COUNTER32;
} else if (COUNTER64.equalsIgnoreCase(sDataType)) {
return BER.COUNTER64;
} else if (GAUGE32.equalsIgnoreCase(sDataType)) {
return BER.GAUGE32;
} else if (INTEGER32.equalsIgnoreCase(sDataType)) {
return BER.INTEGER32;
} else if (TIMETICKS.equalsIgnoreCase(sDataType)) {
return BER.TIMETICKS;
} else if (IPADDRESS.equalsIgnoreCase(sDataType)) {
return BER.IPADDRESS;
} else if (OCTETSTRING.equalsIgnoreCase(sDataType)) {
return BER.OCTETSTRING;
} else if (HEXSTRING.equalsIgnoreCase(sDataType)) {
return HEX;
}
return 0x00;
}
开发者ID:Comcast,项目名称:Oscar,代码行数:27,代码来源:BERService.java
示例5: decodeBER
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public void decodeBER(BERInputStream inputStream) throws IOException {
BER.MutableByte type = new BER.MutableByte();
byte[] value = BER.decodeString(inputStream, type);
if (type.getValue() != BER.IPADDRESS) {
throw new IOException(
"Wrong type encountered when decoding Counter: "
+ type.getValue()
);
}
if (value.length != 4) {
logger.warn(
"IpAddress encoding is invalid, wrong length: " + value.length
);
super.setInetAddress(null);
rawValue = value;
}
else {
setAddress(value);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:21,代码来源:LenientIpAddress.java
示例6: isStringDataType
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @param iBerDataType
* @return boolean*/
public static boolean isStringDataType (int iBerDataType) {
boolean boolStatus = false;
if ((iBerDataType == BER.IPADDRESS) || (iBerDataType == BER.OCTETSTRING) ) {
boolStatus = true;
}
return boolStatus;
}
开发者ID:Comcast,项目名称:Oscar,代码行数:15,代码来源:BERService.java
示例7: initBER
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
* */
private void initBER() {
BER_DATA_TYPE.put((int) BER.COUNTER32, "Counter32");
BER_DATA_TYPE.put((int) BER.COUNTER64, "Counter64");
BER_DATA_TYPE.put((int) BER.GAUGE32, "Gauge32");
BER_DATA_TYPE.put((int) BER.INTEGER32, "Integer32");
BER_DATA_TYPE.put((int) BER.TIMETICKS, "TimeTicks");
BER_DATA_TYPE.put((int) BER.IPADDRESS, "IpAddress");
BER_DATA_TYPE.put((int) BER.OCTETSTRING, "OctetString");
//This Type does not exists as a SNMP DataType, this is only for use in this program
BER_DATA_TYPE.put(BinaryConversion.byteToUnsignedInteger(BERService.HEX), "HexString");
}
开发者ID:Comcast,项目名称:Oscar,代码行数:15,代码来源:ConfigurationFileExport.java
示例8: init
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public void init(String host, String varBind) {
vbs = getVariableBinding(varBind);
if (pduType == PDU.INFORM || pduType == PDU.TRAP) {
checkTrapVariables(vbs);
}
address = new UdpAddress(host + "/" + _port);
LogFactory.setLogFactory(new Log4jLogFactory());
BER.setCheckSequenceLength(false);
}
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:10,代码来源:SnmpUtil.java
示例9: decodeBER
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public void decodeBER(BERInputStream inputStream) throws java.io.IOException {
BER.MutableByte type = new BER.MutableByte();
int length;
BigInteger value = BigInteger.ZERO;
type.setValue((byte)inputStream.read());
if ((type.getValue() != 0x02) && (type.getValue() != 0x43) &&
(type.getValue() != 0x41)) {
throw new IOException("Wrong ASN.1 type. Not an integer: "+type.getValue()+
(" at position "+inputStream.getPosition()));
}
length = BER.decodeLength(inputStream);
if (length > 4) {
if (log().isDebugEnabled()) {
log().debug("Working around invalid Integer32 likely dealing with a permissive Net-SNMP agent");
}
}
int b = inputStream.read() & 0xFF;
if ((b & 0x80) > 0) {
value = BigInteger.ONE.negate();
}
while (length-- > 0) {
value = value.shiftLeft(8).or(BigInteger.valueOf(b));
if (length > 0) {
b = inputStream.read();
}
}
int newValue = value.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0 ? 0 : value.intValue();
if (type.getValue() != BER.INTEGER) {
throw new IOException("Wrong type encountered when decoding Counter: "+type.getValue());
}
setValue(newValue);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:Integer32IgnoreTooManyBytes.java
示例10: encodeBER
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public void encodeBER(OutputStream outputStream) throws IOException {
if (isValid()) {
super.encodeBER(outputStream);
}
else {
logger.warn("Encode invalid IpAddress: " + joinBytesWithDot(rawValue));
BER.encodeString(outputStream, BER.IPADDRESS, rawValue);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:10,代码来源:LenientIpAddress.java
示例11: getBERLength
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public int getBERLength() {
if (isValid()) {
return super.getBERLength();
}
else {
return rawValue.length + BER.getBERLengthOfLength(rawValue.length) + 1;
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:9,代码来源:LenientIpAddress.java
示例12: format
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
* Returns a textual representation of the supplied variable against the
* optionally supplied instance OID.
*
* @param instanceOID the instance OID <code>variable</code> is associated
* with. If <code>null</code> the formatting cannot take any MIB
* specification of the variable into account and has to format it based
* on its type only.
* @param variable
* the variable to format.
* @param withOID
* if <code>true</code> the <code>instanceOID</code> should be included
* in the textual representation to form a {@link VariableBinding}
* representation.
* @return the textual representation.
*/
public String format(OID instanceOID, Variable variable, boolean withOID) {
String valueString;
String typeString = variable.getSyntaxString();
switch (variable.getSyntax()) {
case SMIConstants.SYNTAX_TIMETICKS :
valueString = String.valueOf(((TimeTicks) variable).getValue());
break;
case SMIConstants.SYNTAX_OCTET_STRING :
if (!is_PrintableOneLine(((OctetString)variable))) {
typeString = TYPE_NAME_4_OCTETSTRING_IN_HEX;
valueString = ((OctetString)variable).toHexString();
}
else {
valueString = variable.toString();
}
break;
case BER.BITSTRING:
valueString = ((BitString)variable).toHexString();
break;
default :
valueString = variable.toString();
break;
}
if (withOID) {
return oidFormat.format(instanceOID.getValue())
+ SEPARATOR + typeString + SEPARATOR + valueString;
}
else {
return valueString;
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:50,代码来源:ColonSeparatedOidTypeValueVariableTextFormat.java
示例13: parseVariableBinding
import org.snmp4j.asn1.BER; //导入依赖的package包/类
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)
);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:29,代码来源:ColonSeparatedOidTypeValueVariableTextFormat.java
示例14: main
import org.snmp4j.asn1.BER; //导入依赖的package包/类
public static void main(String[] args) {
ConfigurationFileExport cfe =
new ConfigurationFileExport (TestDirectoryStructure.fInputDirFileName("DOCSIS-GOLDEN.txt.bin"),
ConfigurationFileExport.DOCSIS_VER_31);
System.out.println(cfe.toPrettyPrint(ConfigurationFileExport.EXPORT_FOUND_TLV));
ConfigurationFileImport cfi =
new ConfigurationFileImport(new StringBuilder(cfe.toPrettyPrint(ConfigurationFileExport.EXPORT_FOUND_TLV)));
ConfigurationFile cf = new ConfigurationFile(cfi.getConfigurationFileType(),cfi.getTlvBuilder());
CommonTlvInsertions.insertSnmpOID("docsDevNmAccessIp.1", BER.INTEGER, 1, cf, CommonTlvInsertions.FINALIZE_FALSE);
cfe = new ConfigurationFileExport(cf);
System.out.println(cfe.toPrettyPrint(ConfigurationFileExport.EXPORT_FOUND_TLV));
}
开发者ID:Comcast,项目名称:Oscar,代码行数:22,代码来源:NetSNMPTlvInsertionTest.java
示例15: parseBits
import org.snmp4j.asn1.BER; //导入依赖的package包/类
private BitString parseBits(String valueString) throws ParseException {
String[] strOctets = valueString.split(String.valueOf(HEX_SEPARATOR));
StringBuilder valuePattern = new StringBuilder();
StringBuilder parsedOctets = new StringBuilder();
boolean match = false;
for (int octIdx = 0; octIdx < strOctets.length; octIdx++) {
int octet;
try {
octet = Integer.parseInt(strOctets[octIdx], 16);
parsedOctets.append(strOctets[octIdx]).append(HEX_SEPARATOR);
} catch (NumberFormatException e) {
throw
new ParseException("Invalid value for BITS: "+ valueString, octIdx);
}
int mask = 128;
for (int bitIdx = 0; bitIdx < 8; bitIdx++) {
if ((octet & mask) != 0) {
valuePattern.append(octIdx * 8 + bitIdx).append(HEX_SEPARATOR);
}
mask >>= 1;
}
if (
valueString.matches(parsedOctets + "(00 )*" + valuePattern)
) {
match = true;
break;
}
}
BitString bs
= (BitString)AbstractVariable.createFromSyntax(BER.ASN_BIT_STR);
if (match) {
bs.setValue(
OctetString.fromHexString(
valueString.substring(
0,
valueString.lastIndexOf(valuePattern.toString())
),
HEX_SEPARATOR
).getValue()
);
}
else {
bs.setValue(
OctetString.fromHexString(
valueString,
HEX_SEPARATOR
).getValue()
);
}
return bs;
}
开发者ID:kaitoy,项目名称:sneo,代码行数:58,代码来源:NetSnmpVariableTextFormat.java
示例16: insertSHA1Hash
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @param bTlvArray
* @param bSHA1
* @return byte[]
* @throws IOException */
private byte[] insertSHA1Hash(byte[] bTlvArray, byte[] bSHA1) throws IOException {
ByteArrayOutputStream baosbTlvArray = new ByteArrayOutputStream();
//Write into Array
baosbTlvArray.write(bTlvArray);
//Create SHA-1 TLV
TlvBuilder tbTlvSHA1 = new TlvBuilder();
//Select Correct Packet Cable Version
if (iPacketCableVersion == ConfigurationFileTypeConstants.PKT_CABLE_10_CONFIGURATION_TYPE) {
tbTlvSHA1.add( PacketCableConstants.SNMP_TLV_11,
new OID(PacketCableConstants.PKT_CABLE_10_BASIC_AUTH_OID),
BER.OCTETSTRING, bSHA1);
} else if (iPacketCableVersion == ConfigurationFileTypeConstants.PKT_CABLE_15_CONFIGURATION_TYPE) {
tbTlvSHA1.add( PacketCableConstants.SNMP_TLV_11,
new OID(PacketCableConstants.PKT_CABLE_15_BASIC_AUTH_OID),
BER.OCTETSTRING, bSHA1);
} else if (iPacketCableVersion == ConfigurationFileTypeConstants.PKT_CABLE_20_CONFIGURATION_TYPE) {
tbTlvSHA1.add( PacketCableConstants.SNMP_TLV_11,
new OID(PacketCableConstants.PKT_CABLE_20_BASIC_AUTH_OID),
BER.OCTETSTRING, bSHA1);
}
//Added SHA1 Hash BASIC.1 Authentication
baosbTlvArray.write(tbTlvSHA1.toByteArray());
return baosbTlvArray.toByteArray();
}
开发者ID:Comcast,项目名称:Oscar,代码行数:43,代码来源:PacketCableCompiler.java
示例17: toMap
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @return Map<String,String>
*/
public Map<String,String> toMap () {
boolean localDebug = Boolean.FALSE;
Map<String, String> mssReturn = new HashMap<String,String>();
mssReturn.put(OID, NetSNMP.toTextualOID(getOidName()));
//Make sure it is a OCTET String and a HexString with : and is it contains NON PlainText ASCII Char
//mgarcia - 140224 - Added Logic to figure out a HexString vs. OctetString in some conditions from Packet ACE Tool
if (
(vbBER.getSyntax() == BinaryConversion.byteToUnsignedInteger(BER.OCTETSTRING)) &&
/* Checks to see if the string is in DEXTER HEX FORMAT */ /*Checks to see if there is a HEX String of 1 byte */
((!vbBER.getVariable().toString().matches("(.*:.*)+?")) &&
(vbBER.getVariable().toString().length() <= HexString.HEX_STRING_1_BYTE_LENGTH)) &&
/* Make sure that String is a HEX Format */
(HexString.isHexString(vbBER.getVariable().toString())) &&
/* Checks to see if the HEX String Contains and Values that are outside of the Typical ASCII Chars*/
(!HexString.verifyAsciiPlainText(HexString.toByteArray(vbBER.getVariable().toString())))
) {
if (localDebug|debug)
logger.debug("BEROIDConversion.toMap() - Found a NON-ASCII Plain Text Characters");
mssReturn.put(DATA_TYPE, Integer.toString(BinaryConversion.byteToUnsignedInteger(BERService.HEX)));
mssReturn.put(VALUE, vbBER.getVariable().toString());
} else if (
(vbBER.getSyntax() == BinaryConversion.byteToUnsignedInteger(BER.OCTETSTRING)) &&
((HexString.isHexString(vbBER.getVariable().toString())) && (vbBER.getVariable().toString().matches("(.*:.*)+?"))) &&
(!HexString.verifyAsciiPlainText(HexString.toByteArray(vbBER.getVariable().toString())))
) {
if (localDebug|debug)
logger.debug("BEROIDConversion.toMap() - Found a NON-ASCII Plain Text Characters");
mssReturn.put(DATA_TYPE, Integer.toString(BinaryConversion.byteToUnsignedInteger(BERService.HEX)));
mssReturn.put(VALUE, vbBER.getVariable().toString());
} else if (
(vbBER.getSyntax() == BinaryConversion.byteToUnsignedInteger(BER.OCTETSTRING)) &&
(HexString.containAsciiWhiteSpace(HexString.toByteArray(HexString.asciiToHex(getOidValue()))))
) {
if (localDebug|debug)
logger.debug("BEROIDConversion.toMap() - Found a ASCII Plain Text Characters: \"" + getOidValue() + "\"");
mssReturn.put(DATA_TYPE, getDataType().toString());
mssReturn.put(VALUE, vbBER.getVariable().toString());
} else {
mssReturn.put(DATA_TYPE, getDataType().toString());
mssReturn.put(VALUE, getOidValue());
}
return mssReturn;
}
开发者ID:Comcast,项目名称:Oscar,代码行数:72,代码来源:BEROIDConversion.java
示例18: getBERSetValue
import org.snmp4j.asn1.BER; //导入依赖的package包/类
/**
*
* @param bBERSetValueTLV
* @return String
* @throws TlvException */
public static String getBERSetValue (byte[] bBERSetValueTLV) throws TlvException {
boolean localDebug = Boolean.FALSE;
byte bBerDataType = bBERSetValueTLV[0];
byte[] bBerDataValue = TlvBuilder.getTlvValue(bBERSetValueTLV);
Integer iBERValue = null;
String sBERValue = null;
if ((BER.COUNTER == bBerDataType) || (BER.COUNTER32 == bBerDataType)) {
iBERValue = new HexString(bBerDataValue).toInteger();
sBERValue = iBERValue.toString();
} else if (BER.COUNTER64 == bBerDataType) {
iBERValue = new HexString(bBerDataValue).toInteger();
sBERValue = iBERValue.toString();
} else if ((BER.GAUGE == bBerDataType) || (BER.GAUGE32 == bBerDataType)) {
iBERValue = new HexString(bBerDataValue).toInteger();
sBERValue = iBERValue.toString();
} else if ((BER.INTEGER == bBerDataType) || (BER.INTEGER32 == bBerDataType)) {
iBERValue = new HexString(bBerDataValue).toInteger();
sBERValue = iBERValue.toString();
} else if ((BER.TIMETICKS == bBerDataType)) {
iBERValue = new HexString(bBerDataValue).toInteger();
sBERValue = iBERValue.toString();
} else if (BER.IPADDRESS == bBerDataType) {
if (debug|localDebug) {
HexString hsBerIpAddress = new HexString(bBerDataValue);
logger.debug("BER.IPADDRESS: " + hsBerIpAddress);
}
sBERValue = HexString.toInetAddress(bBerDataValue);
} else if (BER.OCTETSTRING == bBerDataType) {
sBERValue = new HexString(bBerDataValue).toASCII();
}
return sBERValue;
}
开发者ID:Comcast,项目名称:Oscar,代码行数:62,代码来源:BERService.java
注:本文中的org.snmp4j.asn1.BER类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论