Guest User

With Parallel Processing

a guest
Feb 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 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.         Scanner scanner = new Scanner(System.in);
  19.  
  20.         int count = 20;
  21.         while (count > 0) {
  22.             new Thread(new B()).start();
  23.             count--;
  24.         }
  25.  
  26.         System.out.println("Done");
  27.         scanner.nextInt();
  28.         PDFNet.terminate();
  29.         scanner.nextInt();
  30.     }
  31.  
  32.     private static class B implements Runnable {
  33.         public void run() {
  34.             int count = 10;
  35.             while (count > 0) {
  36.                 try {
  37.                     String pathToZipFile = "files.zip";
  38.                     ZipFile zipFile = new ZipFile(pathToZipFile);
  39.  
  40.                     List<PDFDoc> pdfDocs = zipFile.stream().parallel()
  41.                             .map(zipEntry -> {
  42.                                 try {
  43.                                     return new PDFDoc(zipFile.getInputStream(zipEntry));
  44.                                 } catch (Exception e) {
  45.                                     e.printStackTrace();
  46.                                 }
  47.                                 return null;
  48.                             })
  49.                             .collect(Collectors.toList());
  50.  
  51.                     zipFile.close();
  52.                     for (PDFDoc pdfDoc : pdfDocs) {
  53.                         pdfDoc.close();
  54.                     }
  55.  
  56.                 } catch (Exception e) {
  57.                     e.printStackTrace();
  58.                 }
  59.                 count--;
  60.             }
  61.         }
  62.     }
  63. }
Add Comment
Please, Sign In to add comment