unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    IdTCPClient1: TIdTCPClient;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function sendbytes(b: string; L: integer): longInt;
  end;

var
  Form1: TForm1;

implementation

function HexToInt(Str1: string): longInt;
var i: integer;
begin
  Result := 0;
  for i := 1 to length(Str1) do
  begin
    if (Str1[i] >= '0') and (Str1[i] <= '9') then
      Result := Result * 16 + StrToInt(Str1[i])
    else
    begin
      if (Str1[i] >= 'A') and (Str1[i] <= 'F') then
        result := Result * 16 + ord(Str1[i]) - 55
      else
      begin
        result := 0;
        exit;
      end;
    end;
  end;
end;

function FileToString(mFileName: TFileName): string;
var
  I: Integer;
  mStream: tfilestream;
  bb: byte;
begin
  mStream := tfilestream.Create(mFileName, fmOpenRead);
  Result := '';
  if not Assigned(mStream) then Exit;
//SetLength(Result,   mStream.Size);
  for I := 0 to Pred(mStream.Size) do try
    mStream.Position := I;

    mStream.Read(bb, 1);
    Result := Result + inttohex(bb, 2);

  except
    Result := '';
  end;
  mStream.Destroy;
end; {   StreamToString   }

function StringToFile(mString: string; mFileName: TFileName): Boolean;
  {   返回字符串保存到文件是否成功   }
var
  I, j: Integer;
  mStream: tfilestream;
  bb: byte;
  ss: string;
begin
  Result := True;
  mStream := tfilestream.Create(mFileName, fmCreate);
  try
    mStream.Size := 0;
    mStream.Position := 0;
    j := 0;
    for I := 1 to Length(mString) do
    begin
      ss := ss + mString[I];
      j := j + 1;
      if j = 2 then
      begin
        j := j div 2;
        bb := hextoint(ss);
        mStream.Write(bb, j);
        j := 0;
        ss := ''; //加此则很快了。
      end;
    end;
    if j > 0 then
    begin
      j := j div 2;
      bb := hextoint(ss);
      mStream.Write(bb, j);

    end;
  except
    Result := False;

  end;
  mStream.Destroy;
end; {   StringToStream   }
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  UpLoadFile: TFileStream;
  oldid, newid, keywww: string;
  B0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10: string;
  i, j: integer;
  ss, b: string;
begin
  oldid := 'ID:WWW-5DAA99645BA-3700-1494653738046-';
  newid := 'ID_WWW-5DAA99645BA-4047-1494657860484-';
  UpLoadFile := TFileStream.Create('c:\www.jpg', fmOpenRead);
 
//UpLoadFile:=TFileStream.Create('E:\软件大全\Dreamweaver_CS6.zip',fmOpenRead);
 // DownLoadFile:=TFileStream.Create(LocalPath+'\lm.gif',fmCreate);
  try
  
//idHttp1.Put('http://192.168.2.227:8161/fileserver/'+newid+'1:1:1:1:1',UpLoadFile);
    idHttp1.Put('http://localhost:8161/fileserver/' + oldid + '1:1:1:1:1',
UpLoadFile);
  except
    showMessage('上传失败');
    exit;
  end;
  showMessage('上传成功');
  ///////////////////
  keywww := newid;
  //下面尚未替换子串的。
  B0 := '0000018A014163746976654D510000000C01000001780000000' +
'D0009436163686553697A650500000400000C4D61784672616D6553697A65067FFFFFFFFFFFFFFF000C4361636865456E61626C656401010004486F737409000D3139322E3136382E322E323237000C50726F76696465724E616D650900084163746976654D51001253697A6550726566697844697361626C656401000020'
+
'4D6178496E61637469766974794475726174696F6E496E6974616C44656C617906000000000000271000145469676874456E636F64696E67456E61'
+
'626C656401010011537461636B5472616365456E61626C65640101000F50726F766964657256657273696F6E0000115463704E6F44656C6179456E61626C65640101000F506C6174666F726D44657461696C730900454A564D3A20312E372E305F30312'
+
'C2032312E312D6230322C204F7261636C6520436F72706F726174696F6E2C204F533A2057696E646F77732058502C20352E312C2078383600154D6178496E61637469766974794475726174696F6E06000000000000753000';
  B1 := '0000006103027F1800000001000078002949443A5757572D354441' +
