当前位置: 首页 > wzjs >正文

做网站样品图片怎么拍照广州公司排名100强

做网站样品图片怎么拍照,广州公司排名100强,做公司网站流程,广西和住房城乡建设厅网站文件分片,顾名思义,就是将一个大文件分割成多个小的文件块(chunk)。每个文件块都是原始文件的一部分,并可以通过特定的方式将这些小文件块重新组装成原始文件。 1. 基本原理: 文件分片从底层来看,主要是对…

文件分片,顾名思义,就是将一个大文件分割成多个小的文件块(chunk)。每个文件块都是原始文件的一部分,并可以通过特定的方式将这些小文件块重新组装成原始文件。

1. 基本原理:

文件分片从底层来看,主要是对文件进行字节级别的读取和分割。可以将文件看作一个巨大的字节数组,分片的过程就是按照一定的规则将这个字节数组切割成多个小数组,然后将每个小数组写入到不同的文件中。

  • 定义分片大小 (Chunk Size): 这是核心参数。所有的分片都会被切割成这个大小 (最后一个分片可能小于这个大小).

  • 读取文件: 用二进制方式读取文件.

  • 分割数据: 根据 Chunk Size,将读取到的文件内容分割成多个字节数组.

  • 写入分片文件: 每个字节数组 (chunk) 被写入到单独的文件中。 通常,会为每个分片文件命名,以便后续可以按顺序组装它们。

  • 元数据:在分片的同时,通常会生成一个元数据文件,其中包含原始文件名、分片数量、每个分片的顺序和大小等信息。这个元数据文件是后续重新组装文件的关键。

2. 关键技术:

  • 文件读取: 使用 InputStream 或 FileChannel 等进行二进制文件读取. FileChannel 通常提供更高的性能.

  • 字节数组操作: 使用 byte[] 来存储和操作文件数据.

  • 文件写入: 使用 OutputStream 或 FileChannel 将字节数组写入到各个分片文件中。同样的,FileChannel 通常有更好的性能。

  • 偏移量 (Offset): 在读取和写入过程中,需要记录每个分片的起始位置(偏移量),以便正确地分割和组装文件。

 3.参考代码(来源于练习项目)

package com.frontend.file;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.stream.Stream;public class FileMerger{private static final String tempFilePath = "D:/data/project/com.frontEndProject/temp/download";private static final String userFilePath ="D:/data/project/com.frontEndProject/userFile";private final String inputFolder;private final String outputFolder;private final String fileName;public FileMerger(String inputFolder, String outputFolder, String fileName) {this.inputFolder = inputFolder;this.outputFolder = outputFolder;this.fileName = fileName;}public Path mergeFiles() throws IOException {Path chunkPath= Paths.get(tempFilePath+"/"+inputFolder);Path parentDir=Paths.get(userFilePath+"/"+outputFolder);Path saveFilePath=Paths.get(userFilePath+"/"+outputFolder+"/"+fileName);if(!Files.exists(chunkPath)){Files.createDirectories(chunkPath);}if(!Files.exists(parentDir)){Files.createDirectories(parentDir);}if(!Files.exists(saveFilePath)){Files.createFile(saveFilePath);}try(Stream<Path> paths = Files.list(chunkPath).sorted(Comparator.comparing(p->p.getFileName().toString()))){try(FileOutputStream fos=new FileOutputStream(saveFilePath.toFile()); BufferedOutputStream bos=new BufferedOutputStream(fos)){paths.forEach(chunkFile->{try(FileInputStream fis=new FileInputStream(chunkFile.toFile()); BufferedInputStream bis=new BufferedInputStream(fis)) {byte[] buffer=new byte[8192];int bytesRead;while((bytesRead=bis.read(buffer))!=-1){bos.write(buffer,0,bytesRead);}} catch (IOException e) {throw new RuntimeException(e);}});}}return saveFilePath;}
}
package com.frontend.file;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;
import java.util.stream.Stream;public class FileSplitter{private static final String tempFilePath = "D:/data/project/com.frontEndProject/temp/upload";private final File sourceFile;private final String outputFolder;private final int chunkSize;public FileSplitter(File sourceFile, String outputFolder, int chunkSize){this.sourceFile = sourceFile;this.outputFolder = outputFolder;this.chunkSize = chunkSize;}public Stream<Path> splitFile() throws IOException {Path outputPath = Paths.get(tempFilePath +"/"+outputFolder);if(!Files.exists(outputPath)){Files.createDirectories(outputPath);}try(FileInputStream fis = new FileInputStream(sourceFile); BufferedInputStream bis = new BufferedInputStream(fis)){byte[] buffer=new byte[chunkSize];int index=0,bytesRead;String fileHash= FileHash.calculateHash(sourceFile,"SHA-256");while ((bytesRead=bis.read(buffer))!=-1){String chunkFileName=String.format("%s%06d.temp",fileHash,++index);Path tempFilePath=outputPath.resolve(chunkFileName);if(Files.exists(tempFilePath))continue;try(FileOutputStream fos = new FileOutputStream(tempFilePath.toFile()); BufferedOutputStream bos = new BufferedOutputStream(fos)){bos.write(buffer,0,bytesRead);}}} catch (NoSuchAlgorithmException e) {throw new RuntimeException(e);}Stream<Path> result;try {result =Files.list(outputPath).sorted(Comparator.comparing(p->p.getFileName().toString()));} catch (IOException e) {throw new RuntimeException(e);}return result;}
}
package com.frontend.file;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class FileHash{public static String calculateHash(File file, String algorithm) throws NoSuchAlgorithmException, IOException, IOException {MessageDigest messageDigest= MessageDigest.getInstance(algorithm);try(FileInputStream fr=new FileInputStream(file)){byte[] buffer=new byte[8192];int readBytes;while ((readBytes=fr.read(buffer))!=-1){messageDigest.update(buffer,0,readBytes);}}byte[] digest=messageDigest.digest();StringBuilder stringBuilder=new StringBuilder();for(byte b:digest){stringBuilder.append(String.format("%02x",b));}return stringBuilder.toString();}public static boolean VerifyFileHash(String fileHash, String saveRecordFilePath) throws IOException, NoSuchAlgorithmException {File file = new File(saveRecordFilePath);if(!file.exists()) return false;String verifyFileHash=calculateHash(Paths.get(saveRecordFilePath).toFile(),"SHA-256");return verifyFileHash.equals(fileHash);}public static void main(String[] args) throws NoSuchAlgorithmException, IOException {Path filePath= Paths.get("D:\\code\\Java\\frontEndProject\\src\\main\\java\\com\\frontend\\controller\\EditorialMaterialController.java");String result=calculateHash(filePath.toFile(),"SHA-256");System.out.println(result.length());}
}


