/** * compute the recursive file size of all the files in the list. Folder * have a weight of 1. * This does not check for circular links. * @param files * @return */ private int getTotalLocalFileSize(File[] files) { int count = 0; for (File f : files) { if (f.exists()) { if (f.isDirectory()) { return getTotalLocalFileSize(f.listFiles()) + 1; } else if (f.isFile()) { count += f.length(); } } } return count; }
/** * compute the recursive file size of all the files in the list. Folder * have a weight of 1. * This does not check for circular links. * @param files * @return */ private int getTotalLocalFileSize(File[] files) { int count = 0; for (File f : files) { if (f.exists()) { if (f.isDirectory()) { return getTotalLocalFileSize(f.listFiles()) + 1; } else if (f.isFile()) { count += f.length(); } } } return count; }
/** * Push several files. * @param local An array of loca files to push * @param remote the remote {@link FileEntry} representing a directory. * @param monitor The progress monitor. Cannot be null. * @throws SyncException if file could not be pushed * @throws IOException in case of I/O error on the connection. * @throws TimeoutException in case of a timeout reading responses from the device. */ public void push(String[] local, FileEntry remote, ISyncProgressMonitor monitor) throws SyncException, IOException, TimeoutException { if (remote.isDirectory() == false) { throw new SyncException(SyncError.REMOTE_IS_FILE); } // make a list of File from the list of String ArrayList<File> files = new ArrayList<File>(); for (String path : local) { files.add(new File(path)); } // get the total count of the bytes to transfer File[] fileArray = files.toArray(new File[files.size()]); int total = getTotalLocalFileSize(fileArray); monitor.start(total); doPush(fileArray, remote.getFullPath(), monitor); monitor.stop(); }
/** * Push several files. * @param local An array of loca files to push * @param remote the remote {@link FileEntry} representing a directory. * @param monitor The progress monitor. Cannot be null. * @throws SyncException if file could not be pushed * @throws IOException in case of I/O error on the connection. * @throws TimeoutException in case of a timeout reading responses from the device. */ public void push(String[] local, FileEntry remote, ISyncProgressMonitor monitor) throws SyncException, IOException, TimeoutException { if (!remote.isDirectory()) { throw new SyncException(SyncError.REMOTE_IS_FILE); } // make a list of File from the list of String ArrayList<File> files = new ArrayList<File>(); for (String path : local) { files.add(new File(path)); } // get the total count of the bytes to transfer File[] fileArray = files.toArray(new File[files.size()]); int total = getTotalLocalFileSize(fileArray); monitor.start(total); doPush(fileArray, remote.getFullPath(), monitor); monitor.stop(); }