activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e271828 <165442...@qq.com>
Subject Re: BlobMessage in ActiveMQ-CPP by now 2017
Date Wed, 24 May 2017 02:14:55 GMT
I can do as follow,and change the java to delphi and C++,but my manager do
not agree do that.
=============================================
package com.blob.activemq;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;

/*
 * 客户端
 */
public class SoBlob {
	public static String keywww;
    public static void main(String[] args) {
    	
    	String oldid="ID:WWW-5DAA99645BA-3700-1494653738046-";
    	String newid="ID_WWW-5DAA99645BA-4047-1494657860484-";
    	URL url = null;//createMessageURL(message);
    	  try {
		
//http://192.168.2.227:8161/fileserver/ID:WWW-5DAA99645BA-4345-1494661885140-1:1:1:1:1
		//url=new URL("http://192.168.2.227:8161/fileserver/"+newid+"1:1:1:1:1");
		url=new URL("http://localhost:8161/fileserver/"+newid+"1:1:1:1:1");
    	  } catch (MalformedURLException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
    	File file = new File("c:\\www.jpg");
    	FileInputStream fis = null;
    	HttpURLConnection connection = null;
		try {
			fis = new FileInputStream(file);
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}		
    	//InputStream fis=new inputstream(file);
         try {
			connection = (HttpURLConnection)url.openConnection();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
			try {
				connection.setRequestMethod("PUT");
			} catch (ProtocolException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

        connection.setDoOutput(true);


        // use chunked mode or otherwise URLConnection loads everything into
        // memory
        // (chunked mode not supported before JRE 1.5)
       
//connection.setChunkedStreamingMode(transferPolicy.getBufferSize());
        connection.setChunkedStreamingMode((int) file.length());
        try(OutputStream oss = connection.getOutputStream()) {
            byte[] buf =new byte[(int) file.length()];//new
byte[transferPolicy.getBufferSize()];
            for (int c = fis.read(buf); c != -1; c = fis.read(buf)) {
                oss.write(buf, 0, c);
                oss.flush();
            }
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	///////////////////////////////////////////////////////////
        try {
            //1.创建客户端Socket,指定服务器地址和端口
            //Socket socket=new Socket("192.168.2.227", 61616);
            Socket socket=new Socket("localhost", 61616);
            //2.获取输出流,向服务器端发送信息
            OutputStream os=socket.getOutputStream();//字节输出流
            //PrintWriter pw=new PrintWriter(os);//将输出流包装为打印流
            //pw.write("用户名:whf;密码:789");
            //pw.flush();

        	//os.write(buffer99, 0, buffer99.length);
        	//os.flush();

            So.keywww=newid;
            int[]  BBB={398,101,139,59,85,211,21,21,21,21,11};
            ///*
            String
B0="0000018A014163746976654D510000000C01000001780000000D0009436163686553697A650500000400000C4D61784672616D6553697A65067FFFFFFFFFFFFFFF000C4361636865456E61626C656401010004486F737409000D3139322E3136382E322E323237000C50726F76696465724E616D650900084163746976654D51001253697A6550726566697844697361626C6564010000204D6178496E61637469766974794475726174696F6E496E6974616C44656C617906000000000000271000145469676874456E636F64696E67456E61626C656401010011537461636B5472616365456E61626C65640101000F50726F766964657256657273696F6E0000115463704E6F44656C6179456E61626C65640101000F506C6174666F726D44657461696C730900454A564D3A20312E372E305F30312C2032312E312D6230322C204F7261636C6520436F72706F726174696F6E2C204F533A2057696E646F77732058502C20352E312C2078383600154D6178496E61637469766974794475726174696F6E06000000000000753000";
        	String
B1="0000006103027F1800000001000078002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D313A31002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D303A3132
                                                                                         
                                                                                         
                                                                                         
                                                                                         
              
";
        	String
B2="0000008705047F7D04000000000200017A002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D313A31FFFFFFFFFFFFFFFF000100026500374163746976654D512E41647669736F72792E54656D7051756575652C4163746976654D512E41647669736F72792E54656D70546F706963000003E8000000000078
                                                                                         
                                                                                         
                                                                                         
                                                                                         
              
";
        	String
B3="0000003704015E00000003000379002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D313A31000131
                                                                                         
                                                                                         
                                                                                         
                                                                                         
              
";
        	String
B4="0000005106025F1F0000000400047B002949443A5757572D35444141393936343542412D333730302D313439343635333733383034362D313A3100010001000564000E46696C652E5472616E73706F72740000000064
                                                                                         
                                                                                         
                                                                                         
                                                                                         
              
";
        	String
B5="000000CF1D0648043001001F0000000500040005000600066E00040001000600000000040000015C004E1FF80000002D00000002000946494C452E53495A450600000000000122F8000946494C452E4E414D450900077777772E6A70670006000000000054687474703A2F2F3139322E3136382E322E3232373A383136312F66696C657365727665722F49443A5757572D35444141393936343542412D333730302D313439343635333733383034362D313A313A313A313A3100186170706C69636174696F6E2F6F637465742D73747265616D62";
        	String B6="000000110C010C000000060004FFFFFFFFFFFFFFFE06";
        	String B7="000000110C010C000000070003FFFFFFFFFFFFFFFE06";
        	String B8="000000110C010C000000080001FFFFFFFFFFFFFFFE06";
        	String B9="000000110C010D000000090000FFFFFFFFFFFFFFFF06";
        	String B10="000000070B01000000000A00";
           // */
        	//So.keywww="ID:WWW-5DAA99645BA-2748-1494638863984-";
        	 So.keywww=bytes2HexString(So.keywww.getBytes());       	
        	System.out.println("B0");
        	printchar(hexStringToBytes(B0));
        	byte[] buffer=hexStringToBytes(B0);
        	os.write(buffer, 0, BBB[0]);
        	os.flush();
        	/*
还有参数的替换问题。
文件名可替换,但文件名长度不能变。是不是队列名一样长度不能变?
且可能只能是英文名,不可中文名?
文件大小的数值或可以不理,如果理,是不是数值的长度也不能变化?
这些小事想起来也会烦人的。
        	*/
        	System.out.println("B1");
        	
        	printchar(hexStringToBytes(B1));
        	byte[] wwwbb1=oldid.getBytes();
        	String wwwb1=bytes2HexString(wwwbb1);
        	B1=B1.replaceAll(wwwb1, So.keywww);
        	
        	byte[] buffer1=hexStringToBytes(B1);
        	printchar((buffer1));
        	os.write(buffer1, 0, BBB[1]);
        	os.flush();
        	
        	System.out.println("B2");
        	printchar(hexStringToBytes(B2));

        	B2=B2.replaceAll(wwwb1, So.keywww);
        	byte[] buffer2=hexStringToBytes(B2);
        	printchar((buffer2));
        	os.write(buffer2, 0, BBB[2]);
        	os.flush();
        	try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	
        	System.out.println("B3");
        	printchar(hexStringToBytes(B3));

        	B3=B3.replaceAll(wwwb1, So.keywww);
        	byte[] buffer3=hexStringToBytes(B3);
        	printchar((buffer3));
        	os.write(buffer3, 0, BBB[3]);
        	os.flush();
        	
        	System.out.println("B4");
        	printchar(hexStringToBytes(B4));

       	B4=B4.replaceAll(wwwb1, So.keywww);
        	byte[] buffer4=hexStringToBytes(B4);
        	printchar((buffer4));
        	os.write(buffer4, 0, BBB[4]);
        	os.flush();
        	
        	
        	System.out.println("B5");
        	printchar(hexStringToBytes(B5));
        	B5=B5.replaceAll(wwwb1, So.keywww);
        	B5=B5.replaceAll(bytes2HexString("www.jpg".getBytes()),
bytes2HexString("qqq.jpg".getBytes()));
        	printchar(hexStringToBytes(B5));
        	byte[] buffer5=hexStringToBytes(B5);
        	os.write(buffer5, 0, BBB[5]);
        	os.flush();
        	System.out.println("B6");
        	printchar(hexStringToBytes(B6));
        	byte[] buffer6=hexStringToBytes(B6);
        	os.write(buffer6, 0, BBB[6]);
        	os.flush();
        	
        	System.out.println("B7");
        	printchar(hexStringToBytes(B7));
        	byte[] buffer7=hexStringToBytes(B7);
        	os.write(buffer7, 0, BBB[7]);
        	os.flush();
        	System.out.println("B8");
        	printchar(hexStringToBytes(B8));
        	byte[] buffer8=hexStringToBytes(B8);
        	os.write(buffer8, 0, BBB[8]);
        	os.flush();
        	System.out.println("B9");
        	printchar(hexStringToBytes(B9));
        	byte[] buffer9=hexStringToBytes(B9);
        	os.write(buffer9, 0, BBB[9]);
        	os.flush();
        	System.out.println("B10");
        	printchar(hexStringToBytes(B10));
        	byte[] buffer10=hexStringToBytes(B10);
        	os.write(buffer10, 0, BBB[10]);
        	os.flush();
        	
        	 
            socket.shutdownOutput();//关闭输出流
            
            //3.获取输入流,并读取服务器端的响应信息
            InputStream is=socket.getInputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(is));
            String info=null;
            while((info=br.readLine())!=null){
                System.out.println("我是客户端,服务器说:"+info);
            }
            //4.关闭资源
            br.close();
            is.close();
            //pw.close();
            os.close();
            socket.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static byte[] hexStringToBytes(String hexString) {
        if (hexString == null || hexString.equals("")) {
            return null;
        }
        hexString = hexString.toUpperCase();
        int length = hexString.length() / 2;
        char[] hexChars = hexString.toCharArray();
        byte[] d = new byte[length];
        for (int i = 0; i < length; i++) {
            int pos = i * 2;
            d[i] = (byte) (charToByte(hexChars[pos]) << 4 |
charToByte(hexChars[pos + 1]));
            
        }
        return d;
    }
    private static byte charToByte(char c) {
        return (byte) "0123456789ABCDEF".indexOf(c);
    }
    public static byte[] hexStringToByteArray(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        try {
            for (int i = 0; i < len; i += 2) {
                data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) <<
4)
                        + Character.digit(s.charAt(i+1), 16));
            }
        } catch (Exception e) {
            //Log.d("", "Argument(s) for hexStringToByteArray(String s)"+
"was not a hex string");
        }
        return data;
    }
    public static String bytes2HexString(byte[] b) {  
    	  String ret = "";  
    	  for (int i = 0; i < b.length; i++) {  
    	   String hex = Integer.toHexString(b[ i ] & 0xFF);  
    	   if (hex.length() == 1) {  
    	    hex = '0' + hex;  
    	   }  
    	   ret += hex.toUpperCase();  
    	  }  
    	  return ret;  
    	}
    public static void printchar(byte[] www){
    	String sss="";
    	for (int ii=0;ii<=www.length-1;ii++){
    	sss=sss+(char)www[ii];}
    	System.out.println(sss);
        }
}



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

Mime
View raw message