zoukankan      html  css  js  c++  java
  • 合并(分割)流

    合并(分割)流

    /// <author>cxg 2020-3-15</author>
    unit uStream;
     
    interface
     
    uses
      SysUtils, Classes;
     
    type
      TStreamArray = array of TStream;
     
    type
      TynStream = class
      private
        { Private declarations }
      public
        { Public declarations }
        class procedure MergeStream(ms: TStream; mss: TStreamArray);
        class procedure SplitStream(ms: TStream; mss: TStreamArray);
      end;
     
    var
      ynStream: TynStream;
     
    implementation
     
    class procedure TynStream.MergeStream(ms: TStream; mss: TStreamArray);
    var
      LSize: Int64;
      lnum: Integer;
      i: Integer;
    begin
      ms.Position := 0;
      lnum := High(mss);
      ms.Write(LNum, SizeOf(Integer));  //有几个流
      for i := 0 to LNum - 1 do
      begin
        LSize := mss[i].Size;
        ms.Write(LSize, SizeOf(Int64));   // 流的大小
        ms.CopyFrom(mss[i], LSize);
      end;
    end;
     
    class procedure TynStream.SplitStream(ms: TStream; mss: TStreamArray);
    var
      i: Integer;
      LSize: Int64;
      LNum: Integer;
    begin
      ms.Position := 0;
      ms.Read(LNum, SizeOf(Integer)); //有几个流
      SetLength(mss, LNum);
      for i := 0 to LNum - 1 do
      begin
        ms.Read(LSize, SizeOf(Int64));   //流的大小
        mss[i] := TMemoryStream.Create;
        mss[i].CopyFrom(ms, LSize);
      end;
    end;
     
    end.

      

  • 相关阅读:
    Generate Parentheses
    Length of Last Word
    Maximum Subarray
    Count and Say
    二分搜索算法
    Search Insert Position
    Implement strStr()
    Remove Element
    Remove Duplicates from Sorted Array
    Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/11799255.html
Copyright © 2011-2022 走看看