Guest User

With Serial Processing

a guest
Feb 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import com.pdftron.pdf.PDFDoc;
  2. import com.pdftron.pdf.PDFNet;
  3.  
  4. import javax.annotation.PostConstruct;
  5. import javax.annotation.PreDestroy;
  6. import java.io.FileNotFoundException;
  7. import java.util.ArrayList;
  8. import java.util.Enumeration;
  9. import java.util.List;
  10. import java.util.zip.ZipEntry;
  11. import java.util.zip.ZipFile;
  12. import java.util.stream.Collectors;
  13. import java.util.Scanner;
  14.  
  15. public class PDFTron {
  16.     public static void main(String[] args) throws Exception {
  17.         PDFNet.initialize();
  18.  
  19.         Scanner scanner = new Scanner(System.in);
  20.         scanner.nextInt();
  21.         int count = 100;
  22.         do {
  23.             while (count > 0) {
  24.                 run();
  25.                 count--;
  26.             }
  27.             System.out.println("Iteration done!");
  28.             count = scanner.nextInt();
  29.         }
  30.         while (count != 0);
  31.  
  32.         PDFNet.terminate();
  33.  
  34.         System.out.println("Done");
  35.         scanner.nextInt();
  36.     }
  37.  
  38.     private static void run() throws Exception {
  39.         String pathToZipFile = "files.zip";
  40.         ZipFile zipFile = new ZipFile(pathToZipFile);
  41.  
  42.         List<PDFDoc> pdfDocs = zipFile.stream().parallel()
  43.                 .map(zipEntry -> {
  44.                     try {
  45.                         return new PDFDoc(zipFile.getInputStream(zipEntry));
  46.                     } catch (Exception e) {
  47.                         e.printStackTrace();
  48.                     }
  49.                     return null;
  50.                 })
  51.                 .collect(Collectors.toList());
  52.  
  53.         zipFile.close();
  54.         for (PDFDoc pdfDoc : pdfDocs) {
  55.             pdfDoc.close();
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment