Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. public Boolean uploadFile(String filePath,int chunkSize,JSONObject
  2. jsonObj)
  3. {
  4. boolean dataUploaded=false;
  5. InputStream inStream=null;
  6. try
  7. {
  8. File zipFile = new File(filePath);
  9.  
  10. int fileSize = (int)zipFile.length();
  11. inStream = new BufferedInputStream( new
  12. FileInputStream(filePath));
  13.  
  14. //<b>this var changing</b>
  15. final int totalparts =(int) Math.ceil((double)fileSize /
  16. (double)chunkSize);
  17. Logger.i("file totalparts", totalparts + "");
  18.  
  19. byte [] data = new byte[chunkSize];
  20. int index=0,checkCount=0;
  21. boolean readNextData=true;
  22.  
  23. while ( true )
  24. {
  25. if(readNextData) {
  26. inStream.read(data, 0, chunkSize);
  27. checkCount=0;
  28. ++index;
  29. }
  30. Logger.i("chunkList index", index + "");
  31. Logger.i("file totalparts", totalparts + "");
  32.  
  33.  
  34. jsonObj.put("fileName", zipFile.getName());
  35. jsonObj.put("base64Content",
  36. convertToBase64EncodingFromByteArray(data));
  37. jsonObj.put("partNo", index);
  38. jsonObj.put("totalParts", totalparts);
  39. //jsonObj.put("md5checksum","A0A0");
  40. jsonObj.put("md5checksum",CheckSum.getMd5OfByteArray(data));
  41.  
  42. String responseData = sendData(jsonObj.toString());
  43.  
  44. Logger.v("responseData",responseData);
  45. JSONObject responData=new JSONObject(responseData);
  46. String errorCode=(String) responData.get("ErrorCode");
  47.  
  48. if(!errorCode.equals("0"))
  49. {
  50. checkCount++;
  51. readNextData=false;
  52. if(checkCount>4)
  53. break;
  54.  
  55. } else if(errorCode.equals("0"))
  56. {
  57. readNextData=true;
  58. if( index==totalparts ){
  59. dataUploaded=true;
  60. break;
  61. }
  62. }else
  63. {
  64. break;
  65. }
  66.  
  67.  
  68. Logger.i("chunkList index status",index + "--" );
  69. Logger.i("file totalparts", totalparts + "");
  70.  
  71.  
  72. }
  73.  
  74.  
  75. }catch(Exception e){
  76. Logger.ex(e);
  77.  
  78. }finally {
  79. if(inStream!=null)
  80.  
  81. {
  82. try {
  83. inStream.close();
  84. }catch (Exception e)
  85. {
  86. Logger.ex(e);
  87. }
  88. }
  89. }
  90.  
  91. return dataUploaded;
  92. }
  93.  
  94. 2019-07-23 18:42:55.726 28853-29047/package name I/chunkList index status: 1--
  95. 2019-07-23 18:42:55.727 28853-29047/package name I/file <b>totalparts</b>: 3
  96. 2019-07-23 18:42:55.731 28853-29047/package name I/chunkList index: 2
  97. 2019-07-23 18:42:55.731 28853-29047/package name I/file <b>totalparts</b>: 3
  98. 2019-07-23 18:42:55.778 28853-29047/package name I/checkSumValue: A01E20955078EBF06A7FB9DEA62A942C
  99. 2019-07-23 18:42:55.899 28853-29047/package name E/Service Started: Service Started
  100. 2019-07-23 18:42:55.906 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  101. 2019-07-23 18:42:55.907 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  102. 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>
  103. 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}
  104.  
  105. <b>here its changed values inside loop</b>
  106. 2019-07-23 18:42:58.602 28853-29047/package name I/chunkList index status: 2--
  107. 2019-07-23 18:42:58.603 28853-29047/package name I/file <b>totalparts</b>: 330826152
  108. 2019-07-23 18:42:58.604 28853-29047/package name I/chunkList index: 3
  109. 2019-07-23 18:42:58.604 28853-29047/package name I/file <b>totalparts</b>: 330826152
  110. 2019-07-23 18:42:58.644 28853-29047/package name I/checkSumValue: 273E285FE912245F9382341A83A3439B
  111. 2019-07-23 18:42:58.749 28853-29047/package name E/Service Started: Service Started
  112. 2019-07-23 18:42:58.754 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  113. 2019-07-23 18:42:58.755 28853-29047/package name I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  114. 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}
  115. 2019-07-23 18:43:00.844 28853-29047/package name I/chunkList index status: 3--
  116. 2019-07-23 18:43:00.844 28853-29047/package name I/file <b>totalparts</b>: 330826152
  117. 2019-07-23 18:43:00.845 28853-29047/package name I/chunkList index: 4
  118. 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