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

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

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

FilenameUtils.separatorsToSystem介绍

[英]Converts all separators to the system separator.
[中]将所有分隔符转换为系统分隔符。

代码示例

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

protected void removeLocalCacheFiles(final String resourceName, String baseDirectory) {
  String systemResourcePath = FilenameUtils.separatorsToSystem(resourceName);
  String filePath = FilenameUtils.normalize(baseDirectory + File.separator + systemResourcePath);
  if (filePath.contains(".")) {
    filePath = filePath.substring(0, filePath.lastIndexOf("."));
  }
  filePath += "---";
  final String checkPath = filePath;
  File dir = new File(baseDirectory);
  File[] children = dir.listFiles(new FileFilter() {
    @Override
    public boolean accept(File pathname) {
      String name = pathname.getAbsolutePath();
      return name.startsWith(checkPath);
    }
  });
  for (File cache : children) {
    FileUtils.deleteQuietly(cache);
  }
}

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

@Test
public void testSeparatorsToSystem() {
  if (WINDOWS) {
    assertEquals(null, FilenameUtils.separatorsToSystem(null));
    assertEquals("\\a\\b\\c", FilenameUtils.separatorsToSystem("\\a\\b\\c"));
    assertEquals("\\a\\b\\c.txt", FilenameUtils.separatorsToSystem("\\a\\b\\c.txt"));
    assertEquals("\\a\\b\\c", FilenameUtils.separatorsToSystem("\\a\\b/c"));
    assertEquals("\\a\\b\\c", FilenameUtils.separatorsToSystem("/a/b/c"));
    assertEquals("D:\\a\\b\\c", FilenameUtils.separatorsToSystem("D:/a/b/c"));
  } else {
    assertEquals(null, FilenameUtils.separatorsToSystem(null));
    assertEquals("/a/b/c", FilenameUtils.separatorsToSystem("/a/b/c"));
    assertEquals("/a/b/c.txt", FilenameUtils.separatorsToSystem("/a/b/c.txt"));
    assertEquals("/a/b/c", FilenameUtils.separatorsToSystem("/a/b\\c"));
    assertEquals("/a/b/c", FilenameUtils.separatorsToSystem("\\a\\b\\c"));
    assertEquals("D:/a/b/c", FilenameUtils.separatorsToSystem("D:\\a\\b\\c"));
  }
}

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

protected void saveBundle(Resource resource) {
  FileWorkArea tempWorkArea = fileService.initializeWorkArea();
  String fileToSave = FilenameUtils.separatorsToSystem(getResourcePath(resource.getDescription()));
  String tempFilename = FilenameUtils.concat(tempWorkArea.getFilePathLocation(), fileToSave);
  File tempFile = new File(tempFilename);

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

FileWorkArea tempWorkArea = broadleafFileService.initializeWorkArea();
String destFileName = FilenameUtils.normalize(tempWorkArea.getFilePathLocation() + File.separator + FilenameUtils.separatorsToSystem(staticAsset.getFullUrl()));

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

protected File getLocalResource(String resourceName, boolean skipSite) {
  if (skipSite) {
    String baseDirectory = getBaseDirectory(skipSite);
    // convert the separators to the system this is currently run on
    String systemResourcePath = FilenameUtils.separatorsToSystem(resourceName);
    String filePath = FilenameUtils.normalize(baseDirectory + File.separator + systemResourcePath);
    return new File(filePath);
  } else {
    String baseDirectory = getBaseDirectory(true);
    ExtensionResultHolder<String> holder = new ExtensionResultHolder<String>();
    if (extensionManager != null) {
      ExtensionResultStatusType result = extensionManager.getProxy().processPathForSite(baseDirectory, resourceName, holder);
      if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
        return new File(holder.getResult());
      }
    }
    return getLocalResource(resourceName, true);
  }
}

代码示例来源:origin: simpligility/android-maven-plugin

configHandler.parseConfiguration();
parsedInputApk = FilenameUtils.separatorsToSystem( parsedInputApk );
parsedOutputApk = FilenameUtils.separatorsToSystem( parsedOutputApk );

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

/**
 * 把文件路径中的分隔符转换当前系统的分隔符
 *
 * @param path
 *            文件完整路径
 * @return 转换后的路径
 */
public static String separatorsToSystem(String path) {
  return FilenameUtils.separatorsToSystem(path);
}

