slash.common.io.Files.lastPathFragment()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(84)

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

Files.lastPathFragment介绍

暂无

代码示例

代码示例来源:origin: cpesch/RouteConverter

public static String lastPathFragment(String path, int maximumLength) {
  return lastPathFragment(path, maximumLength, false);
}

代码示例来源:origin: cpesch/RouteConverter

public static String shortenPath(String path, int maximumLength) {
  if (path.length() <= maximumLength)
    return path;
  String lastPathFragment = lastPathFragment(path, maximumLength, true);
  if (lastPathFragment.length() == maximumLength)
    return lastPathFragment;
  return path.substring(0, maximumLength - 3 - lastPathFragment.length()) + "..." + lastPathFragment;
}

代码示例来源:origin: cpesch/RouteConverter

public String getShortUrl() {
    String string = trim(getString());
    return string != null ? lastPathFragment(string, 60) : null;
  }
}

代码示例来源:origin: cpesch/RouteConverter

private void doExtract(File tempFile, File destination, boolean flatten) throws IOException {
  try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(tempFile))) {
    ZipEntry entry = zipInputStream.getNextEntry();
    while (entry != null) {
      if (entry.isDirectory()) {
        if (!flatten) {
          File directory = new File(destination, entry.getName());
          handleDirectory(directory, entry);
        }
      } else {
        File extracted;
        if(flatten)
          extracted = new File(destination, lastPathFragment(entry.getName(), MAX_VALUE));
        else {
          extracted = new File(destination, entry.getName());
        }
        File directory = extracted.getParentFile();
        handleDirectory(directory, entry);
        log.info(format("Extracting from %s to %s", tempFile, extracted));
        FileOutputStream output = new FileOutputStream(extracted);
        new Copier(listener).copy(zipInputStream, output, 0, entry.getSize());
        // do not close zip input stream
        closeQuietly(output);
        setLastModified(extracted, fromMillis(entry.getTime()));
        zipInputStream.closeEntry();
      }
      entry = zipInputStream.getNextEntry();
    }
  }
}

代码示例来源:origin: cpesch/RouteConverter

@Test
public void testLastPathFragment() {
  assertEquals("file.gpx", lastPathFragment("file.gpx", 60));
  assertEquals("file.gpx", lastPathFragment("../file.gpx", 60));
  assertEquals("file.gpx", lastPathFragment("c:\\bla\\bla\\file.gpx", 60));
  assertEquals("file.gpx", lastPathFragment("c:/bla/bla/file.gpx", 60));
  assertEquals("file.gpx", lastPathFragment("file:///c:/bla/bla/file.gpx", 60));
  assertEquals("file.gpx", lastPathFragment("http://www.blabla.com/bla/bla/file.gpx", 60));
  assertEquals("...file.gpx", lastPathFragment("superlongfilenameforfile.gpx", 11));
  assertEquals(11, lastPathFragment("superlongfilenameforfile.gpx", 11).length());
  assertEquals("...l=54.105307,13.490181&sspn=0.132448,0.318604&ie=UTF8&z=12",
      lastPathFragment("http://maps.google.de/maps?f=d&hl=de&geocode=14250095960720490931,54.0831601,13.475246%3B13832872253745319564,54.096925,13.383573%3B4731465831403354564,54.114440,13.528310&saddr=54.096925,+13.383573&daddr=54.08316,13.475246+to:54.114440,+13.528310&mra=ps&mrcr=0,1&sll=54.105307,13.490181&sspn=0.132448,0.318604&ie=UTF8&z=12", 60));
}

相关文章