'41393936343542412D333730302D313439343635333733383034362D313A31002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D303A3132'
+ '                                                                             
                                                                                
                                 
' + '                                                                           
                                                                                
                             
';
  B2 := '0000008705047F7D04000000000200017A002949443A5757572D354' +
'44141393936343542412D333730302D313439343635333733383034362D313A31FFFFFFFFFFFFFFFF000100026500374163746976654D512E41647669736F72792E54656D7051756575652C4163746976654D512E41647669736F72792E54656D70546F706963000003E8000000000078'
+ '                                                                             
                                           
' + '                                                                           
                                                                     
' + '                                                                           
                                  
';
  B3 := '0000003704015E00000003000379002949443A5757572D35444141393' +
'936343542412D333730302D313439343635333733383034362D313A31000131' + '           
                                                                                
                                                                
' + '                                                                           
                                                                                
                                                                
';
  B4 := '0000005106025F1F0000000400047B002949443A5757572D3544414139' +
'3936343542412D333730302D313439343635333733383034362D313A3100010001000564000E46696C652E5472616E73706F72740000000064'
+ '                                                                             
                               
' + '                                                                           
                                                                                
            
' + '                                                                           
                       
';
  B5 := '000000CF1D0648043001001F0000000500040005000600066E00040001' +
'000600000000040000015C004E1FF80000002D00000002000946494C452E53495A450600000000000122F8000946494C452E4E414D450900077777772E6A70670006000000000054687474703A2F2F3139322E3136382E322E3232373A383136312F66696C657365727665722F49443A5757572D354441413939363435'
+
'42412D333730302D313439343635333733383034362D313A313A313A313A3100186170706C69636174696F6E2F6F637465742D73747265616D62';
  B6 := '000000110C010C000000060004FFFFFFFFFFFFFFFE06';
  B7 := '000000110C010C000000070003FFFFFFFFFFFFFFFE06';
  B8 := '000000110C010C000000080001FFFFFFFFFFFFFFFE06';
  B9 := '000000110C010D000000090000FFFFFFFFFFFFFFFF06';
  B10 := '000000070B01000000000A00';






  self.IdTCPClient1.Host := 'localhost';
           //self.IdTCPClient1.Host:='192.168.2.227';
  IdTCPClient1.Port := 61616;
  IdTCPClient1.Connect();
           //int[]  BBB={398,101,139,59,85,211,21,21,21,21,11};
  try
    sendbytes(b0, 398);
    sendbytes(b1, 101);
    sendbytes(b2, 139);
    sendbytes(b3, 59);
    sendbytes(b4, 85);
    sendbytes(b5, 211);
    sendbytes(b6, 21);
    sendbytes(b7, 21);
    sendbytes(b8, 21);
    sendbytes(b9, 21);
    sendbytes(b10, 11);
    showmessage('send blob');
  except
    IdTCPClient1.Disconnect;
  end;


  IdTCPClient1.Disconnect;
end;
function IntToByte(Value: Integer): Byte; overload;
asm 
       OR     EAX, EAX 
       JNS    @@Positive 
       XOR    EAX, EAX 
       RET

@@Positive: 
       CMP    EAX, 255 
       JBE    @@OK 
       MOV    EAX, 255 
@@OK: 
end;
function TForm1.sendbytes(b: string; L: integer): longInt;
var
  i, j, hh: integer;
  ss, jj: string;
  www: tstringlist;
  buf:array[0..4096] of byte;
begin
  ss := ''; jj := ''; www := tstringlist.Create;
  j := 0;
  IdTCPClient1.SendBufferSize:=L;
  for i := 1 to length(b) do
  begin
    if i > L*2 then
    begin
      break;
    end;
    j := j + 1;
    ss := ss + b[i];
    if j = 2 then
    begin
      hh := hextoint(ss);
      //jj := jj + char(hh);
       //IdTCPClient1.WriteInteger(hh);
       buf[(i div 2)-1]:=IntToByte(hh);
      j := 0;
      ss := '';
    end;

  end;
   IdTCPClient1.WriteBuffer(buf,L);
           //showmessage(jj);
  //self.Memo1.Lines.Add(jj);
  for I := 0 to L-1 do

    jj := jj + inttohex(buf[i], 2);

  www.Text := jj;
  www.SaveToFile('c:\'+inttostr(L)+'.txt');
  www.Free;
end;


end.




--
View this message in context: 
http://activemq.2283324.n4.nabble.com/BlobMessage-in-ActiveMQ-CPP-by-now-2017-tp4726457p4726459.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to