Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public static void copyStreams(InputStream is, OutputStream os, long totalBytes,
  2. FileSenderInterface fileSenderI)
  3. {
  4. if (is != null && os != null)
  5. {
  6. byte[] mybytearray = new byte[4096];
  7. try
  8. {
  9. while (is.read(mybytearray) != -1)
  10. {
  11. int length = mybytearray.length;
  12. os.write(mybytearray, 0, length);
  13.  
  14. if (fileSenderI != null)
  15. {
  16. int progress = (int) (length / totalBytes * 100);
  17. fileSenderI.onWrite(progress);
  18. }
  19. }
  20. os.flush();
  21. }
  22. catch (IOException e)
  23. {
  24. logError(e);
  25. }
  26. finally
  27. {
  28. try
  29. {
  30. os.close();
  31. }
  32. catch (IOException e)
  33. {
  34. logError(e);
  35. }
  36. }
  37. }
  38. }
  39.  
  40. public interface FileSenderInterface
  41. {
  42. void onWrite(int progress);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement