List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:com.sastix.cms.server.services.content.impl.ZipHandlerServiceImpl.java
public String findScormStartPage(final Path metadataPath) { Document doc;/* ww w . j a v a 2s .c om*/ try { doc = Jsoup.parse(new String(Files.readAllBytes(metadataPath), "UTF-8"), "", Parser.xmlParser()); } catch (final IOException e) { throw new ResourceAccessError("Zip " + metadataPath.getFileName() + " cannot be read. "); } String startPage = null; for (Element e : doc.select("resources")) { startPage = e.select("resource").get(0).attr("href"); } if (startPage == null) { throw new ResourceAccessError("Start page in Zip " + metadataPath.getFileName() + " cannot be found"); } return startPage; }
From source file:org.ng200.openolympus.cerberus.DefaultSolutionJudge.java
@Override public void compile(final List<Path> sources, Properties properties) { synchronized (this.compiled) { this.baseResultBuilder.compileStage(() -> { if (sources.size() != 1) { throw new IllegalArgumentException("DefaultSolutionJudge only supports one source file!"); }// www. j av a2 s.co m final Path sourceFile = sources.get(0); if (sourceFile.getFileName().toString().endsWith(".cpp")) { final Path temporaryCopy = this.sharedStorage.getPath().resolve("main.cpp"); FileAccess.copy(sources.get(0), temporaryCopy); this.programLanguage = ProgramLanguage.CPP; return this.compileCpp(temporaryCopy); } else if (sourceFile.getFileName().toString().endsWith(".pas")) { final Path temporaryCopy = this.sharedStorage.getPath().resolve("main.pas"); FileAccess.copy(sources.get(0), temporaryCopy); this.programLanguage = ProgramLanguage.FPC; return this.compileFpc(temporaryCopy); } else if (sourceFile.getFileName().toString().endsWith(".java")) { final Path temporaryCopy = this.sharedStorage.getPath().resolve("Main.java"); FileAccess.copy(sources.get(0), temporaryCopy); this.programLanguage = ProgramLanguage.JAVA; return this.compileJava(temporaryCopy); } else { return new CompilerResult(CompilerResult.CompileResultType.COMPILE_ERROR, new CompilerError("Unknown file type", "Please check the file type.")); } }); } }
From source file:at.tfr.securefs.Configuration.java
public String getSalt(Path path) { if (path == null) { return salt; }/*from w w w .ja v a 2 s . com*/ return path.getFileName().toString(); }
From source file:com.yahoo.parsec.gradle.ParsecInitTask.java
/** * Execute./*from ww w.j a va2 s.c om*/ * * @throws TaskExecutionException TaskExecutionException */ @TaskAction public void executeTask() throws TaskExecutionException { try { // Create ${buildDir}/bin fileUtils.checkAndCreateDirectory(pathUtils.getBinPath()); String rdlBinSuffix = System.getProperty("os.name").equals("Mac OS X") ? "darwin" : "linux"; // Extract rdl to ${buildDir}/bin File file = fileUtils.getFileFromResource("/rdl-bin/rdl-bin.zip"); try (ZipFile zipFile = new ZipFile(file); InputStream inputStream = zipFile .getInputStream(zipFile.getEntry(PathUtils.RDL_BINARY + "-" + rdlBinSuffix))) { fileUtils.writeResourceAsExecutable(inputStream, pathUtils.getRdlBinaryPath()); } extractParsecRdlGenerator(rdlBinSuffix, Arrays.asList("java-model", "java-server", "java-client", "swagger")); // Create ${baseDir}/parsec-bin fileUtils.checkAndCreateDirectory(pathUtils.getBinPath()); // Copy all scripts under resource/scripts to ${baseDir}/parsec-bin for (Path scriptPath : fileUtils.listDirFilePaths("scripts")) { String scriptPathString = scriptPath.toString(); if (scriptPathString.endsWith(".sh") || scriptPathString.endsWith(".rb")) { fileUtils.writeResourceAsExecutable(scriptPath.toString(), pathUtils.getBinPath() + "/" + scriptPath.getFileName()); } } String test = pathUtils.getBinPath(); if (pluginExtension.isGenerateSwagger()) { String swaggerUIPath = pathUtils.getSwaggerUIPath(); // Create ${buildDir}/generated-resources/swagger-ui fileUtils.checkAndCreateDirectory(swaggerUIPath); // Extract swagger-ui archive if ${buildDir}/generated-resources/swagger-ui is empty if (new File(swaggerUIPath).list().length <= 0) { fileUtils.unTarZip("/swagger-ui/swagger-ui.tgz", swaggerUIPath, true); } } } catch (IOException e) { throw new TaskExecutionException(this, e); } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public boolean startsWith(Path other) { if (other.isAbsolute() != isAbsolute()) { return false; } else if (other.getNameCount() > getNameCount()) { return false; } else {//from ww w. j ava 2 s .c om for (int idx = 0; idx < other.getNameCount(); idx++) { Path otherElem = other.getName(idx); if (otherElem.getFileName().equals(this.elements.get(idx))) { return false; } } return true; } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public boolean endsWith(Path other) { int offset = getNameCount() - other.getNameCount(); if (offset < 0) { return false; } else {/*from ww w. ja v a 2 s. c om*/ for (int idx = getNameCount() - 1; idx - offset >= 0; idx--) { Path otherElem = other.getName(idx - offset); if (otherElem.getFileName().equals(this.elements.get(idx))) { return false; } } return true; } }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java
private void extractRar(ActionDescription aAction, Path aCachedFile, Path aTarget) throws IOException, RarException { // We always extract archives into a subfolder. Figure out the name of the folder. String base = getBase(aCachedFile.getFileName().toString()); Map<String, Object> cfg = aAction.getConfiguration(); int strip = cfg.containsKey("strip") ? (int) cfg.get("strip") : 0; AntFileFilter filter = new AntFileFilter(coerceToList(cfg.get("includes")), coerceToList(cfg.get("excludes"))); try (Archive archive = new Archive(new FileVolumeManager(aCachedFile.toFile()))) { FileHeader fh = archive.nextFileHeader(); while (fh != null) { String name = stripLeadingFolders(fh.getFileNameString(), strip); if (name == null) { // Stripped to null - nothing left to extract - continue; continue; }/* www .ja v a 2s .c o m*/ if (filter.accept(name)) { Path out = aTarget.resolve(base).resolve(name); if (fh.isDirectory()) { Files.createDirectories(out); } else { Files.createDirectories(out.getParent()); try (OutputStream os = Files.newOutputStream(out)) { archive.extractFile(fh, os); } } } fh = archive.nextFileHeader(); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java
private void extract7z(ActionDescription aAction, Path aCachedFile, Path aTarget) throws IOException, RarException { // We always extract archives into a subfolder. Figure out the name of the folder. String base = getBase(aCachedFile.getFileName().toString()); Map<String, Object> cfg = aAction.getConfiguration(); int strip = cfg.containsKey("strip") ? (int) cfg.get("strip") : 0; AntFileFilter filter = new AntFileFilter(coerceToList(cfg.get("includes")), coerceToList(cfg.get("excludes"))); try (SevenZFile archive = new SevenZFile(aCachedFile.toFile())) { SevenZArchiveEntry entry = archive.getNextEntry(); while (entry != null) { String name = stripLeadingFolders(entry.getName(), strip); if (name == null) { // Stripped to null - nothing left to extract - continue; continue; }// w w w. jav a2 s. c om if (filter.accept(name)) { Path out = aTarget.resolve(base).resolve(name); if (entry.isDirectory()) { Files.createDirectories(out); } else { Files.createDirectories(out.getParent()); try (OutputStream os = Files.newOutputStream(out)) { InputStream is = new SevenZEntryInputStream(archive, entry); IOUtils.copyLarge(is, os); } } } entry = archive.getNextEntry(); } } }
From source file:com.htmlhifive.visualeditor.persister.LocalFileContentsPersister.java
/** * ????./*from w ww .j a v a2s . com*/ * * @param metadata ?urlTree * @param ctx urlTree */ @Override public void delete(UrlTreeMetaData<InputStream> metadata, UrlTreeContext ctx) throws BadContentException { Path f = generateFileObj(metadata.getAbsolutePath()); logger.debug("delete: " + f.getFileName()); try { boolean deleted = Files.deleteIfExists(f); if (!deleted) { throw new IOException("file not exists"); } } catch (IOException e) { // TargetNotFound???BadContent??? throw new GenericResourceException("cannot delete file", e); } }
From source file:net.sf.jabref.logic.exporter.ExportFormat.java
@Override public void performExport(final BibDatabaseContext databaseContext, Path file, final Charset encoding, List<BibEntry> entries) throws Exception { performExport(databaseContext, file.getFileName().toString(), encoding, entries); }