zoukankan      html  css  js  c++  java
  • TRawByteStringStream

    TRawByteStringStream

      TRawByteStringStream = class(TStream)
      protected
        fDataString: RawByteString;
        fPosition: Integer;
        procedure SetSize(NewSize: Longint); override;
      public
        constructor Create(const aString: RawByteString = ''); overload;
        function Read(var Buffer; Count: Longint): Longint; override;
        function Seek(Offset: Longint; Origin: Word): Longint; override;
        function Write(const Buffer; Count: Longint): Longint; override;
        property DataString: RawByteString read fDataString write fDataString;
      end;
    { TRawByteStringStream }
    
    constructor TRawByteStringStream.Create(const aString: RawByteString);
    begin
      fDataString := aString;
    end;
    
    function TRawByteStringStream.Read(var Buffer; Count: Integer): Longint;
    begin
      if Count <= 0 then
        Result := 0
      else
      begin
        Result := Length(fDataString) - fPosition;
        if Result > Count then
          Result := Count;
        Move(PByteArray(fDataString)[fPosition], Buffer, Result);
        inc(fPosition, Result);
      end;
    end;
    
    function TRawByteStringStream.Seek(Offset: Integer; Origin: Word): Longint;
    begin
      case Origin of
        soFromBeginning:
          fPosition := Offset;
        soFromCurrent:
          fPosition := fPosition + Offset;
        soFromEnd:
          fPosition := Length(fDataString) - Offset;
      end;
      if fPosition > Length(fDataString) then
        fPosition := Length(fDataString)
      else if fPosition < 0 then
        fPosition := 0;
      result := fPosition;
    end;
    
    procedure TRawByteStringStream.SetSize(NewSize: Integer);
    begin
      SetLength(fDataString, NewSize);
      if fPosition > NewSize then
        fPosition := NewSize;
    end;
    
    function TRawByteStringStream.Write(const Buffer; Count: Integer): Longint;
    begin
      if Count <= 0 then
        Result := 0
      else
      begin
        Result := Count;
        SetLength(fDataString, fPosition + Result);
        Move(Buffer, PByteArray(fDataString)[fPosition], Result);
        inc(FPosition, Result);
      end;
    end;
    

      

  • 相关阅读:
    C#中调用DTS
    经典问题:向setTimeout传递函数参数
    C#.NET 中的类型转换
    SQL语句导入导出大全 (转载)
    js脚本defer的作用
    [转]使用 Java API 处理 WebSphere MQ 大消息
    WideCharToMultiByte 宽字节转换为多字节
    [原].NET数据库开发中请注意区域时间格式
    输出页眉和页脚的简单HTTP模块实践
    浅析ASP.NET HTTP Module
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/13733625.html
Copyright © 2011-2022 走看看