当前位置: 首页>>代码示例>>C#>>正文


C# BigEndianBinaryReader.ReadString方法代码示例

本文整理汇总了C#中BigEndianBinaryReader.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# BigEndianBinaryReader.ReadString方法的具体用法?C# BigEndianBinaryReader.ReadString怎么用?C# BigEndianBinaryReader.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigEndianBinaryReader的用法示例。


在下文中一共展示了BigEndianBinaryReader.ReadString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClassName

		// This method parses just enough of the class file to obtain its name, it doesn't
		// validate the class file structure, but it may throw a ClassFormatError if it
		// encounters bogus data
		internal static string GetClassName(byte[] buf, int offset, int length)
		{
			BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
			if(br.ReadUInt32() != 0xCAFEBABE)
			{
				throw new ClassFormatError("Bad magic number");
			}
			int minorVersion = br.ReadUInt16();
			int majorVersion = br.ReadUInt16();
			if((majorVersion & FLAG_MASK_MAJORVERSION) != majorVersion
				|| majorVersion < SupportedVersions.Minimum
				|| majorVersion > SupportedVersions.Maximum
				|| (majorVersion == SupportedVersions.Minimum && minorVersion < 3)
				|| (majorVersion == SupportedVersions.Maximum && minorVersion != 0))
			{
				throw new UnsupportedClassVersionError(majorVersion + "." + minorVersion);
			}
			int constantpoolcount = br.ReadUInt16();
			int[] cpclass = new int[constantpoolcount];
			string[] utf8_cp = new string[constantpoolcount];
			for(int i = 1; i < constantpoolcount; i++)
			{
				Constant tag = (Constant)br.ReadByte();
				switch(tag)
				{
					case Constant.Class:
						cpclass[i] = br.ReadUInt16();
						break;
					case Constant.Double:
					case Constant.Long:
						br.Skip(8);
						i++;
						break;
					case Constant.Fieldref:
					case Constant.InterfaceMethodref:
					case Constant.Methodref:
					case Constant.InvokeDynamic:
					case Constant.NameAndType:
					case Constant.Float:
					case Constant.Integer:
						br.Skip(4);
						break;
					case Constant.MethodHandle:
						br.Skip(3);
						break;
					case Constant.String:
					case Constant.MethodType:
						br.Skip(2);
						break;
					case Constant.Utf8:
						utf8_cp[i] = br.ReadString("<unknown>");
						break;
					default:
						throw new ClassFormatError("Illegal constant pool type 0x{0:X}", tag);
				}
			}
			br.ReadUInt16(); // access_flags
			try
			{
				return String.Intern(utf8_cp[cpclass[br.ReadUInt16()]].Replace('/', '.'));
			}
			catch(Exception x)
			{
				throw new ClassFormatError("{0}: {1}", x.GetType().Name, x.Message);
			}
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:69,代码来源:ClassFile.cs

示例2: ClassFile

		internal ClassFile(byte[] buf, int offset, int length, string inputClassName, ClassFileParseOptions options)
		{
			try
			{
				BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
				if(br.ReadUInt32() != 0xCAFEBABE)
				{
					throw new ClassFormatError("{0} (Bad magic number)", inputClassName);
				}
				ushort minorVersion = br.ReadUInt16();
				ushort majorVersion = br.ReadUInt16();
				if((majorVersion & FLAG_MASK_MAJORVERSION) != majorVersion
					|| majorVersion < SupportedVersions.Minimum
					|| majorVersion > SupportedVersions.Maximum
					|| (majorVersion == SupportedVersions.Minimum && minorVersion < 3)
					|| (majorVersion == SupportedVersions.Maximum && minorVersion != 0))
				{
					throw new UnsupportedClassVersionError(inputClassName + " (" + majorVersion + "." + minorVersion + ")");
				}
				flags = majorVersion;
				int constantpoolcount = br.ReadUInt16();
				constantpool = new ConstantPoolItem[constantpoolcount];
				string[] utf8_cp = new string[constantpoolcount];
				for(int i = 1; i < constantpoolcount; i++)
				{
					Constant tag = (Constant)br.ReadByte();
					switch(tag)
					{
						case Constant.Class:
							constantpool[i] = new ConstantPoolItemClass(br);
							break;
						case Constant.Double:
							constantpool[i] = new ConstantPoolItemDouble(br);
							i++;
							break;
						case Constant.Fieldref:
							constantpool[i] = new ConstantPoolItemFieldref(br);
							break;
						case Constant.Float:
							constantpool[i] = new ConstantPoolItemFloat(br);
							break;
						case Constant.Integer:
							constantpool[i] = new ConstantPoolItemInteger(br);
							break;
						case Constant.InterfaceMethodref:
							constantpool[i] = new ConstantPoolItemInterfaceMethodref(br);
							break;
						case Constant.Long:
							constantpool[i] = new ConstantPoolItemLong(br);
							i++;
							break;
						case Constant.Methodref:
							constantpool[i] = new ConstantPoolItemMethodref(br);
							break;
						case Constant.NameAndType:
							constantpool[i] = new ConstantPoolItemNameAndType(br);
							break;
						case Constant.MethodHandle:
							if (majorVersion < 51)
								goto default;
							constantpool[i] = new ConstantPoolItemMethodHandle(br);
							break;
						case Constant.MethodType:
							if (majorVersion < 51)
								goto default;
							constantpool[i] = new ConstantPoolItemMethodType(br);
							break;
						case Constant.InvokeDynamic:
							if (majorVersion < 51)
								goto default;
							constantpool[i] = new ConstantPoolItemInvokeDynamic(br);
							break;
						case Constant.String:
							constantpool[i] = new ConstantPoolItemString(br);
							break;
						case Constant.Utf8:
							utf8_cp[i] = br.ReadString(inputClassName);
							break;
						default:
							throw new ClassFormatError("{0} (Illegal constant pool type 0x{1:X})", inputClassName, tag);
					}
				}
				for(int i = 1; i < constantpoolcount; i++)
				{
					if(constantpool[i] != null)
					{
						try
						{
							constantpool[i].Resolve(this, utf8_cp, options);
						}
						catch(ClassFormatError x)
						{
							// HACK at this point we don't yet have the class name, so any exceptions throw
							// are missing the class name
							throw new ClassFormatError("{0} ({1})", inputClassName, x.Message);
						}
						catch(IndexOutOfRangeException)
						{
							throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
						}
//.........这里部分代码省略.........
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:101,代码来源:ClassFile.cs

示例3: StringTests

        public void StringTests(String expectedValue, Byte[] givenBytes)
        {
            // arrange
            var binaryReader = new BigEndianBinaryReader(givenBytes);

            // act
            var actualValue = binaryReader.ReadString();

            // assert
            Assert.That(expectedValue, Is.EqualTo(actualValue));
        }
开发者ID:BDeus,项目名称:KafkaNetClient,代码行数:11,代码来源:BigEndianBinaryReaderTests.cs

示例4: ClassFile

	internal ClassFile(byte[] buf, int offset, int length, string inputClassName, bool allowJavaLangObject)
	{
		try
		{
			BigEndianBinaryReader br = new BigEndianBinaryReader(buf, offset, length);
			if (br.ReadUInt32() != 0xCAFEBABE)
			{
				throw new ClassFormatError("{0} (Bad magic number)", inputClassName);
			}
			int minorVersion = br.ReadUInt16();
			majorVersion = br.ReadUInt16();
			if (majorVersion < SupportedVersions.Minimum || majorVersion > SupportedVersions.Maximum)
			{
				throw new UnsupportedClassVersionError(inputClassName + " (" + majorVersion + "." + minorVersion + ")");
			}
			int constantpoolcount = br.ReadUInt16();
			constantpool = new ConstantPoolItem[constantpoolcount];
			utf8_cp = new string[constantpoolcount];
			for (int i = 1; i < constantpoolcount; i++)
			{
				Constant tag = (Constant) br.ReadByte();
				switch (tag)
				{
					case Constant.Class:
						constantpool[i] = new ConstantPoolItemClass(br);
						break;
					case Constant.Double:
						constantpool[i] = new ConstantPoolItemDouble(br);
						i++;
						break;
					case Constant.Fieldref:
						constantpool[i] = new ConstantPoolItemFieldref(br);
						break;
					case Constant.Float:
						constantpool[i] = new ConstantPoolItemFloat(br);
						break;
					case Constant.Integer:
						constantpool[i] = new ConstantPoolItemInteger(br);
						break;
					case Constant.InterfaceMethodref:
						constantpool[i] = new ConstantPoolItemInterfaceMethodref(br);
						break;
					case Constant.Long:
						constantpool[i] = new ConstantPoolItemLong(br);
						i++;
						break;
					case Constant.Methodref:
						constantpool[i] = new ConstantPoolItemMethodref(br);
						break;
					case Constant.NameAndType:
						constantpool[i] = new ConstantPoolItemNameAndType(br);
						break;
					case Constant.String:
						constantpool[i] = new ConstantPoolItemString(br);
						break;
					case Constant.Utf8:
						utf8_cp[i] = br.ReadString(inputClassName);
						break;
					default:
						throw new ClassFormatError("{0} (Illegal constant pool type 0x{1:X})", inputClassName, tag);
				}
			}
			for (int i = 1; i < constantpoolcount; i++)
			{
				if (constantpool[i] != null)
				{
					try
					{
						constantpool[i].Resolve(this);
					}
					catch (ClassFormatError x)
					{
						// HACK at this point we don't yet have the class name, so any exceptions throw
						// are missing the class name
						throw new ClassFormatError("{0} ({1})", inputClassName, x.Message);
					}
					catch (IndexOutOfRangeException)
					{
						throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
					}
					catch (InvalidCastException)
					{
						throw new ClassFormatError("{0} (Invalid constant pool item #{1})", inputClassName, i);
					}
				}
			}
			access_flags = (__Modifiers) br.ReadUInt16();
			// NOTE although the vmspec says (in 4.1) that interfaces must be marked abstract, earlier versions of
			// javac (JDK 1.1) didn't do this, so the VM doesn't enforce this rule
			// NOTE although the vmspec implies (in 4.1) that ACC_SUPER is illegal on interfaces, it doesn't enforce this
			if ((IsInterface && IsFinal) || (IsAbstract && IsFinal))
			{
				throw new ClassFormatError("{0} (Illegal class modifiers 0x{1:X})", inputClassName, access_flags);
			}
			this_class = br.ReadUInt16();
			ValidateConstantPoolItemClass(inputClassName, this_class);
			super_class = br.ReadUInt16();
			// NOTE for convenience we allow parsing java/lang/Object (which has no super class), so
			// we check for super_class != 0
			if (super_class != 0)
//.........这里部分代码省略.........
开发者ID:sourcewarehouse,项目名称:janett,代码行数:101,代码来源:ClassFile.cs

示例5: ReadConstantPool


//.........这里部分代码省略.........
                         u2 string_index;
                     }
                 */
                 item.ConstantType = ConstantType.String;
                 item.StringIndex = reader.ReadUInt16();
                 break;
             case ConstantType.Integer:
                 /*
                     CONSTANT_Integer_info {
                         u1 tag;
                         u4 bytes;
                     }
                 */
                 item.ConstantType = ConstantType.Integer;
                 item.Integer = reader.ReadInt32();
                 break;
             case ConstantType.Float:
                 /*
                     CONSTANT_Float_info {
                         u1 tag;
                         u4 bytes;
                     }
                 */
                 item.ConstantType = ConstantType.Float;
                 item.Float = reader.ReadSingle();
                 break;
             case ConstantType.Long:
                 /*
                     CONSTANT_Long_info {
                         u1 tag;
                         u4 high_bytes;
                         u4 low_bytes;
                     }
                 */
                 item.ConstantType = ConstantType.Long;
                 item.Long = reader.ReadInt64();
                 // JVM Spec. 4.4.5.
                 // All 8-byte constants take up two entries in the
                 // constant_pool table of the class file. If a
                 // CONSTANT_Long_info or CONSTANT_Double_info structure
                 // is the item in the constant_pool table at index n,
                 // then the next usable item in the pool is located at
                 // index n+2. The constant_pool index n+1 must be valid
                 // but is considered unusable.2
                 // 2 In retrospect, making 8-byte constants take two
                 // constant pool entries was a poor choice.
                 ++i;
                 break;
             case ConstantType.Double:
                 /*
                     CONSTANT_Double_info {
                         u1 tag;
                         u4 high_bytes;
                         u4 low_bytes;
                     }
                 */
                 item.ConstantType = ConstantType.Double;
                 item.Double = reader.ReadDouble();
                 // JVM Spec. 4.4.5.
                 // All 8-byte constants take up two entries in the
                 // constant_pool table of the class file. If a
                 // CONSTANT_Long_info or CONSTANT_Double_info structure
                 // is the item in the constant_pool table at index n,
                 // then the next usable item in the pool is located at
                 // index n+2. The constant_pool index n+1 must be valid
                 // but is considered unusable.2
                 // 2 In retrospect, making 8-byte constants take two
                 // constant pool entries was a poor choice.
                 ++i;
                 break;
             case ConstantType.NameAndType:
                 /*
                     CONSTANT_NameAndType_info {
                         u1 tag;
                         u2 name_index;
                         u2 descriptor_index;
                     }
                 */
                 item.ConstantType = ConstantType.NameAndType;
                 item.NameIndex = reader.ReadUInt16();
                 item.DescriptorIndex = reader.ReadUInt16();
                 break;
             case ConstantType.Utf8:
                 /*
                     CONSTANT_Utf8_info {
                         u1 tag;
                         u2 length;
                         u1 bytes[length];
                     }
                 */
                 item.ConstantType = ConstantType.Utf8;
                 item.String = reader.ReadString(reader.ReadUInt16());
                 break;
             default:
                 throw new ApplicationException("Wrong ConstantType: " +
                     tag);
         }
     }
     return constantPool;
 }
开发者ID:olympum,项目名称:caffeine,代码行数:101,代码来源:ClassFile.cs

示例6: StringTests

        public void StringTests(String expectedValue, Byte[] givenBytes)
        {
            // arrange
            var memoryStream = new MemoryStream(givenBytes);
            var binaryReader = new BigEndianBinaryReader(memoryStream);

            // act
            var actualValue = binaryReader.ReadString();

            // assert
            Assert.Equal(expectedValue, actualValue);
        }
开发者ID:rudygt,项目名称:dot-kafka,代码行数:12,代码来源:BigEndianBinaryReaderTests.cs


注:本文中的BigEndianBinaryReader.ReadString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。