cn.hutool.core.io.FileUtil.readBytes()方法的使用及代码示例

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

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

FileUtil.readBytes介绍

[英]读取文件所有数据
文件的长度不能超过Integer.MAX_VALUE
[中]读取文件所有数据
文件的长度不能超过整数最大值

代码示例

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

/**
 * base64编码,URL安全的
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encodeUrlSafe(File file) {
  return Base64Encoder.encodeUrlSafe(FileUtil.readBytes(file));
}

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

/**
 * base64编码
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encode(File file) {
  return Base64Encoder.encode(FileUtil.readBytes(file));
}

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

/**
 * base64编码,URL安全的
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encodeUrlSafe(File file) {
  return Base64Encoder.encodeUrlSafe(FileUtil.readBytes(file));
}

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

/**
 * 读取文件所有数据<br>
 * 文件的长度不能超过Integer.MAX_VALUE
 * 
 * @param filePath 文件路径
 * @return 字节码
 * @throws IORuntimeException IO异常
 * @since 3.2.0
 */
public static byte[] readBytes(String filePath) throws IORuntimeException {
  return readBytes(file(filePath));
}

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

/**
 * 读取文件所有数据<br>
 * 文件的长度不能超过Integer.MAX_VALUE
 * 
 * @param filePath 文件路径
 * @return 字节码
 * @throws IORuntimeException IO异常
 * @since 3.2.0
 */
public static byte[] readBytes(String filePath) throws IORuntimeException {
  return readBytes(file(filePath));
}

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

/**
 * base64编码
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encode(File file) {
  return Base64Encoder.encode(FileUtil.readBytes(file));
}

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

/**
 * @return 获得文件字节流
 * @throws IOException
 */
public byte[] getFileContent() throws IOException {
  assertValid();
  
  if (data != null) {
    return data;
  }
  if (tempFile != null) {
    return FileUtil.readBytes(tempFile);
  }
  return null;
}

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

/**
 * @return 获得文件字节流
 * @throws IOException
 */
public byte[] getFileContent() throws IOException {
  assertValid();
  
  if (data != null) {
    return data;
  }
  if (tempFile != null) {
    return FileUtil.readBytes(tempFile);
  }
  return null;
}

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

/**
 * 获得缓存过的文件bytes
 * @param file 文件
 * @return 缓存过的文件bytes
 * @throws IORuntimeException IO异常
 */
public byte[] getFileBytes(File file) throws IORuntimeException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    //大于缓存空间,不缓存,直接返回
    return bytes;
  }
  usedSize += bytes.length;
  //文件放入缓存,如果usedSize > capacity,purge()方法将被调用
  cache.put(file, bytes);
  return bytes;
}

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

/**
 * 获得缓存过的文件bytes
 * @param file 文件
 * @return 缓存过的文件bytes
 * @throws IORuntimeException IO异常
 */
public byte[] getFileBytes(File file) throws IORuntimeException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    //大于缓存空间,不缓存,直接返回
    return bytes;
  }
  usedSize += bytes.length;
  //文件放入缓存,如果usedSize > capacity,purge()方法将被调用
  cache.put(file, bytes);
  return bytes;
}

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

/**
 * base64编码
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encode(File file) {
  return Base64Encoder.encode(FileUtil.readBytes(file));
}

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

/**
 * 读取文件所有数据<br>
 * 文件的长度不能超过Integer.MAX_VALUE
 * 
 * @param filePath 文件路径
 * @return 字节码
 * @throws IORuntimeException IO异常
 * @since 3.2.0
 */
public static byte[] readBytes(String filePath) throws IORuntimeException {
  return readBytes(file(filePath));
}

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

/**
 * base64编码,URL安全的
 * 
 * @param file 被编码base64的文件
 * @return 被加密后的字符串
 * @since 4.0.9
 */
public static String encodeUrlSafe(File file) {
  return Base64Encoder.encodeUrlSafe(FileUtil.readBytes(file));
}

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

/**
 * @return 获得文件字节流
 * @throws IOException
 */
public byte[] getFileContent() throws IOException {
  assertValid();
  
  if (data != null) {
    return data;
  }
  if (tempFile != null) {
    return FileUtil.readBytes(tempFile);
  }
  return null;
}

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

/**
 * 获得缓存过的文件bytes
 * @param file 文件
 * @return 缓存过的文件bytes
 * @throws IORuntimeException IO异常
 */
public byte[] getFileBytes(File file) throws IORuntimeException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    //大于缓存空间,不缓存,直接返回
    return bytes;
  }
  usedSize += bytes.length;
  //文件放入缓存,如果usedSize > capacity,purge()方法将被调用
  cache.put(file, bytes);
  return bytes;
}

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

/**
 * 获得缓存过的文件bytes
 * @param file 文件
 * @return 缓存过的文件bytes
 * @throws IORuntimeException IO异常
 */
public byte[] getFileBytes(File file) throws IORuntimeException {
  byte[] bytes = cache.get(file);
  if (bytes != null) {
    return bytes;
  }
  // add file
  bytes = FileUtil.readBytes(file);
  if ((maxFileSize != 0) && (file.length() > maxFileSize)) {
    //大于缓存空间,不缓存,直接返回
    return bytes;
  }
  usedSize += bytes.length;
  //文件放入缓存,如果usedSize > capacity,purge()方法将被调用
  cache.put(file, bytes);
  return bytes;
}

代码示例来源:origin: yuboon/Aooms

byte[] bytes = FileUtil.readBytes(url.getPath());
ShardingDataSource dataSource = (ShardingDataSource)YamlShardingDataSourceFactory.createDataSource(shardingDataSources,bytes);

相关文章

微信公众号

最新文章

更多