本文整理汇总了C#中ByteVector.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# ByteVector.StartsWith方法的具体用法?C# ByteVector.StartsWith怎么用?C# ByteVector.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteVector
的用法示例。
在下文中一共展示了ByteVector.StartsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
private void Parse(ByteVector data)
{
// Check to see if a valid Xing header is available.
if (!data.StartsWith("Xing"))
return;
// If the XingHeader doesn'type contain the number of frames and the total stream
// info it'field invalid.
if ((data[7] & 0x02) == 0)
{
TagLibDebugger.Debug("MPEG::XingHeader::parse() -- Xing header doesn't contain the total number of frames.");
return;
}
if ((data[7] & 0x04) == 0)
{
TagLibDebugger.Debug("MPEG::XingHeader::parse() -- Xing header doesn't contain the total stream size.");
return;
}
frames = data.Mid(8, 4).ToUInt();
size = data.Mid(12, 4).ToUInt();
valid = true;
}
示例2: StreamHeader
public StreamHeader(ByteVector data, long streamLength)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (!data.StartsWith(FileIdentifier))
{
throw new CorruptFileException("Data does not begin with identifier.");
}
if (data.Count < 0x38L)
{
throw new CorruptFileException("Insufficient data in stream header");
}
this.stream_length = streamLength;
this.version = data[3] & 15;
if (this.version >= 7)
{
this.frames = data.Mid(4, 4).ToUInt(false);
uint num = data.Mid(8, 4).ToUInt(false);
this.sample_rate = sftable[(((num >> 0x11) & 1) * 2) + ((num >> 0x10) & 1)];
this.header_data = 0;
}
else
{
this.header_data = data.Mid(0, 4).ToUInt(false);
this.version = ((int) (this.header_data >> 11)) & 0x3ff;
this.sample_rate = 0xac44;
this.frames = data.Mid(4, (this.version < 5) ? 2 : 4).ToUInt(false);
}
}
示例3: ParseStreamList
public static AviStream ParseStreamList (ByteVector data)
{
if (data == null)
throw new ArgumentNullException ("data");
AviStream stream = null;
int pos = 4;
if (data.StartsWith ("strl"))
while (pos + 8 < data.Count)
{
ByteVector id = data.Mid (pos, 4);
int block_length = (int) data.Mid (pos + 4, 4).ToUInt (false);
if (id == "strh" && stream == null)
{
AviStreamHeader stream_header = new AviStreamHeader (data, pos + 8);
if (stream_header.Type == "vids")
stream = new AviVideoStream (stream_header);
else if (stream_header.Type == "auds")
stream = new AviAudioStream (stream_header);
}
else if (stream != null)
stream.ParseItem (id, data, pos + 8, block_length);
pos += block_length + 8;
}
return stream;
}
示例4: Read
//private void Read(ByteVector data, long stream_length, ReadStyle style)
private void Read(ByteVector data, long streamLength)
{
if (data.StartsWith("MP+"))
return;
version = data[3] & 15;
uint frames;
if (version >= 7)
{
frames = data.Mid(4, 4).ToUInt(false);
uint flags = data.Mid(8, 4).ToUInt(false);
sampleRate = sfTable[(int)(((flags >> 17) & 1) * 2 + ((flags >> 16) & 1))];
channels = 2;
}
else
{
uint headerData = data.Mid(0, 4).ToUInt(false);
bitrate = (int)((headerData >> 23) & 0x01ff);
version = (int)((headerData >> 11) & 0x03ff);
sampleRate = 44100;
channels = 2;
if (version >= 5)
frames = data.Mid(4, 4).ToUInt(false);
else
frames = data.Mid(4, 2).ToUInt(false);
}
uint samples = frames * 1152 - 576;
duration = sampleRate > 0 ? TimeSpan.FromSeconds((double)samples / (double)sampleRate + 0.5) : TimeSpan.Zero;
if (bitrate == 0)
bitrate = (int)(duration > TimeSpan.Zero ? ((streamLength * 8L) / duration.TotalSeconds) / 1000 : 0);
}
示例5: XingHeader
public XingHeader(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (!data.StartsWith(FileIdentifier))
{
throw new CorruptFileException("Not a valid Xing header");
}
int startIndex = 8;
if ((data[7] & 1) != 0)
{
this.frames = data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
}
else
{
this.frames = 0;
}
if ((data[7] & 2) != 0)
{
this.size = data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
}
else
{
this.size = 0;
}
this.present = true;
}
示例6: ParseStreamList
public static AviStream ParseStreamList(ByteVector data)
{
int num2;
if (data == null)
{
throw new ArgumentNullException("data");
}
if (!data.StartsWith("strl"))
{
return null;
}
AviStream stream = null;
for (int i = 4; (i + 8) < data.Count; i += num2 + 8)
{
ByteVector id = data.Mid(i, 4);
num2 = (int) data.Mid(i + 4, 4).ToUInt(false);
if ((id == "strh") && (stream == null))
{
AviStreamHeader header = new AviStreamHeader(data, i + 8);
if (header.Type == "vids")
{
stream = new AviVideoStream(header);
}
else if (header.Type == "auds")
{
stream = new AviAudioStream(header);
}
}
else if (stream != null)
{
stream.ParseItem(id, data, i + 8, num2);
}
}
return stream;
}
示例7: Footer
public Footer (ByteVector data)
{
if (data.Count < Size)
throw new CorruptFileException ("Provided data is smaller than object size.");
if (!data.StartsWith (FileIdentifier))
throw new CorruptFileException ("Provided data does not start with File Identifier");
major_version = data [3];
revision_number = data [4];
flags = (HeaderFlags) data [5];
if (major_version == 2 && (flags & (HeaderFlags) 127) != 0)
throw new CorruptFileException ("Invalid flags set on version 2 tag.");
if (major_version == 3 && (flags & (HeaderFlags) 15) != 0)
throw new CorruptFileException ("Invalid flags set on version 3 tag.");
if (major_version == 4 && (flags & (HeaderFlags) 7) != 0)
throw new CorruptFileException ("Invalid flags set on version 4 tag.");
ByteVector size_data = data.Mid (6, 4);
foreach (byte b in size_data)
if (b >= 128)
throw new CorruptFileException ("One of the bytes in the header was greater than the allowed 128.");
tag_size = SynchData.ToUInt (size_data);
}
示例8: Tag
public Tag(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (data.Count < 0x80L)
{
throw new CorruptFileException("ID3v1 data is less than 128 bytes long.");
}
if (!data.StartsWith(FileIdentifier))
{
throw new CorruptFileException("ID3v1 data does not start with identifier.");
}
this.Parse(data);
}
示例9: VBRIHeader
public VBRIHeader(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (!data.StartsWith(FileIdentifier))
{
throw new CorruptFileException("Not a valid VBRI header");
}
int startIndex = 10;
this.size = data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.frames = data.Mid(startIndex, 4).ToUInt();
startIndex += 4;
this.present = true;
}
示例10: Footer
public Footer(ByteVector data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
if (data.Count < 10L)
{
throw new CorruptFileException("Provided data is smaller than object size.");
}
if (!data.StartsWith(FileIdentifier))
{
throw new CorruptFileException("Provided data does not start with the file identifier");
}
this.major_version = data[3];
this.revision_number = data[4];
this.flags = (HeaderFlags) data[5];
if ((this.major_version == 2) && ((((int) this.flags) & 0x7f) != 0))
{
throw new CorruptFileException("Invalid flags set on version 2 tag.");
}
if ((this.major_version == 3) && ((((int) this.flags) & 15) != 0))
{
throw new CorruptFileException("Invalid flags set on version 3 tag.");
}
if ((this.major_version == 4) && ((((int) this.flags) & 7) != 0))
{
throw new CorruptFileException("Invalid flags set on version 4 tag.");
}
for (int i = 6; i < 10; i++)
{
if (data[i] >= 0x80)
{
throw new CorruptFileException("One of the bytes in the header was greater than the allowed 128.");
}
}
this.tag_size = SynchData.ToUInt(data.Mid(6, 4));
}
示例11: StreamHeader
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="StreamHeader" /> for a specified header block and
/// stream length.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the stream
/// header data.
/// </param>
/// <param name="streamLength">
/// A <see cref="long" /> value containing the length of the
/// Monkey Audio stream in bytes.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="data" /> is <see langword="null" />.
/// </exception>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> does not begin with <see
/// cref="FileIdentifier" /> or is less than <see cref="Size"
/// /> bytes long.
/// </exception>
public StreamHeader(ByteVector data, long streamLength)
{
if (data == null)
throw new ArgumentNullException("data");
if (!data.StartsWith(FileIdentifier))
throw new CorruptFileException(
"Data does not begin with identifier.");
if (data.Count < Size)
throw new CorruptFileException(
"Insufficient data in stream header");
stream_length = streamLength;
version = data.Mid (4, 2).ToUShort(false);
compression_level = (CompressionLevel) data.Mid(52, 2)
.ToUShort(false);
// format_flags = data.Mid(54, 2).ToUShort(false);
blocks_per_frame = data.Mid(56, 4).ToUInt(false);
final_frame_blocks = data.Mid(60, 4).ToUInt(false);
total_frames = data.Mid(64, 4).ToUInt(false);
bits_per_sample = data.Mid(68, 2).ToUShort(false);
channels = data.Mid(70, 2).ToUShort(false);
sample_rate = data.Mid(72, 4).ToUInt(false);
}
示例12: StreamHeader
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="StreamHeader" /> for a specified header block and
/// stream length.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the stream
/// header data.
/// </param>
/// <param name="streamLength">
/// A <see cref="long" /> value containing the length of the
/// AIFF Audio stream in bytes.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="data" /> is <see langword="null" />.
/// </exception>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> does not begin with <see
/// cref="FileIdentifier" />
/// </exception>
public StreamHeader(ByteVector data, long streamLength)
{
if (data == null)
throw new ArgumentNullException("data");
if (!data.StartsWith(FileIdentifier))
throw new CorruptFileException(
"Data does not begin with identifier.");
stream_length = streamLength;
// The first 8 bytes contain the Common chunk identifier "COMM"
// And the size of the common chunk, which is always 18
channels = data.Mid(8, 2).ToUShort(true);
total_frames = data.Mid(10, 4).ToULong(true);
bits_per_sample = data.Mid(14, 2).ToUShort(true);
ByteVector sample_rate_indicator = data.Mid(17, 1);
ulong sample_rate_tmp = data.Mid(18, 2).ToULong(true);
sample_rate = 44100; // Set 44100 as default sample rate
// The following are combinations that iTunes 8 encodes to.
// There may be other combinations in the field, but i couldn't test them.
switch (sample_rate_tmp)
{
case 44100:
if (sample_rate_indicator == 0x0E)
{
sample_rate = 44100;
}
else if (sample_rate_indicator == 0x0D)
{
sample_rate = 22050;
}
else if (sample_rate_indicator == 0x0C)
{
sample_rate = 11025;
}
break;
case 48000:
if (sample_rate_indicator == 0x0E)
{
sample_rate = 48000;
}
else if (sample_rate_indicator == 0x0D)
{
sample_rate = 24000;
}
break;
case 64000:
if (sample_rate_indicator == 0x0D)
{
sample_rate = 32000;
}
else if (sample_rate_indicator == 0x0C)
{
sample_rate = 16000;
}
else if (sample_rate_indicator == 0x0B)
{
sample_rate = 8000;
}
break;
case 44510:
if (sample_rate_indicator == 0x0D)
{
sample_rate = 22255;
}
break;
case 44508:
if (sample_rate_indicator == 0x0C)
{
sample_rate = 11127;
}
break;
//.........这里部分代码省略.........
示例13: StreamHeader
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="StreamHeader" /> for a specified header block and
/// stream length.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the stream
/// header data.
/// </param>
/// <param name="streamLength">
/// A <see cref="long" /> value containing the length of the
/// MusePAck stream in bytes.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="data" /> is <see langword="null" />.
/// </exception>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> does not begin with <see
/// cref="FileIdentifier" /> or is less than <see cref="Size"
/// /> bytes long.
/// </exception>
public StreamHeader (ByteVector data, long streamLength)
{
if (data == null)
throw new ArgumentNullException ("data");
if (!data.StartsWith (FileIdentifier))
throw new CorruptFileException (
"Data does not begin with identifier.");
if (data.Count < Size)
throw new CorruptFileException (
"Insufficient data in stream header");
stream_length = streamLength;
version = data [3] & 15;
if (version >= 7) {
frames = data.Mid (4, 4).ToUInt (false);
uint flags = data.Mid (8, 4).ToUInt (false);
sample_rate = sftable [(int) (((flags >> 17) &
1) * 2 + ((flags >> 16) & 1))];
header_data = 0;
} else {
header_data = data.Mid (0, 4).ToUInt (false);
version = (int) ((header_data >> 11) & 0x03ff);
sample_rate = 44100;
frames = data.Mid (4,
version >= 5 ? 4 : 2).ToUInt (false);
}
}
示例14: UserCommentIFDEntry
/// <summary>
/// Construcor.
/// </summary>
/// <param name="tag">
/// A <see cref="System.UInt16"/> with the tag ID of the entry this instance
/// represents
/// </param>
/// <param name="data">
/// A <see cref="ByteVector"/> to be stored
/// </param>
public UserCommentIFDEntry (ushort tag, ByteVector data)
{
Tag = tag;
if (data.StartsWith (COMMENT_ASCII_CODE)) {
Value = data.ToString (StringType.Latin1, COMMENT_ASCII_CODE.Count, data.Count - COMMENT_ASCII_CODE.Count);
return;
}
if (data.StartsWith (COMMENT_UNICODE_CODE)) {
Value = data.ToString (StringType.UTF8, COMMENT_UNICODE_CODE.Count, data.Count - COMMENT_UNICODE_CODE.Count);
return;
}
// Some programs like e.g. CanonZoomBrowser inserts just the first 0x00-byte
// followed by 7-bytes of trash.
if (data.StartsWith ((byte) 0x00) && data.Count >= 8) {
// And CanonZoomBrowser fills some trailing bytes of the comment field
// with '\0'. So we return only the characters before the first '\0'.
int term = data.Find ("\0", 8);
if (term != -1) {
Value = data.ToString (StringType.Latin1, 8, term - 8);
} else {
Value = data.ToString (StringType.Latin1, 8, data.Count - 8);
}
return;
}
if (data.Data.Length == 0) {
Value = String.Empty;
return;
}
throw new NotImplementedException ("UserComment with other encoding than Latin1 or Unicode");
}
示例15: XingHeader
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="XingHeader" /> by reading its raw contents.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the raw
/// Xing header.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="data" /> is <see langword="null" />.
/// </exception>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> does not start with <see
/// cref="FileIdentifier" />.
/// </exception>
public XingHeader(ByteVector data)
{
if (data == null)
throw new ArgumentNullException ("data");
// Check to see if a valid Xing header is available.
if (!data.StartsWith (FileIdentifier))
throw new CorruptFileException (
"Not a valid Xing header");
int position = 8;
if ((data [7] & 0x01) != 0) {
frames = data.Mid (position, 4).ToUInt ();
position += 4;
} else
frames = 0;
if ((data [7] & 0x02) != 0) {
size = data.Mid (position, 4).ToUInt ();
position += 4;
} else
size = 0;
present = true;
}