文章转载自:

http://jVlc9PXj.qLkjh.cn
http://553WePGT.qLkjh.cn
http://cFzg0KAQ.qLkjh.cn
http://s9knP7pU.qLkjh.cn
http://9wBKx3iu.qLkjh.cn
http://uxrwzy9f.qLkjh.cn
http://Uj5GYpDz.qLkjh.cn
http://1QpxPBFL.qLkjh.cn
http://8sCKPUeE.qLkjh.cn
http://5Nrv61GS.qLkjh.cn
http://GZnJPYyh.qLkjh.cn
http://3oWZT7XH.qLkjh.cn
http://o42rvc0g.qLkjh.cn
http://p58QYyHJ.qLkjh.cn
http://bDsuOXnb.qLkjh.cn
http://HT0Eo3l0.qLkjh.cn
http://m04u92JR.qLkjh.cn
http://MnYYccfh.qLkjh.cn
http://A5gIHh4O.qLkjh.cn
http://hpCR6amK.qLkjh.cn
http://A9h2aD2p.qLkjh.cn
http://zH7CWOgk.qLkjh.cn
http://83GafKZe.qLkjh.cn
http://P4Ryqghw.qLkjh.cn
http://0s5vRq3p.qLkjh.cn
http://1zfUefzb.qLkjh.cn
http://7l5cwtqi.qLkjh.cn
http://h8MalFbV.qLkjh.cn
http://OjCDz6yH.qLkjh.cn
http://MOBmIyE1.qLkjh.cn
http://www.dtcms.com/wzjs/635233.html

相关文章:

  • 凡科可以做淘客网站吗企业文化墙设计图
  • 浙江华企网站做的咋样seo快速工具
  • 江苏建设工程招标网站南京网站建设公司 雷仁网络
  • 湖南建设网站公司网站建设86215
  • 做淘宝客网站用什么系统做照片有那些网站好
  • 做几何图形和网站山东做网站建设的好公司哪家好
  • 一流的品牌网站建设公司做网站的
  • 网站建设入门pdf建设阿里巴巴网站
  • 手机数据线东莞网站建设网站管家
  • 河北爱站网络科技有限公司遵义网站建设托管公司
  • 如何做像淘宝一样的网站哪里有网站建设定制
  • asp学习网站小程序导航wordpress
  • 自己做的网站添加域名wordpress手机版侧栏导航
  • 什么网站可以自己做配图怎么知道网站是某个公司做的
  • 网站psd设计稿ps做网站首页步骤
  • 可以直接进入的正能量网站老狼湖南太平洋建设集团网站
  • 专业购物网站定制同国外做贸易的网站
  • 淄博网站搜索排名qq群推广网站
  • 注册网站商标水冷眸WordPress
  • 网站编辑做的准备wordpress.org配置
  • 做淘宝客网站违法吗阿里云备案网站建设方案书
  • 青岛商城网站开发深圳网站外包公司
  • 做诚信通谁给做网站网站功能设计指什么
  • 徐州seo全网营销seo 优化 工具
  • 网站开发string文件公司网站建立教程
  • 广州外贸型网站顺义建设网站
  • 高端网站建设网络设计互联网信息化服务类专业网站建设价格最优
  • 网站首页轮播图怎么做的装饰公司接单技巧
  • 湘潭学校网站建设 z磐石网络广州佛山网站建设地址
  • 网站建设 培训网站建设售后服务