private void download(InputStream is, String destinationFile) { try { double currentSize = 0; OutputStream os = new FileOutputStream(destinationFile); byte[] b = new byte[4096]; int length; this.setProgress(0); while ((length = is.read(b)) != -1) { os.write(b, 0, length); currentSize += length; setProgress((int) ((currentSize / fileSize) * 100)); } is.close(); os.close(); } catch (FileNotFoundException e) { java.io.File file = new java.io.File(MAMUtil.getTempDownloadPath()); file.mkdirs(); download(is, destinationFile); } catch (Exception e) { MAMUtil.writeLog(e); e.printStackTrace(); } }
private void downloadFileWithStream(String fileName) { try { InputStream is = downloadFile(fileName); download(is, MAMUtil.getTempDownloadPath() + fileName); FileUtils.moveFile( new java.io.File(MAMUtil.getTempDownloadPath() + fileName), new java.io.File(MAMUtil.getMusicPath() + fileName)); } catch (Exception e) { MAMUtil.writeLog(e); e.printStackTrace(); } }
public GoogleDriveDownloadTask(String fileName) { if (DriveUtil.service == null) { try { DriveUtil.getDriveService(); } catch (GeneralSecurityException | IOException | URISyntaxException e) { MAMUtil.writeLog(e); e.printStackTrace(); } } ArrayList<String> fileList = new ArrayList<String>(); fileList.add(fileName); this.fileList = fileList; this.totalFileNumber = 1; }
private InputStream downloadFile(String fileName) throws IOException { File file = DriveUtil.getFileByName(fileName); if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) try { fileSize = file.getFileSize(); return DriveUtil.service.files().get(file.getId()).executeMediaAsInputStream(); } catch (IOException e) { e.printStackTrace(); MAMUtil.writeLog(e); return null; } return null; }