List of usage examples for java.nio.file.attribute PosixFileAttributes lastModifiedTime
FileTime lastModifiedTime();
From source file:com.vns.pdf.impl.PdfDocument.java
private PdfDocument(String pdfFileName) throws IOException { this.pdfFileName = pdfFileName; setWorkingDir();/*from w ww . j a v a 2 s .c om*/ Path filePath = Paths.get(pdfFileName); PosixFileAttributes attrs = Files.getFileAttributeView(filePath, PosixFileAttributeView.class) .readAttributes(); String textAreaFileName = filePath.getFileName().toString() + "_" + filePath.toAbsolutePath().hashCode() + "_" + attrs.size() + "_" + attrs.lastModifiedTime().toString().replace(":", "_") + ".xml"; textAreaFilePath = Paths.get(workingDir.toAbsolutePath().toString(), textAreaFileName); pdfTextStripper = new CustomPDFTextStripper(); document = PDDocument.load(new File(pdfFileName)); pdfRenderer = new PDFRenderer(document); if (Files.notExists(textAreaFilePath, LinkOption.NOFOLLOW_LINKS)) { pdfTextStripper.setSortByPosition(false); pdfTextStripper.setStartPage(0); pdfTextStripper.setEndPage(document.getNumberOfPages()); this.doc = new Doc(new ArrayList<>(), new ArrayList<>()); for (int i = 0; i < document.getNumberOfPages(); i++) { PDPage pdPage = document.getPage(i); PDRectangle box = pdPage.getMediaBox(); this.doc.getPages().add(new Page(new ArrayList<>(), new ArrayList<>(), (int) box.getWidth(), (int) box.getHeight())); } Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream()); try { pdfTextStripper.writeText(document, dummy); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } parseBookmarksAnnotation(); createTextAreaFile(); //document.save(pdfFileName + ".pdf"); } else { loadTextAreaFile(); } }