cn.hutool.core.util.StrUtil.addSuffixIfNot()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(238)

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

StrUtil.addSuffixIfNot介绍

[英]如果给定字符串不是以suffix结尾的,在尾部补充 suffix
[中]如果给定字符串不是以后缀结尾的,在尾部补充 后缀

代码示例

代码示例来源:origin: looly/hutool

/**
 * 构造
 * 
 * @param packageName 包名,所有包传入""或者null
 * @param classFilter 过滤器,无需传入null
 * @param charset 编码
 */
public ClassScaner(String packageName, Filter<Class<?>> classFilter, Charset charset) {
  packageName = StrUtil.nullToEmpty(packageName);
  this.packageName = packageName;
  this.packageNameWithDot = StrUtil.addSuffixIfNot(packageName, StrUtil.DOT);
  this.packageDirName = packageName.replace(CharUtil.DOT, File.separatorChar);
  this.packagePath = packageName.replace(CharUtil.DOT, CharUtil.SLASH);
  this.classFilter = classFilter;
  this.charset = charset;
}

代码示例来源:origin: looly/hutool

/**
 * 构造
 * 
 * @param packageName 包名,所有包传入""或者null
 * @param classFilter 过滤器,无需传入null
 * @param charset 编码
 */
public ClassScaner(String packageName, Filter<Class<?>> classFilter, Charset charset) {
  packageName = StrUtil.nullToEmpty(packageName);
  this.packageName = packageName;
  this.packageNameWithDot = StrUtil.addSuffixIfNot(packageName, StrUtil.DOT);
  this.packageDirName = packageName.replace(CharUtil.DOT, File.separatorChar);
  this.packagePath = packageName.replace(CharUtil.DOT, CharUtil.SLASH);
  this.classFilter = classFilter;
  this.charset = charset;
}

代码示例来源:origin: looly/hutool

/**
 * 在压缩包中新建目录
 * 
 * @param path 压缩的路径
 * @param out 压缩文件存储对象
 * @throws UtilException IO异常
 */
private static void addDir(String path, ZipOutputStream out) throws UtilException {
  path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
  try {
    out.putNextEntry(new ZipEntry(path));
  } catch (IOException e) {
    throw new UtilException(e);
  } finally {
    closeEntry(out);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 截取文件绝对路径中包名之前的部分
 * 
 * @param file 文件
 * @return 包名之前的部分
 */
private String subPathBeforePackage(File file) {
  String filePath = file.getAbsolutePath();
  if (StrUtil.isNotEmpty(this.packageDirName)) {
    filePath = StrUtil.subBefore(filePath, this.packageDirName, true);
  }
  return StrUtil.addSuffixIfNot(filePath, File.separator);
}
// --------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: looly/hutool

/**
 * 在压缩包中新建目录
 * 
 * @param path 压缩的路径
 * @param out 压缩文件存储对象
 * @throws UtilException IO异常
 */
private static void addDir(String path, ZipOutputStream out) throws UtilException {
  path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
  try {
    out.putNextEntry(new ZipEntry(path));
  } catch (IOException e) {
    throw new UtilException(e);
  } finally {
    closeEntry(out);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 截取文件绝对路径中包名之前的部分
 * 
 * @param file 文件
 * @return 包名之前的部分
 */
private String subPathBeforePackage(File file) {
  String filePath = file.getAbsolutePath();
  if (StrUtil.isNotEmpty(this.packageDirName)) {
    filePath = StrUtil.subBefore(filePath, this.packageDirName, true);
  }
  return StrUtil.addSuffixIfNot(filePath, File.separator);
}
// --------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 构造
 * 
 * @param packageName 包名,所有包传入""或者null
 * @param classFilter 过滤器,无需传入null
 * @param charset 编码
 */
public ClassScaner(String packageName, Filter<Class<?>> classFilter, Charset charset) {
  packageName = StrUtil.nullToEmpty(packageName);
  this.packageName = packageName;
  this.packageNameWithDot = StrUtil.addSuffixIfNot(packageName, StrUtil.DOT);
  this.packageDirName = packageName.replace(CharUtil.DOT, File.separatorChar);
  this.packagePath = packageName.replace(CharUtil.DOT, CharUtil.SLASH);
  this.classFilter = classFilter;
  this.charset = charset;
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 截取文件绝对路径中包名之前的部分
 * 
 * @param file 文件
 * @return 包名之前的部分
 */
private String subPathBeforePackage(File file) {
  String filePath = file.getAbsolutePath();
  if (StrUtil.isNotEmpty(this.packageDirName)) {
    filePath = StrUtil.subBefore(filePath, this.packageDirName, true);
  }
  return StrUtil.addSuffixIfNot(filePath, File.separator);
}
// --------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 在压缩包中新建目录
 * 
 * @param path 压缩的路径
 * @param out 压缩文件存储对象
 * @throws UtilException IO异常
 */
private static void addDir(String path, ZipOutputStream out) throws UtilException {
  path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
  try {
    out.putNextEntry(new ZipEntry(path));
  } catch (IOException e) {
    throw new UtilException(e);
  } finally {
    closeEntry(out);
  }
}

相关文章

微信公众号

最新文章

更多

StrUtil类方法