代码示例来源:origin: org.jboss.windup.reporting/windup-reporting-impl

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
  {
    String relativePath = StringUtils.substringAfter(file.toString(), path.toString());
    // needed on windows, as for some reason the path from a zip still uses s'/' sometimes
    relativePath = FilenameUtils.separatorsToSystem(relativePath);
    relativePath = StringUtils.removeStart(relativePath, File.separator);
    Path resultFile = resultPath.resolve(relativePath);
    FileUtils.forceMkdir(resultFile.getParent().toFile());
    Files.copy(file, resultFile, StandardCopyOption.REPLACE_EXISTING);
    return FileVisitResult.CONTINUE;
  }
});

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

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
  {
    String relativePath = StringUtils.substringAfter(file.toString(), path.toString());
    // needed on windows, as for some reason the path from a zip still uses s'/' sometimes
    relativePath = FilenameUtils.separatorsToSystem(relativePath);
    relativePath = StringUtils.removeStart(relativePath, File.separator);
    Path resultFile = resultPath.resolve(relativePath);
    FileUtils.forceMkdir(resultFile.getParent().toFile());
    Files.copy(file, resultFile, StandardCopyOption.REPLACE_EXISTING);
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: com.googlecode.the-fascinator/fascinator-common

/**
 * Gets a relative directory inside the Fascinator home directory.
 * 
 * @param subDir the directory name
 * @return a directory path
 */
public static String getPath(String subDir) {
  return getPath() + File.separator
      + FilenameUtils.separatorsToSystem(subDir);
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.keyphrases/de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing-gpl

private String getPath(String baseName)
{
  return FilenameUtils.separatorsToSystem(FilenameUtils.concat(pathName,
      baseName)
      + ((suffix.startsWith(".")) ? suffix : "." + suffix));
}

代码示例来源:origin: Jasig/uPortal

private String fixAntPattern(String pattern) {
  pattern = FilenameUtils.separatorsToSystem(pattern);
  if (!SelectorUtils.hasWildcards(pattern)) {
    pattern = "**" + File.separatorChar + pattern;
  }
  return pattern;
}

代码示例来源:origin: org.jasig.portal/uPortal-utils-core

private String fixAntPattern(String pattern) {
  pattern = FilenameUtils.separatorsToSystem(pattern);
  if (!SelectorUtils.hasWildcards(pattern)) {
    pattern = "**" + File.separatorChar + pattern;
  }
  return pattern;
}

代码示例来源:origin: org.sonarsource.java/java-squid

public WilcardPatternFileFilter(File baseDir, String wildcardPattern) {
 this.baseDir = baseDir;
 this.wildcardPattern = WildcardPattern.create(FilenameUtils.separatorsToSystem(wildcardPattern), File.separator);
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-squid

public WilcardPatternFileFilter(File baseDir, String wildcardPattern) {
 this.baseDir = baseDir;
 this.wildcardPattern = WildcardPattern.create(FilenameUtils.separatorsToSystem(wildcardPattern), File.separator);
}

代码示例来源:origin: danielflower/app-runner

private File ensureExists(String relativePath) {
    String path = FilenameUtils.concat(fullPath(root), FilenameUtils.separatorsToSystem(relativePath));
    File f = new File(path);
    f.mkdirs();
    return f;
  }
}

代码示例来源:origin: qwazer/scheme2ddl

public void writeUserObject(UserObject userObject) throws Exception {
  String absoluteFileName = outputPath + "/" +  userObject.getFileName();
  absoluteFileName = FilenameUtils.separatorsToSystem(absoluteFileName);
  File file = new File(absoluteFileName);
  FileUtils.writeStringToFile(file, userObject.getDdl());
  log.info(String.format("Saved %s %s.%s to file %s",
      userObject.getType().toLowerCase(),
      userObject.getSchema().toLowerCase(),
      userObject.getName().toLowerCase(),
      file.getAbsolutePath()));
}

代码示例来源:origin: epam/Wilma

@Test
public void testGetConfigPathsFromSpecificFolderWhenThePatternIsASpecificFileNameAndThisIsInASpecificFolder() {
  //GIVEN
  expectedFilePaths = new ArrayList<>();
  expectedFilePaths.add(FilenameUtils.separatorsToSystem("test/path/TestPattern"));
  //WHEN
  List<String> result = underTest.getConfigPathsFromSpecificFolder("test/path", "TestPattern");
  //THEN
  Assert.assertEquals(result, expectedFilePaths);
}

代码示例来源:origin: epam/Wilma

@Test
public void testCreateZipWithFilesWhenFilePathContainsBackSlashes() throws IOException {
  //GIVEN
  List<String> pair = new ArrayList<String>();
  pair.add(FilenameUtils.separatorsToSystem("src\\test\\resources\\first_testreq.txt"));
  filePaths.add(pair);
  //WHEN
  underTest.createZipWithFiles(filePaths, outputStream);
  //THEN
  verify(entryFactory).createZipEntry("first_testreq.txt");
  verify(zipOutputStream).putNextEntry(zipEntry);
  verify(zipOutputStream).close();
}

代码示例来源:origin: bonitasoft/bonita-engine

@Test
public void getFolderFromConfiguration_should_work_for_platform_level_folder() throws Exception {
  // given:
  final Path setupFolder = temporaryFolder.newFolder().toPath();
  System.setProperty(BONITA_SETUP_FOLDER, setupFolder.toString());
  platformSetup.initProperties();
  LightBonitaConfiguration configuration = new LightBonitaConfiguration(0L, "some_folder");
  // when:
  final Path folder = platformSetup.getFolderFromConfiguration(configuration);
  // then:
  assertThat(folder.toString())
      .isEqualTo(separatorsToSystem(setupFolder.toString() + "/platform_conf/current/some_folder"));
}

相关文章