/** * Conditionally prints the @a string depending on the current * setting of the Options singleton. */ private void print(String string) { if (Options.instance().getDiagnosticsEnabled()) System.out.println(string); } }
/** * This static main() entry point runs the example. */ public static void main(String[] args) { // Initializes the Options singleton. Options.instance().parseArgs(args); // Create an object that count the images. new ImageCounter(); } }
/** * Clears the filter directories. */ private void deleteDownloadedImages() { int deletedFiles = deleteSubFolders(Options.instance().getDirectoryPath()); System.out.println(TAG + ": " + deletedFiles + " previously downloaded file(s) deleted"); }
/** * @return A future to the page at the root URI */ private CompletableFuture<Document> getStartPage(String pageUri) { return CompletableFuture // Asynchronously get the contents of the page. .supplyAsync(() -> Options .instance() .getJSuper() .getPage(pageUri)); }
/** * Run the program. */ private void run() { // Delete any the filtered images from the previous run. deleteDownloadedImages(); // Get the list of files to the downloaded images. List<File> imageFiles = Options.instance().getUrlList() // Convert the URLs in the input list into a stream and // process them in parallel. .parallelStream() // Transform URL to a File by downloading each image via // its URL. This call ensures the common fork/join thread // pool is expanded to handle the blocking image download. .map(this::downloadAndStoreImage) // Terminate the stream and collect the results into list // of images. .collect(Collectors.toList()); System.out.println(TAG + ": downloaded and stored " + imageFiles.size() + " images"); }
/** * The JVM requires a static main() entry point to run the app. */ public static void main(String[] args) { // Initializes the Options singleton. Options.instance().parseArgs(args); new ex20().run(); }
/** * Store the image on the local file system. * * @return The stored image file. */ public File store() { // Get a reference to the file in which the image will be // stored. File imageFile = new File(new File(Options.instance().getDirectoryPath()), getFileName()); // Store the image using try-with-resources try (FileOutputStream outputFile = new FileOutputStream(imageFile)) { // Write the image to the output file. PlatSpec.writeImageFile(outputFile, this); return imageFile; } catch (Exception e) { e.printStackTrace(); return null; } } }
String rootUri = Options.instance().getRootUri();
.instance() .getJSuper() .getHyperLink(hyperLink),