Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Nullable public static Resource getDocumentResource(SmbFile file)
- throws IOException
- {
- final ResourceHandler resourceHandler = Context.getSingleton(ResourceHandler.class);
- final Resource.Factory factory = resourceHandler.create();
- Resource resource = null;
- if (file.exists() && file.canRead() && file.isFile()) {
- try(final InputStream is = file.getInputStream()) {
- resource = factory.upload(file.getName(), Mime.APPLICATION_PDF.getMime(), is);
- }
- }
- if (file.canWrite()) file.delete();
- return resource;
- }
- public static List<SmbFile> findFiles(@NotNull String type)
- throws Exception
- {
- final ScanProperties props = Context.getProperties(ScanProperties.class);
- final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(props.domain, props.user, props.password);
- final ImmutableList<String> hosts = Strings.split(props.hostname, ':');
- final List<SmbFile> list = new ArrayList<>();
- for (final String host : hosts) {
- logger.info("DOCUMENT_SCAN_SUBSCRIPTION HOST: " + host);
- final String pdfUrl = format("smb://%s/%s/", host, props.share);
- final SmbFile dir = new SmbFile(pdfUrl, auth);
- final List<SmbFile> listFilter = Arrays.stream(dir.listFiles())
- .filter(file ->
- file.getCanonicalPath().contains(type))
- .collect(Collectors.toList());
- list.addAll(listFilter);
- }
- list.forEach(file -> logger.info("DOCUMENT_SCAN_SUBSCRIPTION DIR: " + file.getCanonicalPath()));
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement