我有一些Android应用程序的代码,它应该将大于6kb的任何消息分成块,然后再发送到服务器。
以下是执行" chunking":
的代码 //split the post data into 6k chunks
int chunkSize = 6144, chunks = size / chunkSize;
int remaining = size - (chunks * chunkSize);
android.util.Log.v("INFO-----------------------------------","chunks " + chunks+", " + remaining);
nameValuePairs = new ArrayList<NameValuePair>(0);
int offset = 0;
for(int i=0;i< chunks;i++)
{
byte[] bytes = new byte[chunkSize];
System.arraycopy(postData,offset, bytes, 0, chunkSize);
nameValuePairs.add(new BasicNameValuePair(REQUEST_PARAMETER_NAME, new String(bytes).trim()));
offset += chunkSize;
android.util.Log.v("INFO------------"+(i+1)+"------------------","-------------------" + bytes.length);
android.util.Log.v("",new String(bytes).trim());
android.util.Log.v("INFO-----------------------------------","-------------------");
}
if(remaining > 0)
{
byte[] remainingBytes = new byte[remaining];
System.arraycopy(postData,offset, remainingBytes, 0, remaining);
nameValuePairs.add(new BasicNameValuePair(REQUEST_PARAMETER_NAME, new String(remainingBytes).trim()));
android.util.Log.v("INFO-----------------------------------","-------------------");
android.util.Log.v("",new String(remainingBytes).trim());
android.util.Log.v("INFO-----------------------------------","-------------------");
}
现在由于某种原因,第一个数组bytes
总是以原始数组的所有内容结束,而不仅仅是它的一部分(bytes.length = postData.length
)。
最奇怪的部分是remainingBytes
数组恰好包含原始数组的最后剩余部分。
EDIT(logcat)很长
原创内容:
V/ ( 766):
X1MGjey46m/voRnS7eI+nNcZMqBkIbJGGFC2GpIt1ElV69U9t8MUD4jbzFyj1sfxLQJD1p4AUIsYoGejj1jDMVEwpbrXzEbmvuWDIqSulEDS0MCx69srF+wca
pJtFRCfFgU2FIfuAO58+rknTuqlh0D6lB2DA+jSWd0KXTwFS+pX3oWueokg0AyX85VHxzUICbU0FiywkE2l4W77kBpKbZ2QUnIwHZFWkivAOiUy4Gq+qkduwQtrJsIwsOIyMYJJYMnEO
Ayfb0pJrjfe2smQt0tgZNNFSmVlR2euzoE5YlyDQ8Ut0o+UULrC9switwNmUcorBDa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uJcobjqA48wtshYf82c14ThPT9Ej5ETyMRwZDjTgrUFcnTCPdWYnKyQPlx/oDOWAszeag6dw
EcgG0LuT6MfFU+qqchdOqJn807KT/Vqummn0oVRZIhn2hKsy2PJECv2l6vz45th5SR9MhR3l/+DtO5j/y1mdX4lNpibBkzfj+3BYp5HaLbYb6v3QeOpqPjadSS8HPsaklKq+qgMBp+9x
T6hlS2tS537lL1peDrD4IIKZmiQOrNbpTdAJ2uIQuIRQo51ruI+8/I1mbC9zTkpAfHE4QUSSyqoN7vNcqIKtIEDfQdjMu5fZG5PJkdoACE3z2a5VPwMV2sNQNnUpLh8bWYlxd5Sq73ea
n8ioKH9Wh2Kssap3+lb5vVtMzXR/1rGSsRFktw0SWRDjwSCkXi6EZoMrmQ9UCnPSUbkhQo3KYwrEJ5QvjazIpFRhrxO9gR9bo2c35iXAkER7Md3xYi8vstTdAQPQjgQEhl/JQbaoXCsV
Xwe6S/mZ3WJFVYh/O/hpdBoe8mlS9bwh
V/INFO-----------------------------------( 766): -------------------
第一块:
V/INFO------------1------------------( 766): -------------------
V/ ( 766): X1MGjey46m/voRnS7eI+nNcZMqBkIbJGGFC2GpIt1ElV69U9t8MUD4jbzFyj1sfxLQJD1p4AUIsYoGejj1jDMVEwpbrXzEbmvuWDIqSulEDS0MCx69srF+wca
pJtFRCfFgU2FIfuAO58+rknTuqlh0D6lB2DA+jSWd0KXTwFS+pX3oWueokg0AyX85VHxzUICbU0FiywkE2l4W77kBpKbZ2QUnIwHZFWkivAOiUy4Gq+qkduwQtrJsIwsOIyMYJJYMnEO
Ayfb0pJrjfe2smQt0tgZNNFSmVlR2euzoE5YlyDQ8Ut0o+UULrC9switwNmUcorBDa4ubWpGkmcImQ++lNLsrK+/B/gtF1uAnpDHRc8nybtp/4Mhdx5pw4iDHkHlDuVEW0GP3QyO1fjC
474RHXMcV99tbxYeC2Go+aPHpksx6wnlp+UqPeQcMqJc1GUVnhx8nTAB45g/fJf7WL0qmwPKxhWm87EzqACoQKI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j+3BYp5HaLbYb6v3QeOpqPjadSS8HPsaklKq+qgMBp+9x
T6hlS2tS537lL1peDrD4IIKZmiQOrNbpTdAJ2uIQuIRQo51ruI+8/I1mbC9zTkpAfHE4QUSSyqoN7vNcqIKtIEDfQdjMu5fZG5PJkdoACE3z2a5VPwMV2sNQNnUpLh8bWYlxd5Sq73ea
n8ioKH9Wh2Kssap3+lb5vVtMzXR/1rGSsRFktw0SWRDjwSCkXi6EZoMrmQ9UCnPSUbkhQo3KYwrEJ5QvjazIpFRhrxO9gR9bo2c35iXAkER7Md3xYi8vstTdAQPQjgQEhl/JQbaoXCsV
Xwe6S/mZ3WJFVYh/O/hpdBoe8mlS9bwh
V/INFO-----------------------------------( 766): -------------------
上一个剩余的块:
V/INFO-----------------------------------( 766): -------------------
V/ ( 766): EeQstUMzrB+jgIuFI2w9TgOAdSu9LAyBBJ7BgRuMP/EyzqP2x8pQMTiCaMKZZf7UuKmp18ud/2R/wdQ4MI9CfgTrtDlmiqmQ5MthJh/e8ozf9UZJKZdpVXEQI
6BxUCaJQzHnwWUxuTBo9P1zBGojJ7T6oc1IquYz0R6Z4qPfmL0v7n8OyskDOWzAFXYiGCrc9WvmY6vleyNGCA+Ivf8Xh7G5czUIQjsQBUdcqCWXq1hgCIts5KQHwGG0UDCTZxf4cZxxK
K7N2awkTAeev82lw0ZfSqKUnZWJGdEK9Nip7NEL5eQy3wxvQVvVuChwX0/u4k9DJbaVwLusrt9G4GRNQzOdw179rWUCyLWcV0HPqTWhzdI69Ur8evmaKB9SGcjBevFlx3SZ7kQK2+8UA
B83YL4QXef734tIiUYomQ+k6CYgaWF+cjG/+Vv3r+x0IynVd9QI0nHxJVTZfCtAF6I7xAdlYzra3ej0eYvULOKhMd4mFdhmjKYVpMqpscG9Yo1PW0mSdZRAAHK3TXE9Xwwb4QflFnSzm
yiJ3D4gJe+fduR0sFtuij7i7fhHmU7GAr8QtAS4dkZcVkjnvnURVx5ko1c2lz+HNFT6CjuNoFNhcEyLMmY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