org.apache.commons.io.FilenameUtils.getFullPathNoEndSeparator()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中org.apache.commons.io.FilenameUtils.getFullPathNoEndSeparator()方法的一些代码示例,展示了FilenameUtils.getFullPathNoEndSeparator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.getFullPathNoEndSeparator()方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:getFullPathNoEndSeparator

FilenameUtils.getFullPathNoEndSeparator介绍

[英]Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before the last forward or backslash.

C:\a\b\c.txt --> C:\a\b 
~/a/b/c.txt  --> ~/a/b 
a.txt        --> "" 
a/b/c        --> a/b 
a/b/c/       --> a/b/c 
C:           --> C: 
C:\          --> C:\ 
~            --> ~ 
~/           --> ~ 
~user        --> ~user 
~user/       --> ~user

The output will be the same irrespective of the machine that the code is running on.
[中]

代码示例

代码示例来源:origin: eirslett/frontend-maven-plugin

@Override
public void download(String downloadUrl, String destination, String userName, String password) throws DownloadException {
  // force tls to 1.2 since github removed weak cryptographic standards
  // https://blog.github.com/2018-02-02-weak-cryptographic-standards-removal-notice/
  System.setProperty("https.protocols", "TLSv1.2");
  String fixedDownloadUrl = downloadUrl;
  try {
    fixedDownloadUrl = FilenameUtils.separatorsToUnix(fixedDownloadUrl);
    URI downloadURI = new URI(fixedDownloadUrl);
    if ("file".equalsIgnoreCase(downloadURI.getScheme())) {
      FileUtils.copyFile(new File(downloadURI), new File(destination));
    }
    else {
      CloseableHttpResponse response = execute(fixedDownloadUrl, userName, password);
      int statusCode = response.getStatusLine().getStatusCode();
      if(statusCode != 200){
        throw new DownloadException("Got error code "+ statusCode +" from the server.");
      }
      new File(FilenameUtils.getFullPathNoEndSeparator(destination)).mkdirs();
      ReadableByteChannel rbc = Channels.newChannel(response.getEntity().getContent());
      FileOutputStream fos = new FileOutputStream(destination);
      fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
      fos.close();
    }
  } catch (IOException | URISyntaxException e) {
    throw new DownloadException("Could not download " + fixedDownloadUrl, e);
  }
}

代码示例来源:origin: commons-io/commons-io

/**
 * Test for https://issues.apache.org/jira/browse/IO-248
 */
@Test
public void testGetFullPathNoEndSeparator_IO_248() {
  // Test single separator
  assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/"));
  assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\"));
  // Test one level directory
  assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/abc"));
  assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\abc"));
  // Test one level directory
  assertEquals("/abc", FilenameUtils.getFullPathNoEndSeparator("/abc/xyz"));
  assertEquals("\\abc", FilenameUtils.getFullPathNoEndSeparator("\\abc\\xyz"));
}

代码示例来源:origin: skylot/jadx

