List of usage examples for java.nio.file Path toString
String toString();
From source file:com.aleerant.tnssync.PropertiesHandler.java
private void validateTnsAdminPath() { if (this.mTnsAdminPathString == null) { throw new IllegalArgumentException("Missing parameter: TNS_ADMIN"); }//from ww w .ja v a 2 s . c o m Path p = Paths.get(this.mTnsAdminPathString); if (Files.notExists(p)) { throw new IllegalArgumentException("Directory not found (TNS_ADMIN): " + p.toString()); } }
From source file:misc.FileHandler.java
/** * Returns the access bundle for the given location or <code>null</code>, if * no parseable access bundle was found. * /*from w w w .ja va 2 s. c om*/ * @param prefix * the path to the client's root directory. May not be * <code>null</code>. * @param folder * a folder path relative to prefix containing an access bundle. * May not be <code>null</code>. * @return the parsed access bundle, if the bundle exists and the bundle is * syntactically correct. <code>null</code>, otherwise. */ public static AccessBundle getAccessBundle(Path prefix, Path folder) { if (prefix == null) { throw new NullPointerException("prefix may not be null!"); } if (folder == null) { throw new NullPointerException("folder may not be null!"); } AccessBundle bundle = null; Path completePath = Paths.get(prefix.toString(), folder.toString()); try { if (isShared(prefix, folder)) { bundle = GroupAccessBundle .parse(Paths.get(completePath.toString(), AccessBundle.ACCESS_BUNDLE_FILENAME)); } else { bundle = OwnerAccessBundle .parse(Paths.get(completePath.toString(), AccessBundle.ACCESS_BUNDLE_FILENAME)); } } catch (IOException | ParseException e) { Logger.logError(e); } return bundle; }
From source file:edu.chalmers.dat076.moviefinder.service.MovieFileDatabaseHandlerImpl.java
@Override public void setPaths(List<Path> paths) { Iterable<Movie> movies = movieRepository.findAll(); Iterable<Episode> episodes = episodeRepository.findAll(); for (Movie m : movies) { boolean foundParent = false; for (Path p : paths) { if (m.getFilePath().startsWith(p.toString())) { foundParent = true;// ww w .java2s . c o m break; } } if (!foundParent) { removeFile(new File(m.getFilePath()).toPath()); } } for (Episode e : episodes) { boolean foundParent = false; for (Path p : paths) { if (e.getFilePath().startsWith(p.toString())) { foundParent = true; break; } } if (!foundParent) { removeFile(new File(e.getFilePath()).toPath()); } } }
From source file:io.syndesis.git.GitWorkflow.java
/** * Write files to the file system// w w w . j a v a2 s. c o m * * @param workingDir * @param files * @throws IOException */ @SuppressWarnings("unused") private void writeFiles(Path workingDir, Map<String, byte[]> files) throws IOException { for (Map.Entry<String, byte[]> entry : files.entrySet()) { File file = new File(workingDir.toString(), entry.getKey()); if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { throw new IOException("Cannot create directory " + file.getParentFile()); } Files.write(file.toPath(), entry.getValue()); } }
From source file:de.fatalix.bookery.bl.background.importer.CalibriImporter.java
private void processArchive(final Path zipFile, final int batchSize) throws IOException { try (FileSystem zipFileSystem = FileSystems.newFileSystem(zipFile, null)) { final List<BookEntry> bookEntries = new ArrayList<>(); Path root = zipFileSystem.getPath("/"); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override/*from w w w .j av a2s.com*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.toString().contains("__MACOSX")) { return FileVisitResult.SKIP_SUBTREE; } try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) { BookEntry bookEntry = new BookEntry().setUploader("admin"); for (Path path : directoryStream) { if (!Files.isDirectory(path)) { if (path.toString().contains(".opf")) { bookEntry = parseOPF(path, bookEntry); } if (path.toString().contains(".mobi")) { bookEntry.setMobi(Files.readAllBytes(path)).setMimeType("MOBI"); } if (path.toString().contains(".epub")) { bookEntry.setEpub(Files.readAllBytes(path)); } if (path.toString().contains(".jpg")) { bookEntry.setCover(Files.readAllBytes(path)); ByteArrayOutputStream output = new ByteArrayOutputStream(); Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover())).size(130, 200) .toOutputStream(output); bookEntry.setThumbnail(output.toByteArray()); bookEntry.setThumbnailGenerated("done"); } } } if (bookEntry.getMobi() != null || bookEntry.getEpub() != null) { bookEntries.add(bookEntry); if (bookEntries.size() > batchSize) { logger.info("Adding " + bookEntries.size() + " Books..."); try { solrHandler.addBeans(bookEntries); } catch (SolrServerException ex) { logger.error(ex, ex); } bookEntries.clear(); } } } catch (IOException ex) { logger.error(ex, ex); } return super.preVisitDirectory(dir, attrs); } }); try { if (!bookEntries.isEmpty()) { logger.info("Adding " + bookEntries.size() + " Books..."); solrHandler.addBeans(bookEntries); } } catch (SolrServerException ex) { logger.error(ex, ex); } } finally { Files.delete(zipFile); } }
From source file:jodtemplate.pptx.ImageService.java
private Relationship getImageRelationship(final Image image, final Slide slide) { final Path imageFullPath = Paths.get(image.getFullPath()); final Path slideFullPath = Paths.get(FilenameUtils .getFullPath(slide.getPresentation().getFullPath() + slide.getRelationship().getTarget())); final Path relativeImagePath = slideFullPath.relativize(imageFullPath); final String normRelativeImagePath = FilenameUtils.separatorsToUnix(relativeImagePath.toString()); Relationship imageRel = slide.getRelationshipByTarget(normRelativeImagePath); if (imageRel == null) { imageRel = new Relationship(); imageRel.setId(slide.getNextId()); imageRel.setTarget(normRelativeImagePath); imageRel.setType(Relationship.IMAGE_TYPE); slide.addOtherRelationship(imageRel); }//from w w w . j a va2s . c o m return imageRel; }
From source file:com.streamsets.pipeline.lib.io.FileContext.java
public FileContext(MultiFileInfo multiFileInfo, Charset charset, int maxLineLength, PostProcessingOptions postProcessing, String archiveDir, FileEventPublisher eventPublisher) throws IOException { open = true;/*from www.j av a2 s . c o m*/ this.multiFileInfo = multiFileInfo; this.charset = charset; this.maxLineLength = maxLineLength; this.postProcessing = postProcessing; this.archiveDir = archiveDir; this.eventPublisher = eventPublisher; Path fullPath = Paths.get(multiFileInfo.getFileFullPath()); dir = fullPath.getParent(); Path name = fullPath.getFileName(); rollMode = multiFileInfo.getFileRollMode().createRollMode(name.toString(), multiFileInfo.getPattern()); scanner = new LiveDirectoryScanner(dir.toString(), multiFileInfo.getFirstFile(), getRollMode()); }
From source file:de.teamgrit.grit.checking.testing.JavaProjectTester.java
/** * Creates the fully qualified name of a class based on its location * relative to a base directory./*w w w .ja v a 2 s.co m*/ * * @param basePath * the base path * @param subPath * the path to the classfile, must be a located bellow basepath * in the directory tree * @return the fully name of the class */ private String getQuallifiedName(Path basePath, Path subPath) { // relative resolution String quallifiedName = StringUtils.difference(basePath.toString(), subPath.toString()); quallifiedName = quallifiedName.substring(1); quallifiedName = FilenameUtils.removeExtension(quallifiedName); quallifiedName = StringUtils.replaceChars(quallifiedName, '/', '.'); return quallifiedName; }
From source file:dk.ekot.misc.SynchronizedCacheTest.java
@Test public void testHammering() throws InterruptedException { final int THREADS = 20; final List<String> copied = new ArrayList<>(); final SynchronizedCache sc = new SynchronizedCache() { @Override/*from w ww . j a va2 s . c o m*/ protected void copy(Path fullSourcePath, Path fullCachePath) throws IOException { try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } copied.add(fullCachePath.toString()); } }; for (int t = 0; t < THREADS; t++) { // Test-copies take ~25ms. Every fifth "copy" should this be processed without delay final String dest = t % 5 == 0 ? "fifth" : "same"; new Thread(() -> { try { sc.add(Paths.get("foo"), Paths.get(dest)); } catch (IOException e) { e.printStackTrace(); } }).start(); Thread.sleep(5); } Thread.sleep(1000); // It should take 19*20ms log.debug("Mock file copy order: " + copied); // There are 4 'fifth's and 16 'same'. As the two groups should be processed practically independently, // The 4 'fifth's should be in the first half of the copied list int fifths = 0; for (int i = 0; i < THREADS / 2; i++) { if ("fifth".equals(copied.get(i))) { fifths++; } } assertEquals("There should be " + THREADS / 5 + " \"copies\" of the file 'fifth' among the first " + THREADS / 2 + " files \"copied\"\n" + copied, THREADS / 5, fifths); }
From source file:it.sonarlint.cli.tools.SonarlintInstaller.java
private Path locateZipInLocalMaven(String version) { String fileName = "sonarlint-cli-" + version + ".zip"; LOG.info("Searching for SonarLint CLI {} in maven repositories", version); Path mvnRepo = getMavenLocalRepository(); Path file = getMavenFilePath(mvnRepo, GROUP_ID, ARTIFACT_ID, version, fileName); if (!Files.exists(file)) { throw new IllegalArgumentException("Couldn't find in local repo: sonarlint cli " + file.toString()); }// w ww .j av a 2 s . c o m return file; }