Has the error: BufferOverflowException when deliver file
<p>This is the code of deliverying data. I use my own packet method to send the packets. </p>

<pre><code>public void sendImage(String imgPath){
                short msg = MySelfCustom.MSG_Photo_uploading;
                File imgFile = new File(imgPath);



                byte[] buff = new byte[MySelfCustom.DATA_LEN1];
                try {
                        InputStream input = new FileInputStream(imgFile);
                        int maxHex = input.available();
                        int count = maxHex/MySelfCustom.DATA_LEN1;
                        if(maxHex%MySelfCustom.DATA_LEN1 != 0){
                                count = count + 1;
                        }

                        byte[] box_head = new byte[8];
                        box_head[0] = (byte) msg;
                        box_head[1] = 0;

                        box_head[2] = 4;
                        box_head[3] = 0;
                        //the image begin to be sent
                        box_head[4] = 0;
                        box_head[5] = 0; 
                        box_head[6] = 0;
                        box_head[7] = 0; 
//                        sendBuffer.clear();
                        sendBuffer.put(box_head);
                        sendBuffer.flip();
                        socketChannel.write(sendBuffer);
                        sendBuffer.compact();

                        int number = 0;
                        int i = 2;
                        //send image data circulate
                        while ((number = input.read(buff)) != -1) {
                                box_head[0] = (byte) msg;
                                box_head[1] = 0;

                                box_head[2] = (byte)((number + 4) &amp; 0xff);
                                box_head[3] = (byte)(((number + 4) &amp; 0xff00)&gt;&gt;8);

                                //begin to send image
                                box_head[4] = (byte)(i &amp; 0xff);
                                box_head[5] = (byte)((i &amp; 0xff00)&gt;&gt;8);
                                box_head[6] = (byte)((i &amp; 0xff0000)&gt;&gt;16);
                                box_head[7] = (byte)((i &amp; 0xff000000)&gt;&gt;24);
                                sendBuffer.clear();
                                sendBuffer.put(box_head);
                                sendBuffer.put(buff);
                                sendBuffer.flip();
                                socketChannel.write(sendBuffer);
                                sendBuffer.compact();
                                i++;
                        }
                        String file_md5 = GetMd5.getFileMD5String(imgFile).toUpperCase();
                        //send image over
                        box_head[0] = (byte) msg;
                        box_head[1] = 0;

                        box_head[2] = (byte)(GetUnicode(file_md5).length + 6);
                        box_head[3] = 0;

                        box_head[4] = 1;
                        box_head[5] = 0;
                        box_head[6] = 0;
                        box_head[7] = 0; 

                        byte[] b = new byte[2];

                        b[0] = (byte)(GetUnicode(file_md5).length);
                        b[1] = 0;
                        sendBuffer.clear();
                        sendBuffer.put(box_head);
                        sendBuffer.put(b);
                        sendBuffer.put(GetUnicode(file_md5));

                        sendBuffer.flip();
                        socketChannel.write(sendBuffer);
                        sendBuffer.compact();

                } catch (FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }

        }
</code></pre>

<p>There is no problem when I debug. The service also can accept data. But when it is executing, it will has the error like BufferOverflowException.</p>

<pre><code>01-01 08:42:22.170: W/dalvikvm(2726): threadid=1: thread exiting with uncaught exception (group=0x401ec560)
01-01 08:42:22.190: E/AndroidRuntime(2726): FATAL EXCEPTION: main
01-01 08:42:22.190: E/AndroidRuntime(2726): java.nio.BufferOverflowException
01-01 08:42:22.190: E/AndroidRuntime(2726):         at java.nio.ReadWriteHeapByteBuffer.put(ReadWriteHeapByteBuffer.java:125)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at java.nio.ByteBuffer.put(ByteBuffer.java:724)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at com.jiekong.socket.ClientSocket.sendImage(ClientSocket.java:260)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at com.jiekong.conference.Setting$1.onClick(Setting.java:72)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.view.View.performClick(View.java:2485)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.view.View$PerformClick.run(View.java:9080)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.os.Handler.handleCallback(Handler.java:587)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.os.Handler.dispatchMessage(Handler.java:92)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.os.Looper.loop(Looper.java:130)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at android.app.ActivityThread.main(ActivityThread.java:3683)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at java.lang.reflect.Method.invokeNative(Native Method)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at java.lang.reflect.Method.invoke(Method.java:507)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-01 08:42:22.190: E/AndroidRuntime(2726):         at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Has anyone met this question? Could you help me? thanks very much.</p>
