List of usage examples for java.nio.file Path getNameCount
int getNameCount();
From source file:fr.mby.opa.pics.web.controller.UploadPicturesController.java
/*************************************************** * URL: /upload/jqueryUpload upload(): receives files * /*from w w w. jav a 2s.co m*/ * @param request * : MultipartHttpServletRequest auto passed * @param response * : HttpServletResponse auto passed * @return LinkedList<FileMeta> as json format ****************************************************/ @ResponseBody @RequestMapping(value = "/jqueryUpload", method = RequestMethod.POST) public FileMetaList jqueryUpload(@RequestParam final Long albumId, final MultipartHttpServletRequest request, final HttpServletResponse response) throws Exception { Assert.notNull(albumId, "No Album Id supplied !"); final FileMetaList files = new FileMetaList(); // 1. build an iterator final Iterator<String> itr = request.getFileNames(); // 2. get each file while (itr.hasNext()) { // 2.1 get next MultipartFile final MultipartFile mpf = request.getFile(itr.next()); // Here the file is uploaded final String originalFilename = mpf.getOriginalFilename(); final String contentType = mpf.getContentType(); final Matcher zipMatcher = UploadPicturesController.ZIP_CONTENT_TYPE_PATTERN.matcher(contentType); if (zipMatcher.find()) { // 2.3 create new fileMeta final FileMeta zipMeta = new FileMeta(); zipMeta.setFileName(originalFilename); zipMeta.setFileSize(mpf.getSize() / 1024 + " Kb"); zipMeta.setFileType(mpf.getContentType()); final List<Path> picturesPaths = this.processArchive(mpf); final Collection<Future<Void>> futures = new ArrayList<>(picturesPaths.size()); final ExecutorService executorService = Executors .newFixedThreadPool(Runtime.getRuntime().availableProcessors()); for (final Path picturePath : picturesPaths) { final Future<Void> future = executorService.submit(new Callable<Void>() { @Override public Void call() throws Exception { final String pictureFileName = picturePath.getName(picturePath.getNameCount() - 1) .toString(); final byte[] pictureContents = Files.readAllBytes(picturePath); final FileMeta pictureMeta = new FileMeta(); try { final Picture picture = UploadPicturesController.this.createPicture(albumId, pictureFileName.toString(), pictureContents); final Long imageId = picture.getImage().getId(); final Long thumbnailId = picture.getThumbnail().getId(); pictureMeta.setFileName(pictureFileName); pictureMeta.setFileSize(pictureContents.length / 1024 + " Kb"); pictureMeta.setFileType(Files.probeContentType(picturePath)); pictureMeta.setUrl( response.encodeURL(ImageController.IMAGE_CONTROLLER_PATH + "/" + imageId)); pictureMeta.setThumbnailUrl(response .encodeURL(ImageController.IMAGE_CONTROLLER_PATH + "/" + thumbnailId)); } catch (final PictureAlreadyExistsException e) { // Picture already exists ! pictureMeta.setError( UploadPicturesController.PICTURE_ALREADY_EXISTS_MSG + e.getFilename()); } catch (final UnsupportedPictureTypeException e) { // Picture already exists ! pictureMeta.setError( UploadPicturesController.UNSUPPORTED_PICTURE_TYPE_MSG + e.getFilename()); } files.add(pictureMeta); return null; } }); futures.add(future); } for (final Future<Void> future : futures) { future.get(); } files.add(zipMeta); } final Matcher imgMatcher = UploadPicturesController.IMG_CONTENT_TYPE_PATTERN.matcher(contentType); if (imgMatcher.find()) { // 2.3 create new fileMeta final FileMeta fileMeta = new FileMeta(); try { final byte[] fileContents = mpf.getBytes(); final Picture picture = this.createPicture(albumId, originalFilename, fileContents); final Long imageId = picture.getImage().getId(); final Long thumbnailId = picture.getThumbnail().getId(); fileMeta.setFileName(originalFilename); fileMeta.setFileSize(mpf.getSize() / 1024 + " Kb"); fileMeta.setFileType(mpf.getContentType()); fileMeta.setBytes(fileContents); fileMeta.setUrl(response.encodeURL(ImageController.IMAGE_CONTROLLER_PATH + "/" + imageId)); fileMeta.setThumbnailUrl( response.encodeURL(ImageController.IMAGE_CONTROLLER_PATH + "/" + thumbnailId)); // 2.4 add to files files.add(fileMeta); } catch (final PictureAlreadyExistsException e) { // Picture already exists ! fileMeta.setError(UploadPicturesController.PICTURE_ALREADY_EXISTS_MSG); } } } // result will be like this // {files:[{"fileName":"app_engine-85x77.png","fileSize":"8 Kb","fileType":"image/png"},...]} return files; }
From source file:org.nmrfx.processor.gui.MainApp.java
MenuBar makeMenuBar(String appName) { MenuToolkit tk = null;//from w w w . ja va2s .co m if (isMac()) { tk = MenuToolkit.toolkit(); } MenuBar menuBar = new MenuBar(); // Application Menu // TBD: services menu Menu appMenu = new Menu(appName); // Name for appMenu can't be set at // Runtime MenuItem aboutItem = null; Stage aboutStage = makeAbout(appName); if (tk != null) { aboutItem = tk.createAboutMenuItem(appName, aboutStage); } else { aboutItem = new MenuItem("About..."); aboutItem.setOnAction(e -> aboutStage.show()); } MenuItem prefsItem = new MenuItem("Preferences..."); MenuItem quitItem; prefsItem.setOnAction(e -> showPreferences(e)); if (tk != null) { quitItem = tk.createQuitMenuItem(appName); appMenu.getItems().addAll(aboutItem, new SeparatorMenuItem(), prefsItem, new SeparatorMenuItem(), tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(), new SeparatorMenuItem(), quitItem); // createQuitMeneItem doesn't result in stop or quit being called // therefore we can't check for waiting till a commit is done before leaving // so explicitly set action to quit quitItem.setOnAction(e -> quit()); } else { quitItem = new MenuItem("Quit"); quitItem.setOnAction(e -> quit()); } // File Menu (items TBD) Menu fileMenu = new Menu("File"); MenuItem openMenuItem = new MenuItem("Open and Draw..."); openMenuItem.setOnAction(e -> FXMLController.getActiveController().openAction(e)); MenuItem addMenuItem = new MenuItem("Open..."); addMenuItem.setOnAction(e -> FXMLController.getActiveController().addNoDrawAction(e)); MenuItem newMenuItem = new MenuItem("New Window..."); newMenuItem.setOnAction(e -> newGraphics(e)); Menu recentMenuItem = new Menu("Open and Draw Recent"); List<Path> recentDatasets = PreferencesController.getRecentDatasets(); for (Path path : recentDatasets) { int count = path.getNameCount(); int first = count - 3; first = first >= 0 ? first : 0; Path subPath = path.subpath(first, count); MenuItem datasetMenuItem = new MenuItem(subPath.toString()); datasetMenuItem .setOnAction(e -> FXMLController.getActiveController().openFile(path.toString(), false, false)); recentMenuItem.getItems().add(datasetMenuItem); } MenuItem pdfMenuItem = new MenuItem("Export PDF..."); pdfMenuItem.setOnAction(e -> FXMLController.getActiveController().exportPDFAction(e)); MenuItem svgMenuItem = new MenuItem("Export SVG..."); svgMenuItem.setOnAction(e -> FXMLController.getActiveController().exportSVGAction(e)); MenuItem loadPeakListMenuItem = new MenuItem("Load PeakLists"); loadPeakListMenuItem.setOnAction(e -> loadPeakLists()); Menu projectMenu = new Menu("Projects"); MenuItem projectOpenMenuItem = new MenuItem("Open..."); projectOpenMenuItem.setOnAction(e -> loadProject()); MenuItem projectSaveAsMenuItem = new MenuItem("Save As..."); projectSaveAsMenuItem.setOnAction(e -> saveProjectAs()); MenuItem projectSaveMenuItem = new MenuItem("Save"); projectSaveMenuItem.setOnAction(e -> saveProject()); Menu recentProjectMenuItem = new Menu("Open Recent"); List<Path> recentProjects = PreferencesController.getRecentProjects(); for (Path path : recentProjects) { int count = path.getNameCount(); int first = count - 3; first = first >= 0 ? first : 0; Path subPath = path.subpath(first, count); MenuItem projectMenuItem = new MenuItem(subPath.toString()); projectMenuItem.setOnAction(e -> loadProject(path)); recentProjectMenuItem.getItems().add(projectMenuItem); } projectMenu.getItems().addAll(projectOpenMenuItem, recentProjectMenuItem, projectSaveMenuItem, projectSaveAsMenuItem); fileMenu.getItems().addAll(openMenuItem, addMenuItem, newMenuItem, recentMenuItem, new SeparatorMenuItem(), pdfMenuItem, svgMenuItem, loadPeakListMenuItem); Menu spectraMenu = new Menu("Spectra"); MenuItem deleteItem = new MenuItem("Delete Spectrum"); deleteItem.setOnAction(e -> FXMLController.getActiveController().removeChart()); MenuItem syncMenuItem = new MenuItem("Sync Axes"); syncMenuItem.setOnAction(e -> PolyChart.activeChart.syncSceneMates()); Menu arrangeMenu = new Menu("Arrange"); MenuItem horizItem = new MenuItem("Horizontal"); horizItem.setOnAction( e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.HORIZONTAL)); MenuItem vertItem = new MenuItem("Vertical"); vertItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.VERTICAL)); MenuItem gridItem = new MenuItem("Grid"); gridItem.setOnAction(e -> FXMLController.getActiveController().arrange(FractionPane.ORIENTATION.GRID)); MenuItem overlayItem = new MenuItem("Overlay"); overlayItem.setOnAction(e -> FXMLController.getActiveController().overlay()); MenuItem minimizeItem = new MenuItem("Minimize Borders"); minimizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(true)); MenuItem normalizeItem = new MenuItem("Normal Borders"); normalizeItem.setOnAction(e -> FXMLController.getActiveController().setBorderState(false)); arrangeMenu.getItems().addAll(horizItem, vertItem, gridItem, overlayItem, minimizeItem, normalizeItem); MenuItem alignMenuItem = new MenuItem("Align Spectra"); alignMenuItem.setOnAction(e -> FXMLController.getActiveController().alignCenters()); MenuItem analyzeMenuItem = new MenuItem("Analyzer..."); analyzeMenuItem.setOnAction(e -> showAnalyzer(e)); spectraMenu.getItems().addAll(deleteItem, arrangeMenu, syncMenuItem, alignMenuItem, analyzeMenuItem); // Format (items TBD) // Menu formatMenu = new Menu("Format"); // formatMenu.getItems().addAll(new MenuItem("TBD")); // View Menu (items TBD) Menu viewMenu = new Menu("View"); MenuItem dataMenuItem = new MenuItem("Show Datasets"); dataMenuItem.setOnAction(e -> showDatasetsTable(e)); MenuItem consoleMenuItem = new MenuItem("Show Console"); consoleMenuItem.setOnAction(e -> showConsole(e)); MenuItem attrMenuItem = new MenuItem("Show Attributes"); attrMenuItem.setOnAction(e -> FXMLController.getActiveController().showSpecAttrAction(e)); MenuItem procMenuItem = new MenuItem("Show Processor"); procMenuItem.setOnAction(e -> FXMLController.getActiveController().showProcessorAction(e)); MenuItem scannerMenuItem = new MenuItem("Show Scanner"); scannerMenuItem.setOnAction(e -> FXMLController.getActiveController().showScannerAction(e)); viewMenu.getItems().addAll(consoleMenuItem, dataMenuItem, attrMenuItem, procMenuItem, scannerMenuItem); Menu peakMenu = new Menu("Peaks"); MenuItem peakAttrMenuItem = new MenuItem("Show Peak Tool"); peakAttrMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakAttrAction(e)); MenuItem peakNavigatorMenuItem = new MenuItem("Show Peak Navigator"); peakNavigatorMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakNavigator()); MenuItem linkPeakDimsMenuItem = new MenuItem("Link by Labels"); linkPeakDimsMenuItem.setOnAction(e -> FXMLController.getActiveController().linkPeakDims()); MenuItem peakSliderMenuItem = new MenuItem("Show Peak Slider"); peakSliderMenuItem.setOnAction(e -> FXMLController.getActiveController().showPeakSlider()); peakMenu.getItems().addAll(peakAttrMenuItem, peakNavigatorMenuItem, linkPeakDimsMenuItem, peakSliderMenuItem); // Window Menu // TBD standard window menu items // Help Menu (items TBD) Menu helpMenu = new Menu("Help"); MenuItem webSiteMenuItem = new MenuItem("NMRFx Web Site"); webSiteMenuItem.setOnAction(e -> showWebSiteAction(e)); MenuItem docsMenuItem = new MenuItem("Online Documentation"); docsMenuItem.setOnAction(e -> showDocAction(e)); MenuItem versionMenuItem = new MenuItem("Check Version"); versionMenuItem.setOnAction(e -> showVersionAction(e)); MenuItem mailingListItem = new MenuItem("Mailing List Site"); mailingListItem.setOnAction(e -> showMailingListAction(e)); MenuItem refMenuItem = new MenuItem("NMRFx Publication"); refMenuItem.setOnAction(e -> { MainApp.hostServices.showDocument("http://link.springer.com/article/10.1007/s10858-016-0049-6"); }); // home // mailing list // helpMenu.getItems().addAll(docsMenuItem, webSiteMenuItem, mailingListItem, versionMenuItem, refMenuItem); if (tk != null) { Menu windowMenu = new Menu("Window"); windowMenu.getItems().addAll(tk.createMinimizeMenuItem(), tk.createZoomMenuItem(), tk.createCycleWindowsItem(), new SeparatorMenuItem(), tk.createBringAllToFrontItem()); menuBar.getMenus().addAll(appMenu, fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, windowMenu, helpMenu); tk.autoAddWindowMenuItems(windowMenu); tk.setGlobalMenuBar(menuBar); } else { fileMenu.getItems().add(prefsItem); fileMenu.getItems().add(quitItem); menuBar.getMenus().addAll(fileMenu, projectMenu, spectraMenu, viewMenu, peakMenu, helpMenu); helpMenu.getItems().add(0, aboutItem); } return menuBar; }
From source file:org.openhab.tools.analysis.checkstyle.ServiceComponentManifestCheck.java
@Override protected void processFiltered(File file, FileText fileText) throws CheckstyleException { Path absolutePath = file.toPath(); int osgiInfIndex = getIndex(absolutePath, OSGI_INF_DIRECTORY_NAME); String fileExtension = FilenameUtils.getExtension(file.getName()); // The components are .xml files located in OSGI-INF folder if (fileExtension.equals(XML_EXTENSION) && osgiInfIndex > -1) { // All the defined components are collected to be processed later componentXmlFiles.add(file.getName()); // Get the relative path Path relativePath = absolutePath.subpath(osgiInfIndex, absolutePath.getNameCount()); componentXmlRelativePaths.add(relativePath); }/*ww w. jav a 2s .c o m*/ if (file.getName().equals(MANIFEST_FILE_NAME)) { verifyManifest(fileText); } if (file.getName().equals(BUILD_PROPERTIES_FILE_NAME)) { processBuildPropertiesFile(fileText); } }
From source file:org.xwiki.filter.xff.internal.input.PagesReader.java
@Override public void route(Path path, InputStream inputStream) throws FilterException { String fileName = path.toString(); if (fileName.equals(org.xwiki.xff.core.model.Page.PAGE_FILENAME)) { this.parsePage(inputStream); this.start(); return;//from ww w . jav a2 s. c om } else { this.start(); } String hint = path.subpath(0, 1).toString(); if (hint.equals(org.xwiki.xff.core.model.Property.PROPERTY_HINT)) { this.routeProperty(path, inputStream); return; } String childId = null; Path childPath = null; switch (hint) { case "attachments": childId = path.subpath(1, 2).toString(); childPath = path.subpath(1, path.getNameCount()); break; case "classes": childId = this.reference.toString(); childPath = path.subpath(1, path.getNameCount()); break; case "objects": childId = path.subpath(1, 3).toString(); childPath = path.subpath(3, path.getNameCount()); break; default: String message = String.format("PagesReader don't know how to route '%s'.", path.toString()); throw new FilterException(message); } // Get a new reader only if the child change if (!childId.equals(this.lastReaderId)) { if (this.reader != null) { this.reader.close(); } this.reader = this.getReader(hint); this.reader.open(childId, this.reference, this.filter, this.proxyFilter); } this.reader.route(childPath, inputStream); this.lastReaderId = childId; }
From source file:org.craftercms.studio.impl.v1.repository.job.RebuildRepositoryMetadata.java
protected boolean populateRebuildRepositoryMetadataQueue(String site) { logger.debug("Populating Rebuild Repository Metadata queue for site " + site); Path siteContentRootPath = Paths.get(previewRepoRootPath, contentService.expandRelativeSitePath(site, "")); logger.debug("Retrieving files list for content repository"); Iterator<File> fileIterator = FileUtils.iterateFiles( Paths.get(previewRepoRootPath, contentService.expandRelativeSitePath(site, "")).toFile(), null, true);//from w ww . j a v a2 s. c om List<String> paths = new ArrayList<String>(); int id = 1; while (fileIterator.hasNext()) { File file = fileIterator.next(); Path filePath = Paths.get(file.toURI()); String relativePath = "/" + filePath.subpath(siteContentRootPath.getNameCount(), filePath.getNameCount()); logger.debug("Processing " + relativePath); paths.add(relativePath); if (paths.size() == batchSize) { logger.debug("Insert batch of file paths into queue."); Map<String, Object> params = new HashMap<String, Object>(); params.put("id", id); params.put("site", site); params.put("pathList", paths); rebuildRepositoryMetadataMapper.insertRebuildRepoMetadataQueue(params); id = id + paths.size(); paths = new ArrayList<String>(); } } if (paths != null && paths.size() > 0) { logger.debug("Insert batch of file paths into queue."); Map<String, Object> params = new HashMap<String, Object>(); params.put("id", id); params.put("site", site); params.put("pathList", paths); rebuildRepositoryMetadataMapper.insertRebuildRepoMetadataQueue(params); paths = new ArrayList<String>(); } return true; }
From source file:org.schedulesdirect.grabber.Grabber.java
private void removeUnusedPrograms(FileSystem vfs) throws IOException { final int[] i = new int[] { 0 }; final Path root = vfs.getPath("programs"); Files.walkFileTree(root, new FileVisitor<Path>() { @Override//from ww w. j a va 2 s. c om public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return !Files.isSameFile(root, dir) ? FileVisitResult.SKIP_SUBTREE : FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String id = file.getName(file.getNameCount() - 1).toString(); id = id.substring(0, id.indexOf('.')); if (!activeProgIds.contains(id)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("CacheCleaner: Unused '%s'", id)); Files.delete(file); ++i[0]; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); LOG.info(String.format("Removed %d unused program(s).", i[0])); }
From source file:org.schedulesdirect.grabber.Grabber.java
private void removeIgnoredStations(FileSystem vfs) throws IOException { final int[] i = new int[] { 0 }; final Path root = vfs.getPath("schedules"); Files.walkFileTree(root, new FileVisitor<Path>() { @Override/* ww w.j av a 2s. c o m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return !Files.isSameFile(root, dir) ? FileVisitResult.SKIP_SUBTREE : FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String id = file.getName(file.getNameCount() - 1).toString(); id = id.substring(0, id.indexOf('.')); if (stationList != null && !stationList.contains(id)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("CacheCleaner: Remove '%s'", id)); Files.delete(file); ++i[0]; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); LOG.info(String.format("Removed %d ignored station(s).", i[0])); }
From source file:org.apache.nifi.processors.standard.MergeContent.java
private String getPath(final FlowFile flowFile) { Path path = Paths.get(flowFile.getAttribute(CoreAttributes.PATH.key())); if (path.getNameCount() == 0) { return ""; }/*ww w . j a v a2s. co m*/ if (".".equals(path.getName(0).toString())) { path = path.getNameCount() == 1 ? null : path.subpath(1, path.getNameCount()); } return path == null ? "" : path.toString() + "/"; }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java
public void run(Path inPath, Path outPath, Analytic<? extends TokenizedCommunication> analytic) { LOGGER.debug("Checking input and output directories."); try {/* w ww. jav a 2 s . c o m*/ prepareInputOutput(inPath, outPath); } catch (IOException e) { LOGGER.error("Caught IOException when checking input and output directories.", e); } String lowerOutPathStr = inPath.toString().toLowerCase(); try { sed.disable(); // Outcomes of outPathStr ending: // No valid ending (program exit) // Ends with .concrete (first if) // Ends with .tar (else, first if) // Ends with .tar.gz (else, second if) boolean isTarExt = lowerOutPathStr.endsWith(".tar"); boolean isTarGzExt = lowerOutPathStr.endsWith(".tar.gz") || lowerOutPathStr.endsWith(".tgz"); boolean isConcreteExt = lowerOutPathStr.endsWith(".concrete") || lowerOutPathStr.endsWith(".comm"); int nElementsInitPath = inPath.getNameCount(); Path inputFileName = inPath.getName(nElementsInitPath - 1); // If no extention matches, exit. if (!isTarExt && !isTarGzExt && !isConcreteExt) { LOGGER.error("Input file extension was not '.concrete', '.comm', '.tar', or '.tar.gz'; exiting."); System.exit(1); } else if (isConcreteExt) { // IF .concrete, run single communication. LOGGER.info("Annotating single .concrete file at: {}", inPath.toString()); try (InputStream in = Files.newInputStream(inPath); BufferedInputStream bin = new BufferedInputStream(in, 1024 * 8 * 24);) { byte[] inputBytes = IOUtils.toByteArray(bin); Communication c = ser.fromBytes(inputBytes); WrappedCommunication annotated = analytic.annotate(c); Communication ar = annotated.getRoot(); WritableCommunication wc = new WritableCommunication(ar); if (Files.isDirectory(outPath)) wc.writeToFile(outPath.resolve(inputFileName), true); else wc.writeToFile(outPath, true); } catch (AnalyticException e) { LOGGER.error("Caught exception when running the analytic.", e); } } else { Path localOutPath; if (Files.isDirectory(outPath)) // if directory, use same extension as input. localOutPath = outPath.resolve(inputFileName); else localOutPath = outPath; // Iterate over the archive. AutoCloseableIterator<byte[]> iter; try (InputStream is = Files.newInputStream(inPath); BufferedInputStream bis = new BufferedInputStream(is, 1024 * 8 * 24);) { // open iterator based on file extension iter = isTarExt ? new TarArchiveEntryByteIterator(bis) : new TarGzArchiveEntryByteIterator(bis); try (OutputStream os = Files.newOutputStream(localOutPath); BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 24);) { TarArchiver archiver = isTarExt ? new TarArchiver(bos) : new TarArchiver(new GzipCompressorOutputStream(bos)); final StopWatch sw = new StopWatch(); sw.start(); int docCtr = 0; final AtomicInteger tokenCtr = new AtomicInteger(0); LOGGER.info("Iterating over archive: {}", inPath.toString()); while (iter.hasNext()) { Communication n = ser.fromBytes(iter.next()); LOGGER.info("Annotating communication: {}", n.getId()); try { TokenizedCommunication a = analytic.annotate(n); a.getTokenizations().parallelStream() .map(tkzToInt -> tkzToInt.getTokenList().getTokenListSize()) .forEach(ct -> tokenCtr.addAndGet(ct)); archiver.addEntry(new ArchivableCommunication(a.getRoot())); docCtr++; } catch (AnalyticException | IOException | StringIndexOutOfBoundsException e) { LOGGER.error("Caught exception processing document: " + n.getId(), e); } } try { archiver.close(); iter.close(); } catch (Exception e) { // unlikely. LOGGER.info("Caught exception closing iterator.", e); } sw.stop(); Duration rt = new Duration(sw.getTime()); Seconds st = rt.toStandardSeconds(); Minutes m = rt.toStandardMinutes(); int minutesInt = m.getMinutes(); LOGGER.info("Complete."); LOGGER.info("Runtime: approximately {} minutes.", minutesInt); LOGGER.info("Processed {} documents.", docCtr); final int tokens = tokenCtr.get(); LOGGER.info("Processed {} tokens.", tokens); if (docCtr > 0 && minutesInt > 0) { final float minutesFloat = minutesInt; float perMin = docCtr / minutesFloat; LOGGER.info("Processed approximately {} documents/minute.", perMin); LOGGER.info("Processed approximately {} tokens/second.", st.getSeconds() / minutesFloat); } } } } } catch (IOException | ConcreteException e) { LOGGER.error("Caught exception while running the analytic over archive.", e); } }
From source file:org.esa.s2tbx.dataio.jp2.internal.JP2TileOpImage.java
private Path decompressTile(int tileIndex, int level) throws IOException { Path tileFile = PathUtils.get(cacheDir, PathUtils.getFileNameWithoutExtension(imageFile).toLowerCase() + "_tile_" + String.valueOf(tileIndex) + "_" + String.valueOf(level) + ".tif"); if ((!Files.exists(tileFile)) || (diffLastModifiedTimes(tileFile.toFile(), imageFile.toFile()) < 0L)) { final OpjExecutor decompress = new OpjExecutor(OpenJpegExecRetriever.getOpjDecompress()); final Map<String, String> params = new HashMap<String, String>() { {//w w w.j av a 2 s . c o m put("-i", GetIterativeShortPathNameW(imageFile.toString())); put("-r", String.valueOf(level)); put("-l", "20"); } }; String tileFileName; if (org.apache.commons.lang.SystemUtils.IS_OS_WINDOWS && (tileFile.getParent() != null)) { tileFileName = Utils.GetIterativeShortPathNameW(tileFile.getParent().toString()) + File.separator + tileFile.getName(tileFile.getNameCount() - 1); } else { tileFileName = tileFile.toString(); } params.put("-o", tileFileName); params.put("-t", String.valueOf(tileIndex)); params.put("-p", String.valueOf(DataBuffer.getDataTypeSize(this.getSampleModel().getDataType()))); params.put("-threads", "ALL_CPUS"); if (decompress.execute(params) != 0) { logger.severe(decompress.getLastError()); tileFile = null; } else { logger.fine("Decompressed tile #" + String.valueOf(tileIndex) + " @ resolution " + String.valueOf(level)); } } return tileFile; }