cn.hutool.core.lang.Assert.notBlank()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(2129)

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

Assert.notBlank介绍

[英]检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出 IllegalArgumentException

Assert.notBlank(name, "Name must not be blank");

[中]检查给定字符串是否为空白(空)空串或只包含空白符),为空抛出 IllegalArgumentException

Assert.notBlank(name, "Name must not be blank");

代码示例

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

/**
 * 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出 {@link IllegalArgumentException}
 * 
 * <pre class="code">
 * Assert.notBlank(name, "Name must not be blank");
 * </pre>
 * 
 * @param text 被检查字符串
 * @return 非空字符串
 * @see StrUtil#isNotBlank(CharSequence)
 * @throws IllegalArgumentException 被检查字符串为空白
 */
public static String notBlank(String text) throws IllegalArgumentException {
  return notBlank(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
}

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

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件路径
 * @param dest 目标文件或目录路径,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return File
 * @throws IORuntimeException IO异常
 */
public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException {
  Assert.notBlank(src, "Source File path is blank !");
  Assert.notNull(src, "Destination File path is null !");
  return copyFile(Paths.get(src), Paths.get(dest), options).toFile();
}

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

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件路径
 * @param dest 目标文件或目录路径,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return File
 * @throws IORuntimeException IO异常
 */
public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException {
  Assert.notBlank(src, "Source File path is blank !");
  Assert.notNull(src, "Destination File path is null !");
  return copyFile(Paths.get(src), Paths.get(dest), options).toFile();
}

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

/**
 * 构造,使用相对于Class文件根目录的相对路径
 * 
 * @param path 相对路径或绝对路径
 * @param charset 字符集
 * @param isUseVariable 是否使用变量
 */
public Setting(String path, Charset charset, boolean isUseVariable) {
  Assert.notBlank(path, "Blank setting path !");
  this.init(ResourceUtil.getResourceObj(path), charset, isUseVariable);
}

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

/**
 * 构造
 * 
 * @param url URL
 */
public HttpRequest(String url) {
  Assert.notBlank(url, "Param [url] can not be blank !");
  this.url = URLUtil.normalize(url, true);
  // 给定一个默认头信息
  this.header(GlobalHeaders.INSTANCE.headers);
}

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

/**
 * 构造,相对于classes读取文件
 * 
 * @param path 相对ClassPath路径或绝对路径
 * @param clazz 基准类
 * @param charset 字符集
 * @param isUseVariable 是否使用变量
 */
public Setting(String path, Class<?> clazz, Charset charset, boolean isUseVariable) {
  Assert.notBlank(path, "Blank setting path !");
  this.init(new ClassPathResource(path, clazz), charset, isUseVariable);
}

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

/**
 * 构造
 * 
 * @param url URL
 */
public HttpRequest(String url) {
  Assert.notBlank(url, "Param [url] can not be blank !");
  this.url = URLUtil.normalize(url, true);
  // 给定一个默认头信息
  this.header(GlobalHeaders.INSTANCE.headers);
}

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

/**
 * 构造,使用相对于Class文件根目录的相对路径
 * 
 * @param path 相对路径或绝对路径
 * @param charset 字符集
 * @param isUseVariable 是否使用变量
 */
public Setting(String path, Charset charset, boolean isUseVariable) {
  Assert.notBlank(path, "Blank setting path !");
  this.init(ResourceUtil.getResourceObj(path), charset, isUseVariable);
}

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

/**
 * 构造,使用相对于Class文件根目录的相对路径
 * 
 * @param path 相对或绝对路径
 * @param charset 字符集
 */
public Props(String path, Charset charset) {
  Assert.notBlank(path, "Blank properties file path !");
  if(null != charset) {
    this.charset = charset;
  }
  this.load(ResourceUtil.getResourceObj(path));
}

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

/**
 * 构造,相对于classes读取文件
 * 
 * @param path 相对ClassPath路径或绝对路径
 * @param clazz 基准类
 * @param charset 字符集
 * @param isUseVariable 是否使用变量
 */
public Setting(String path, Class<?> clazz, Charset charset, boolean isUseVariable) {
  Assert.notBlank(path, "Blank setting path !");
  this.init(new ClassPathResource(path, clazz), charset, isUseVariable);
}

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

/**
 * 构造,相对于classes读取文件
 * 
 * @param path 相对路径
 * @param clazz 基准类
 * @param charset 字符集
 */
public Props(String path, Class<?> clazz, Charset charset) {
  Assert.notBlank(path, "Blank properties file path !");
  if(null != charset) {
    this.charset = charset;
  }
  this.load(new ClassPathResource(path, clazz));
}

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

/**
 * 构造,使用相对于Class文件根目录的相对路径
 * 
 * @param path 相对或绝对路径
 * @param charset 字符集
 */
public Props(String path, Charset charset) {
  Assert.notBlank(path, "Blank properties file path !");
  if(null != charset) {
    this.charset = charset;
  }
  this.load(ResourceUtil.getResourceObj(path));
}

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

/**
 * 将URL字符串转换为URL对象,并做必要验证
 * 
 * @param urlStr URL字符串
 * @param handler {@link URLStreamHandler}
 * @return URL
 * @since 4.1.9
 */
public static URL toUrlForHttp(String urlStr, URLStreamHandler handler) {
  Assert.notBlank(urlStr, "Url is blank !");
  // 去掉url中的空白符,防止空白符导致的异常
  urlStr = StrUtil.cleanBlank(urlStr);
  return URLUtil.url(urlStr, handler);
}

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

/**
 * 构造,相对于classes读取文件
 * 
 * @param path 相对路径
 * @param clazz 基准类
 * @param charset 字符集
 */
public Props(String path, Class<?> clazz, Charset charset) {
  Assert.notBlank(path, "Blank properties file path !");
  if(null != charset) {
    this.charset = charset;
  }
  this.load(new ClassPathResource(path, clazz));
}

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

/**
 * 将URL字符串转换为URL对象,并做必要验证
 * 
 * @param urlStr URL字符串
 * @param handler {@link URLStreamHandler}
 * @return URL
 * @since 4.1.9
 */
public static URL toUrlForHttp(String urlStr, URLStreamHandler handler) {
  Assert.notBlank(urlStr, "Url is blank !");
  // 去掉url中的空白符,防止空白符导致的异常
  urlStr = StrUtil.cleanBlank(urlStr);
  return URLUtil.url(urlStr, handler);
}

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

/**
 * 设置字段值
 * 
 * @param obj 对象
 * @param fieldName 字段名
 * @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
 * @throws UtilException 包装IllegalAccessException异常
 */
public static void setFieldValue(Object obj, String fieldName, Object value) throws UtilException {
  Assert.notNull(obj);
  Assert.notBlank(fieldName);
  setFieldValue(obj, getField(obj.getClass(), fieldName), value);
}

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

/**
 * 设置字段值
 * 
 * @param obj 对象
 * @param fieldName 字段名
 * @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
 * @throws UtilException 包装IllegalAccessException异常
 */
public static void setFieldValue(Object obj, String fieldName, Object value) throws UtilException {
  Assert.notNull(obj);
  Assert.notBlank(fieldName);
  setFieldValue(obj, getField(obj.getClass(), fieldName), value);
}

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

/**
 * 写出图像为PNG格式
 * 
 * @param targetImageStream 写出到的目标流
 * @return 是否成功写出,如果返回false表示未找到合适的Writer
 * @throws IORuntimeException IO异常
 */
public boolean write(ImageOutputStream targetImageStream) throws IORuntimeException {
  Assert.notBlank(this.targetImageType, "Target image type is blank !");
  Assert.notNull(targetImageStream, "Target output stream is null !");
  final BufferedImage targetImage = (null == this.targetImage) ? this.srcImage : this.targetImage;
  Assert.notNull(targetImage, "Target image is null !");
  
  return ImageUtil.write(targetImage, this.targetImageType, targetImageStream, this.quality);
}

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

/**
 * 写出图像为PNG格式
 * 
 * @param targetImageStream 写出到的目标流
 * @return 是否成功写出,如果返回false表示未找到合适的Writer
 * @throws IORuntimeException IO异常
 */
public boolean write(ImageOutputStream targetImageStream) throws IORuntimeException {
  Assert.notBlank(this.targetImageType, "Target image type is blank !");
  Assert.notNull(targetImageStream, "Target output stream is null !");
  final BufferedImage targetImage = (null == this.targetImage) ? this.srcImage : this.targetImage;
  Assert.notNull(targetImage, "Target image is null !");
  
  return ImageUtil.write(targetImage, this.targetImageType, targetImageStream, this.quality);
}

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

/**
 * 转换字符串为Date
 * 
 * @param dateStr 日期字符串
 * @param parser {@link FastDateFormat}
 * @return {@link Date}
 */
private static Date parse(String dateStr, DateParser parser) {
  Assert.notNull(parser, "Parser or DateFromat must be not null !");
  Assert.notBlank(dateStr, "Date String must be not blank !");
  try {
    return parser.parse(dateStr);
  } catch (Exception e) {
    throw new DateException("Parse [{}] with format [{}] error!", dateStr, parser.getPattern(), e);
  }
}

相关文章