@Override
public void init(RootNode root) {
  List<DexNode> dexNodes = root.getDexNodes();
  if (dexNodes.isEmpty()) {
    return;
  }
  InputFile firstInputFile = dexNodes.get(0).getDexFile().getInputFile();
  String firstInputFileName = firstInputFile.getFile().getAbsolutePath();
  String inputPath = FilenameUtils.getFullPathNoEndSeparator(firstInputFileName);
  String inputName = FilenameUtils.getBaseName(firstInputFileName);
  File deobfMapFile = new File(inputPath, inputName + ".jobf");
  JadxArgs args = root.getArgs();
  deobfuscator = new Deobfuscator(args, dexNodes, deobfMapFile);
  boolean deobfuscationOn = args.isDeobfuscationOn();
  if (deobfuscationOn) {
    deobfuscator.execute();
  }
  boolean isCaseSensitive = FileUtils.isCaseSensitiveFS(new File(inputPath)); // args.getOutDir() - not set in gui
  checkClasses(root, isCaseSensitive);
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testGetFullPathNoEndSeparator() {
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator(null));
  assertEquals("", FilenameUtils.getFullPathNoEndSeparator("noseperator.inthispath"));
  assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c.txt"));
  assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c"));
  assertEquals("a/b/c", FilenameUtils.getFullPathNoEndSeparator("a/b/c/"));
  assertEquals("a\\b", FilenameUtils.getFullPathNoEndSeparator("a\\b\\c"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator(":"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:/a/b/c.txt"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("1:a"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("///a/b/c.txt"));
  assertEquals(null, FilenameUtils.getFullPathNoEndSeparator("//a"));
  assertEquals("", FilenameUtils.getFullPathNoEndSeparator(""));
  assertEquals("C:", FilenameUtils.getFullPathNoEndSeparator("C:"));
  assertEquals("C:/", FilenameUtils.getFullPathNoEndSeparator("C:/"));
  assertEquals("//server/", FilenameUtils.getFullPathNoEndSeparator("//server/"));
  assertEquals("~", FilenameUtils.getFullPathNoEndSeparator("~"));
  assertEquals("~/", FilenameUtils.getFullPathNoEndSeparator("~/"));
  assertEquals("~user", FilenameUtils.getFullPathNoEndSeparator("~user"));
  assertEquals("~user/", FilenameUtils.getFullPathNoEndSeparator("~user/"));
  assertEquals("a/b", FilenameUtils.getFullPathNoEndSeparator("a/b/c.txt"));
  assertEquals("/a/b", FilenameUtils.getFullPathNoEndSeparator("/a/b/c.txt"));
  assertEquals("C:", FilenameUtils.getFullPathNoEndSeparator("C:a"));
  assertEquals("C:a/b", FilenameUtils.getFullPathNoEndSeparator("C:a/b/c.txt"));
  assertEquals("C:/a/b", FilenameUtils.getFullPathNoEndSeparator("C:/a/b/c.txt"));

代码示例来源:origin: geotools/geotools

@SuppressWarnings("PMD.SystemPrintln")
private static String setOuputFolder(String[] args, File sampleFile) {
  String outputPath = FilenameUtils.getFullPathNoEndSeparator(sampleFile.getAbsolutePath());
  if (args.length > 3) {
    outputPath = args[3];
    System.out.println("Output folder has been specified: " + outputPath);
    final File outputFolder = new File(outputPath);
    if (!outputFolder.exists()) {
      System.out.println("Creating it");
      outputFolder.mkdirs();
    }
  } else {
    System.out.println(
        "Output folder hasn't been specified. The files will be created beside the sample file, at: "
            + outputPath);
  }
  return outputPath;
}

代码示例来源:origin: org.javabeanstack/jbs-commons

/**
 * Devuelve el path de un archivo ejemplo c:/carpeta1/subcarpeta1/archivo.txt
 * retorna /carpeta1/subcarpeta1
 * @param file nombre y path del archivo
 * @return el path del archivo
 */
public static String getFullPathNoEndSeparator(String file){
  return FilenameUtils.getFullPathNoEndSeparator(file);
}

代码示例来源:origin: zhoulychn/mybatis-generator

/**
 * 获得文件的完整路径,不包含最后的路径分隔条
 *
 * @param filename
 *            文件完整路径
 * @return
 */
public static String getFullPathNoEndSeparator(String filename) {
  return FilenameUtils.getFullPathNoEndSeparator(filename);
}

代码示例来源:origin: org.nuiton.js/nuiton-js-wro

/**
   * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root.
   * <p/>
   * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>.
   */
  private String getFullPathNoEndSeparator(final String uri) {
    String result = FilenameUtils.getFullPathNoEndSeparator(uri);
    if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result))
      return "";
    
    return result;
  }
};

代码示例来源:origin: ru.lanwen.raml/rarc-core

public static String addedObjectPackage(String uri) {
  String path = FilenameUtils.getFullPathNoEndSeparator(uri);
  if (path.isEmpty()) {
    return EMPTY;
  }
  return "." + packageName(path);
}

代码示例来源:origin: creactiviti/piper

@Override
public Object handle (Task aTask) {
 return FilenameUtils.getFullPathNoEndSeparator(aTask.getRequiredString("filename"));
}

代码示例来源:origin: alexo/wro4j

/**
  * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root.
  * <p/>
  * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>.
  */
 private String getFullPathNoEndSeparator(final Resource resource) {
  final String result = FilenameUtils.getFullPathNoEndSeparator(resource.getUri());
  if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result)) {
   return "";
  }
  return result;
 }
};

代码示例来源:origin: ro.isdc.wro4j/wro4j-core

/**
  * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root.
  * <p/>
  * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>.
  */
 private String getFullPathNoEndSeparator(final Resource resource1) {
  final String result = FilenameUtils.getFullPathNoEndSeparator(resource1.getUri());
  if (result != null && 1 == result.length() && 0 == FilenameUtils.indexOfLastSeparator(result)) {
   return "";
  }
  return result;
 }
};

代码示例来源:origin: org.eobjects.datacleaner/DataCleaner-monitor-services

