/** * Runs the application, performing the action specified on the given service and local directory paths. * * @param servicePath * the path in service (including the bucket name) to which files are backed-up, or from which files are restored. * @param files * a set of one or more of File objects for Uploads, or a single target directory for Downloads. * @param actionCommand * the action to perform, UP(load) or DOWN(load) * @param cryptoPassword * if non-null, an {@link EncryptionUtil} object is created with the provided password to encrypt or decrypt files. * @param aclString * the ACL to apply to the uploaded object * @param providerId * service provider name: "S3" or "GS" * * @throws Exception */ public void run(String servicePath, List<File> files, String actionCommand, String cryptoPassword, String aclString, String providerId) throws Exception { File[] filesArray = files.toArray(new File[files.size()]); this.run(servicePath, filesArray, actionCommand, cryptoPassword, aclString, providerId); }
public static String getPassword(String prompt) throws IOException { String password = null; String javaVers = System.getProperty("java.runtime.version"); if (LOG.isDebugEnabled()) { LOG.debug("About to attempt to read password under Java " + "version: "+javaVers); } // Split version string into components. String is of the form // MAJOR_VERSION_NUMBER . MINOR_VERSION_NUMBR . REVISION_STRING // e.g. 1.6.0_17-b04-248-10M3025 String[] versionMajAndMin = javaVers.split("\\."); int majorVersion = Integer.parseInt(versionMajAndMin[0]); int minorVersion = Integer.parseInt(versionMajAndMin[1]); if (majorVersion > 1 || minorVersion >= 6) { password = getPasswordJDK16OrLater(prompt); } else { password = getPasswordBeforeJDK16(prompt); } return password; }
@Override public void event(DownloadObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Download: ", event.getThreadWatcher()); } }
private void displayProgressStatus(String prefix, ThreadWatcher watcher) { String progressMessage = prefix + watcher.getCompletedThreads() + "/" + watcher.getThreadCount(); // Show percentage of bytes transferred, if this info is available. if (watcher.isBytesTransferredInfoAvailable()) { String bytesTotalStr = byteFormatter.formatByteSize(watcher.getBytesTotal()); long percentage = (int) (((double)watcher.getBytesTransferred() / watcher.getBytesTotal()) * 100); String detailsText = formatTransferDetails(watcher); progressMessage += " - " + percentage + "% of " + bytesTotalStr + (detailsText.length() > 0 ? " (" + detailsText + ")" : ""); } else { long percentage = (int) (((double)watcher.getCompletedThreads() / watcher.getThreadCount()) * 100); progressMessage += " - " + percentage + "%"; } printProgressLine(progressMessage); }
printProgressLine("Listing objects in service" + (isBatchMode && mergedDiscrepancyResults.getCountOfItemsCompared() > 0 ? " (Continuing in batches, objects listed previously: " printProgressLine("Comparing service contents with local system"); FileComparerResults discrepancyResults = fileComparer.buildDiscrepancyLists( objectKeyToFilepathMap, objectsMap, md5GenerationProgressWatcher, isForce); ComparisonResult result = new ComparisonResult(); result.priorLastKey = priorLastKey; result.objectsMap = objectsMap;
private static String getPasswordJDK16OrLater(String prompt) throws IOException { String password = null; try { Class consoleClass = Class.forName("java.io.Console"); Method consoleReadPassword = consoleClass.getDeclaredMethod("readPassword", new Class[] {}); Method consoleMethod = System.class.getDeclaredMethod("console", new Class[] {});; Object consoleObject = consoleMethod.invoke(null, new Object[] {}); if (consoleObject == null) { if (LOG.isDebugEnabled()) { LOG.debug("java.io.Console using reflection returned null, " + "so that password will be fetched using the pre-JDK 1.6 version"); } password = getPasswordBeforeJDK16(prompt); } else { System.out.println(prompt + " (typing will be hidden):"); Object passwordObj = consoleReadPassword.invoke(consoleObject, new Object[] {}); char[] passwordChars = (char[]) passwordObj; password = String.valueOf(passwordChars); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IOException("Encountered trouble using relection to generate java.io.Console class"); } return password; }
@Override public void event(CreateObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Upload: ", event.getThreadWatcher()); } }
private void displayProgressStatus(String prefix, ThreadWatcher watcher) { String progressMessage = prefix + watcher.getCompletedThreads() + "/" + watcher.getThreadCount(); // Show percentage of bytes transferred, if this info is available. if (watcher.isBytesTransferredInfoAvailable()) { String bytesTotalStr = byteFormatter.formatByteSize(watcher.getBytesTotal()); long percentage = (int) (((double)watcher.getBytesTransferred() / watcher.getBytesTotal()) * 100); String detailsText = formatTransferDetails(watcher); progressMessage += " - " + percentage + "% of " + bytesTotalStr + (detailsText.length() > 0 ? " (" + detailsText + ")" : ""); } else { long percentage = (int) (((double)watcher.getCompletedThreads() / watcher.getThreadCount()) * 100); progressMessage += " - " + percentage + "%"; } printProgressLine(progressMessage); }
public static String getPassword(String prompt) throws IOException { String password = null; String javaVers = System.getProperty("java.runtime.version"); if (LOG.isDebugEnabled()) { LOG.debug("About to attempt to read password under Java " + "version: "+javaVers); } // Split version string into components. String is of the form // MAJOR_VERSION_NUMBER . MINOR_VERSION_NUMBR . REVISION_STRING // e.g. 1.6.0_17-b04-248-10M3025 String[] versionMajAndMin = javaVers.split("\\."); int majorVersion = Integer.parseInt(versionMajAndMin[0]); int minorVersion = Integer.parseInt(versionMajAndMin[1]); if (majorVersion > 1 || minorVersion >= 6) { password = getPasswordJDK16OrLater(prompt); } else { password = getPasswordBeforeJDK16(prompt); } return password; }
printProgressLine("Listing objects in service" + (isBatchMode && mergedDiscrepancyResults.getCountOfItemsCompared() > 0 ? " (Continuing in batches, objects listed previously: " printProgressLine("Comparing service contents with local system"); FileComparerResults discrepancyResults = fileComparer.buildDiscrepancyLists( objectKeyToFilepathMap, objectsMap, md5GenerationProgressWatcher, isForce); ComparisonResult result = new ComparisonResult(); result.priorLastKey = priorLastKey; result.objectsMap = objectsMap;
/** * Runs the application, performing the action specified on the given service and local directory paths. * * @param servicePath * the path in service (including the bucket name) to which files are backed-up, or from which files are restored. * @param files * a set of one or more of File objects for Uploads, or a single target directory for Downloads. * @param actionCommand * the action to perform, UP(load) or DOWN(load) * @param cryptoPassword * if non-null, an {@link EncryptionUtil} object is created with the provided password to encrypt or decrypt files. * @param aclString * the ACL to apply to the uploaded object * @param providerId * service provider name: "S3" or "GS" * * @throws Exception */ public void run(String servicePath, List<File> files, String actionCommand, String cryptoPassword, String aclString, String providerId) throws Exception { File[] filesArray = files.toArray(new File[files.size()]); this.run(servicePath, filesArray, actionCommand, cryptoPassword, aclString, providerId); }
private static String getPasswordJDK16OrLater(String prompt) throws IOException { String password = null; try { Class consoleClass = Class.forName("java.io.Console"); Method consoleReadPassword = consoleClass.getDeclaredMethod("readPassword", new Class[] {}); Method consoleMethod = System.class.getDeclaredMethod("console", new Class[] {});; Object consoleObject = consoleMethod.invoke(null, new Object[] {}); if (consoleObject == null) { if (LOG.isDebugEnabled()) { LOG.debug("java.io.Console using reflection returned null, " + "so that password will be fetched using the pre-JDK 1.6 version"); } password = getPasswordBeforeJDK16(prompt); } else { System.out.println(prompt + " (typing will be hidden):"); Object passwordObj = consoleReadPassword.invoke(consoleObject, new Object[] {}); char[] passwordChars = (char[]) passwordObj; password = String.valueOf(passwordChars); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IOException("Encountered trouble using relection to generate java.io.Console class"); } return password; }
@Override public void event(DownloadObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Download: ", event.getThreadWatcher()); } }
@Override public void event(DeleteObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Deleting objects in service: ", event.getThreadWatcher()); } } };
@Override public void event(MultipartUploadsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Large upload parts: ", event.getThreadWatcher()); } }
@Override public void event(GetObjectHeadsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Retrieving object details from service: ", event.getThreadWatcher()); } }
@Override public void event(CreateObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Upload: ", event.getThreadWatcher()); } }
@Override public void event(MultipartUploadsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Large upload parts: ", event.getThreadWatcher()); } }
@Override public void event(GetObjectHeadsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Retrieving object details from service: ", event.getThreadWatcher()); } }
@Override public void event(DeleteObjectsEvent event) { super.event(event); displayIgnoredErrors(event); if (ServiceEvent.EVENT_IN_PROGRESS == event.getEventCode()) { displayProgressStatus("Deleting objects in service: ", event.getThreadWatcher()); } } };