public static ByteVectorCollection Split(ByteVector vector, ByteVector pattern, int alignment, int maximum) { if (vector != null) { if (pattern != null) { ByteVectorCollection list = new ByteVectorCollection(); int previousOffset = 0; for (int offset = vector.Find(pattern, 0, alignment); offset != -1 && (maximum == 0 || maximum > list.Count + 1); offset = vector.Find(pattern, offset + pattern.Count, alignment)) { list.Add(vector.Mid(previousOffset, offset - previousOffset)); previousOffset = offset + pattern.Count; } if (previousOffset < vector.Count) { list.Add(vector.Mid(previousOffset, vector.Count - previousOffset)); } return(list); } else { throw new ArgumentNullException("pattern"); } } else { throw new ArgumentNullException("vector"); } }
// Set the data with the given box type, strings, and flags. public void SetText(ByteVector type, string[] text) { // Remove empty data and return. if (text == null) { listBox.RemoveChildren(FixId(type)); return; } // Create a text... ByteVectorCollection data = new ByteVectorCollection(); // and populate it with the ByteVectorized strings. foreach (string value in text) { data.Add(ByteVector.FromString(value, StringType.UTF8)); } // Send our final byte vectors to SetData SetData(type, data, (uint)Mpeg4ContentType.ContainsText); }
private void WritePageGroup(IntCollection page_group) { if (page_group.IsEmpty) { return; } ByteVectorCollection packets = new ByteVectorCollection(); // If the first page of the group isn'type dirty, append its partial content here. if (!dirtyPages.Contains(((OggPage)this.pages[page_group[0]]).FirstPacketIndex)) { packets.Add(((OggPage)this.pages[page_group[0]]).Packets[0]); } int previous_packet = -1; int original_size = 0; for (int i = 0; i < page_group.Count; i++) { int page = page_group[i]; uint first_packet = (uint)((OggPage)this.pages[page]).FirstPacketIndex; uint last_packet = first_packet + ((OggPage)this.pages[page]).PacketCount - 1; for (uint j = first_packet; j <= last_packet; j++) { if (i == page_group.Count - 1 && j == last_packet && !dirtyPages.Contains((int)j)) { packets.Add(((OggPage)this.pages[page]).Packets[((OggPage)this.pages[page]).Packets.Count - 1]); } else if ((int)j != previous_packet) { previous_packet = (int)j; packets.Add(GetPacket(j)); } } original_size += ((OggPage)this.pages[page]).Size; } bool continued = ((OggPage)this.pages[page_group[0]]).Header.FirstPacketContinued; bool completed = ((OggPage)this.pages[page_group[page_group.Count - 1]]).Header.LastPacketCompleted; // TODO: This pagination method isn'type accurate for what'field being done here. // This should account for real possibilities like non-aligned packets and such. OggPage[] pages = OggPage.Paginate(packets, PaginationStrategy.SinglePagePerGroup, streamSerialNumber, page_group[0], continued, completed); ByteVector data = new ByteVector(); foreach (OggPage p in pages) { data.Add(p.Render()); } // The insertion algorithms could also be improve to queue and prioritize data // on the way out. Currently it requires rewriting the file for every page // group rather than just once; however, for tagging applications there will // generally only be one page group, so it'field not worth the time for the // optimization at the moment. Insert(data, ((OggPage)this.pages[page_group[0]]).FileOffset, original_size); // Update the page index to include the pages we just created and to delete the // old pages. foreach (OggPage p in pages) { int index = p.Header.PageSequenceNumber; this.pages[index] = p; } }