private FileAlterationObserver createObserver(String fileName) {
  final File file = new File(fileName);
  if (file.isDirectory()) {
    return new FileAlterationObserver(file);
  } else {
    return new FileAlterationObserver(FilenameUtils.getFullPathNoEndSeparator(fileName), FileFilterUtils
        .nameFileFilter(FilenameUtils.getName(fileName)));
  }
}

代码示例来源:origin: alexo/wro4j

/**
 * @return an input stream for an uri containing a wildcard for a given location.
 */
private InputStream locateWildcardStream(final String uri, final String location)
  throws IOException {
 LOG.debug("wildcard detected for location: {}", location);
 // prefix with '/' because we use class relative resource retrieval. Using ClassLoader.getSystemResource doesn't
 // work well.
 final String fullPath = "/" + FilenameUtils.getFullPathNoEndSeparator(location);
 URL url = getClass().getResource(fullPath);
 LOG.debug("Attempting to find resource {} at the following location: {}", uri, fullPath);
 try {
  return locateWildcardStream(uri, url);
 } catch (final IOException e) {
  //do not attempt unless exception is of this type
  if (e instanceof NoMoreAttemptsIOException) {
   throw e;
  }
  // try once more, in order to treat classpath resources located in the currently built project.
  url = getClass().getResource("");
  LOG.debug("Attempting to find resource {} at the following URL: {}", uri, url);
  return locateWildcardStream(uri, url);
 }
}

代码示例来源:origin: ro.isdc.wro4j/wro4j-core

/**
 * @return an input stream for an uri containing a wildcard for a given location.
 */
private InputStream locateWildcardStream(final String uri, final String location)
  throws IOException {
 LOG.debug("wildcard detected for location: {}", location);
 // prefix with '/' because we use class relative resource retrieval. Using ClassLoader.getSystemResource doesn't
 // work well.
 final String fullPath = "/" + FilenameUtils.getFullPathNoEndSeparator(location);
 URL url = getClass().getResource(fullPath);
 LOG.debug("Attempting to find resource {} at the following location: {}", uri, fullPath);
 try {
  return locateWildcardStream(uri, url);
 } catch (final IOException e) {
  //do not attempt unless exception is of this type
  if (e instanceof NoMoreAttemptsIOException) {
   throw e;
  }
  // try once more, in order to treat classpath resources located in the currently built project.
  url = getClass().getResource("");
  LOG.debug("Attempting to find resource {} at the following URL: {}", uri, url);
  return locateWildcardStream(uri, url);
 }
}

代码示例来源:origin: org.apache.royale.compiler/compiler-common

/**
 * @return Path of the target's parent directory.
 */
public String getTargetFileDirectory()
{
  final String targetFile = getTargetFile();
  if (targetFile == null)
    return null;
  final String normalizedTargetFile = FilenameNormalization.normalize(targetFile);
  return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile);
}

代码示例来源:origin: apache/royale-compiler

/**
 * @return Path of the target's parent directory.
 */
public String getTargetFileDirectory()
{
  final String targetFile = getTargetFile();
  if (targetFile == null)
    return null;
  final String normalizedTargetFile = FilenameNormalization.normalize(targetFile);
  return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile);
}

代码示例来源:origin: org.apache.flex.flexjs.compiler/compiler

/**
 * @return Path of the target's parent directory.
 */
public String getTargetFileDirectory()
{
  final String targetFile = getTargetFile();
  if (targetFile == null)
    return null;
  final String normalizedTargetFile = FilenameNormalization.normalize(targetFile);
  return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile);
}

代码示例来源:origin: vmi/selenese-runner-java

private String getParentDir() {
  String filename = PathUtils.normalize(getFilename());
  if (filename == null)
    return null;
  return FilenameUtils.getFullPathNoEndSeparator(filename);
}

代码示例来源:origin: mbok/logsniffer

protected Log[] getPastLogs(final String liveLog) throws IOException {
  final File dir = new File(FilenameUtils.getFullPathNoEndSeparator(liveLog));
  final String pastPattern = FilenameUtils.getName(liveLog) + getPastLogsSuffixPattern();
  final FileFilter fileFilter = new WildcardFileFilter(pastPattern);
  final File[] files = dir.listFiles(fileFilter);
  final FileLog[] logs = new FileLog[files.length];
  Arrays.sort(files, getPastLogsType().getPastComparator());
  int i = 0;
  for (final File file : files) {
    // TODO Decouple direct file log association
    logs[i++] = new FileLog(file);
  }
  logger.debug("Found {} past logs for {} with pattern {}", logs.length, liveLog, pastPattern);
  return logs;
}

相关文章