【发布时间】:2014-05-28 13:45:23
【问题描述】:
我正在使用multipartentity 分块上传视频,上传我正在从文件中读取数据。在第一个循环中,我能够读取数据,但在下一个循环中,它得到了ArrayIndexOutOfBoundsException
例外:
> java.lang.ArrayIndexOutOfBoundsException: length=1024;
> regionStart=1024; regionLength=1024
I am reading 1024 bytes in every loop.
totalSize = 441396
offset starts from 0
chunkSize = 1024
我的代码:
do {
currentChunkSize = totalSize - offset > chunkSize ? chunkSize : totalSize - offset;
String urlString = "http://capmem.omsoftware.co/Event/UploadVideo?" +
"callback=localJsonpCallback&" +
"filename="+ filename +"&" +
"ext="+ exten +"&" +
"totalsize="+ size +"&" +
"EventID="+ eventid +"&" +
"UserID="+ userid +"&" +
"comment="+ coment +"&" +
"VideoLength="+ videolength +
"&chunk=" + currentChunkSize;
httppost1 = new HttpPost(urlString);
byte[] currentBytes = new byte[currentChunkSize];
buf = new BufferedInputStream(new FileInputStream(file));
buf.read(currentBytes, offset, currentChunkSize);
offset += currentChunkSize;
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videofile", new ByteArrayBody(currentBytes, "application/octet-stream", filename));
httppost1.setEntity(reqEntity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httppost1);
int resCode = response.getStatusLine().getStatusCode();
} while(totalSize != offset);
获取异常
buf.read(currentBytes, offset, currentChunkSize);
【问题讨论】:
标签: android bytearray indexoutofboundsexception bufferedinputstream