Monday, April 14, 2014

Help, I smack + openfire conducted Andrews instant communication development, when you send the picture out of the question


Is to send a picture when the link is disconnected from the server, and the message will be sent to fail. 09-22 10:20:24.071: I / System.out (10456): 10:20:24 AM RCV (1079209600):

I want to know, is because of it, or the problem of the server code itself it, I put pictures into bytecode, then put convert bytecode into hexadecimal, and then sent out as a message. This has the problem?
Send:
String msg = MyApplication.encode (MyApplication.Bitmap2Bytes (bmp));
Message mes = new Message ();
mes.setBody (msg);
newchat.sendMessage (mes);
Receive: Bitmap bm = MyApplication.Bytes2Bimap (MyApplication
. Decode (body));
body = "/ mnt / sdcard / imags" + TimeRender.getDatejpg () + "jpg.";
File f = new File (body);
BufferedOutputStream bos;
try {
bos = new BufferedOutputStream (
new FileOutputStream (f));
bm.compress (Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush ();
bos.close ();
} Catch (FileNotFoundException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

Conversion method:
/ *
* String encoded as hexadecimal numbers, for all the characters (including Chinese)
* /
public static String encode (byte [] bytes) {
/ / Get the byte array based on the default encoding
/ / Byte [] bytes = str.getBytes ();
StringBuilder sb = new StringBuilder (bytes.length * 2);
/ / The byte array is broken down into two each byte hexadecimal integer
for (int i = 0; i sb.append (hexString.charAt ((bytes [i] & 0xf0) >> 4));
sb.append (hexString.charAt ((bytes [i] & 0x0f) >> 0));
}
return sb.toString ();
}

/ *
* The decoded into a string of hexadecimal digits for all characters (including Chinese)
* /
public static byte [] decode (String bytes) {
ByteArrayOutputStream baos = new ByteArrayOutputStream (
bytes.length () / 2);
/ / Will assemble every two hexadecimal integer into a byte
for (int i = 0; i baos.write ((hexString.indexOf (bytes.charAt (i)) << 4 | hexString
. IndexOf (bytes.charAt (i + 1))));
return baos.toByteArray ();
}
/ / The picture into a byte
public static byte [] Bitmap2Bytes (Bitmap bm) {
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
bm.compress (Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray ();
}
/ / Byte into the picture
public static Bitmap Bytes2Bimap (byte [] b) {
if (b.length! = 0) {
return BitmapFactory.decodeByteArray (b, 0, b.length);
}
else {
return null;
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
See server logs, that is the internal server error

No comments:

Post a Comment