Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1.     @Nullable public static Resource getDocumentResource(SmbFile file)
  2.         throws IOException
  3.     {
  4.         final ResourceHandler  resourceHandler = Context.getSingleton(ResourceHandler.class);
  5.         final Resource.Factory factory         = resourceHandler.create();
  6.         Resource               resource        = null;
  7.  
  8.  
  9.             if (file.exists() && file.canRead() && file.isFile()) {
  10.                 try(final InputStream is = file.getInputStream()) {
  11.                     resource = factory.upload(file.getName(), Mime.APPLICATION_PDF.getMime(), is);
  12.                 }
  13.             }
  14.        
  15.         if (file.canWrite()) file.delete();
  16.  
  17.         return resource;
  18.     }
  19.  
  20.  
  21.  
  22.     public static List<SmbFile> findFiles(@NotNull String type)
  23.         throws Exception
  24.     {
  25.         final ScanProperties             props = Context.getProperties(ScanProperties.class);
  26.         final NtlmPasswordAuthentication auth  = new NtlmPasswordAuthentication(props.domain, props.user, props.password);
  27.  
  28.         final ImmutableList<String> hosts = Strings.split(props.hostname, ':');
  29.         final List<SmbFile>         list  = new ArrayList<>();
  30.  
  31.         for (final String host : hosts) {
  32.             logger.info("DOCUMENT_SCAN_SUBSCRIPTION HOST: " + host);
  33.             final String  pdfUrl = format("smb://%s/%s/", host, props.share);
  34.             final SmbFile dir    = new SmbFile(pdfUrl, auth);
  35.  
  36.             final List<SmbFile> listFilter = Arrays.stream(dir.listFiles())
  37.                 .filter(file ->
  38.                         file.getCanonicalPath().contains(type))
  39.                 .collect(Collectors.toList());
  40.             list.addAll(listFilter);
  41.         }
  42.         list.forEach(file -> logger.info("DOCUMENT_SCAN_SUBSCRIPTION DIR: " + file.getCanonicalPath()));
  43.         return list;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement