Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Boolean uploadFile(String filePath,int chunkSize,JSONObject
- jsonObj)
- {
- boolean dataUploaded=false;
- InputStream inStream=null;
- try
- {
- File zipFile = new File(filePath);
- int fileSize = (int)zipFile.length();
- inStream = new BufferedInputStream( new
- FileInputStream(filePath));
- //<b>this var changing</b>
- final int totalparts =(int) Math.ceil((double)fileSize /
- (double)chunkSize);
- Logger.i("file totalparts", totalparts + "");
- byte [] data = new byte[chunkSize];
- int index=0,checkCount=0;
- boolean readNextData=true;
- while ( true )
- {
- if(readNextData) {
- inStream.read(data, 0, chunkSize);
- checkCount=0;
- ++index;
- }
- Logger.i("chunkList index", index + "");
- Logger.i("file totalparts", totalparts + "");
- jsonObj.put("fileName", zipFile.getName());
- jsonObj.put("base64Content",
- convertToBase64EncodingFromByteArray(data));
- jsonObj.put("partNo", index);
- jsonObj.put("totalParts", totalparts);
- //jsonObj.put("md5checksum","A0A0");
- jsonObj.put("md5checksum",CheckSum.getMd5OfByteArray(data));
- String responseData = sendData(jsonObj.toString());
- Logger.v("responseData",responseData);
- JSONObject responData=new JSONObject(responseData);
- String errorCode=(String) responData.get("ErrorCode");
- if(!errorCode.equals("0"))
- {
- checkCount++;
- readNextData=false;
- if(checkCount>4)
- break;
- } else if(errorCode.equals("0"))
- {
- readNextData=true;
- if( index==totalparts ){
- dataUploaded=true;
- break;
- }
- }else
- {
- break;
- }
- Logger.i("chunkList index status",index + "--" );
- Logger.i("file totalparts", totalparts + "");
- }
- }catch(Exception e){
- Logger.ex(e);
- }finally {
- if(inStream!=null)
- {
- try {
- inStream.close();
- }catch (Exception e)
- {
- Logger.ex(e);
- }
- }
- }
- return dataUploaded;
- }
- 2019-07-23 18:42:55.726 28853-29047/package name I/chunkList index status: 1--
- 2019-07-23 18:42:55.727 28853-29047/package name I/file <b>totalparts</b>: 3
- 2019-07-23 18:42:55.731 28853-29047/package name I/chunkList index: 2
- 2019-07-23 18:42:55.731 28853-29047/package name I/file <b>totalparts</b>: 3
- 2019-07-23 18:42:55.778 28853-29047/package name I/checkSumValue: A01E20955078EBF06A7FB9DEA62A942C
- 2019-07-23 18:42:55.899 28853-29047/package name E/Service Started: Service Started
- 2019-07-23 18:42:55.906 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
- 2019-07-23 18:42:55.907 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
- 2019-07-23 18:42:56.000 28853-28869/package name <b>I/zygote: Background concurrent copying GC freed 105453(5MB) AllocSpace objects, 83(15MB) LOS objects, 31% free, 52MB/76MB, paused 318us total 172.250ms</b>
- 2019-07-23 18:42:58.600 28853-29047/package name V/responseData: {"ErrorCode":"0","ErrorMessage":"","Result":"True","DeviceIMEI":null,"UserId":null,"UserName":null,"IRNumber":null,"UpdatedDate":"0001-01-01T00:00:00","TokenID":null}
- <b>here its changed values inside loop</b>
- 2019-07-23 18:42:58.602 28853-29047/package name I/chunkList index status: 2--
- 2019-07-23 18:42:58.603 28853-29047/package name I/file <b>totalparts</b>: 330826152
- 2019-07-23 18:42:58.604 28853-29047/package name I/chunkList index: 3
- 2019-07-23 18:42:58.604 28853-29047/package name I/file <b>totalparts</b>: 330826152
- 2019-07-23 18:42:58.644 28853-29047/package name I/checkSumValue: 273E285FE912245F9382341A83A3439B
- 2019-07-23 18:42:58.749 28853-29047/package name E/Service Started: Service Started
- 2019-07-23 18:42:58.754 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
- 2019-07-23 18:42:58.755 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
- 2019-07-23 18:43:00.841 28853-29047/package name V/responseData: {"ErrorCode":"0","ErrorMessage":"","Result":"True","DeviceIMEI":null,"UserId":null,"UserName":null,"IRNumber":null,"UpdatedDate":"0001-01-01T00:00:00","TokenID":null}
- 2019-07-23 18:43:00.844 28853-29047/package name I/chunkList index status: 3--
- 2019-07-23 18:43:00.844 28853-29047/package name I/file <b>totalparts</b>: 330826152
- 2019-07-23 18:43:00.845 28853-29047/package name I/chunkList index: 4
- 2019-07-23 18:43:00.845 28853-29047/package name I/file <b>totalparts</b>: 330826152
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement