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

营销智库网站厦门专业网站建设

营销智库网站,厦门专业网站建设,wordpress 加速 谷歌,wordpress 推送 微信在最近的项目中#xff0c;我们不得不做一些我个人从未真正看过的事情。 压缩。 我们需要拍几个文件和图像#xff0c;将它们压缩并提供给FTP使用#xff0c;是的#xff0c;总有一天#xff0c;感觉确实回到了90年代。 除了过去的FTP之行外#xff0c;它还是一个很好的机… 在最近的项目中我们不得不做一些我个人从未真正看过的事情。 压缩。 我们需要拍几个文件和图像将它们压缩并提供给FTP使用是的总有一天感觉确实回到了90年代。 除了过去的FTP之行外它还是一个很好的机会可以花一点时间在这个问题上。 压缩档案 因此在通常的IO类BufferedInputStream FileOutputStream和File上面有 ZipInputStream –输入流用于读取ZIP文件格式的文件。 与ZipFile不同不缓存Zip条目。 ZipOutputStream –用于以ZIP文件格式写入文件的输出流。 这有一个默认的内部缓冲区512可以使用BufferedOutputStream来增加它。 ZipEntry –表示一个zip文件中的条目。 ZipFile –用于从zip文件读取条目。 条目被缓存。 CRC32 –用于计算数据流的CRC-32。 下面的示例显示了如何在有和没有校验和的情况下压缩和解压缩文件夹中的文件 package javaitzen.blog;import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.zip.CRC32; import java.util.zip.CheckedInputStream; import java.util.zip.CheckedOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream;/*** The Class FileCompressionUtil.*/ public class FileCompressionUtil {private static final String PATH_SEP \\;public static final int BUFFER 2048;private FileCompressionUtil() {}/*** Zip files in path.* * param zipFileName the zip file name* param filePath the file path* throws IOException Signals that an I/O exception has occurred.*/public static void zipFilesInPath(final String zipFileName, final String filePath) throws IOException {final FileOutputStream dest new FileOutputStream(zipFileName);final ZipOutputStream out new ZipOutputStream(new BufferedOutputStream(dest));try {byte[] data new byte[BUFFER];final File folder new File(filePath);final List String files Arrays.asList(folder.list());for (String file : files) {final FileInputStream fi new FileInputStream(filePath PATH_SEP file);final BufferedInputStream origin new BufferedInputStream(fi, BUFFER);out.putNextEntry(new ZipEntry(file));int count;while ((count origin.read(data, 0, BUFFER)) ! -1) {out.write(data, 0, count);}origin.close();fi.close();}} finally {out.close();dest.close();}}/*** Zip with checksum. CRC32* * param zipFileName the zip file name* param folderPath the folder path* return the checksum* throws IOException Signals that an I/O exception has occurred.*/public static long zipFilesInPathWithChecksum(final String zipFileName, final String folderPath) throws IOException {final FileOutputStream dest new FileOutputStream(zipFileName);final CheckedOutputStream checkStream new CheckedOutputStream(dest, new CRC32());final ZipOutputStream out new ZipOutputStream(new BufferedOutputStream(checkStream));try {byte[] data new byte[BUFFER];final File folder new File(folderPath);final List String files Arrays.asList(folder.list());for (String file : files) {final FileInputStream fi new FileInputStream(folderPath PATH_SEP file);final BufferedInputStream origin new BufferedInputStream(fi, BUFFER);out.putNextEntry(new ZipEntry(file));int count;while ((count origin.read(data, 0, BUFFER)) ! -1) {out.write(data, 0, count);}origin.close();}} finally {out.close();checkStream.close();dest.flush();dest.close();}return checkStream.getChecksum().getValue();}/*** Unzip files to path.* * param zipFileName the zip file name* param fileExtractPath the file extract path* throws IOException Signals that an I/O exception has occurred.*/public static void unzipFilesToPath(final String zipFileName, final String fileExtractPath) throws IOException {final FileInputStream fis new FileInputStream(zipFileName);final ZipInputStream zis new ZipInputStream(new BufferedInputStream(fis));try {ZipEntry entry;while ((entry zis.getNextEntry()) ! null) {int count;byte[] data new byte[BUFFER];final FileOutputStream fos new FileOutputStream(fileExtractPath PATH_SEP entry.getName());final BufferedOutputStream dest new BufferedOutputStream(fos, BUFFER);while ((count zis.read(data, 0, BUFFER)) ! -1) {dest.write(data, 0, count);}dest.flush();dest.close();}} finally {fis.close();zis.close();}}/*** Unzip files to path with checksum. CRC32* * param zipFileName the zip file name* param fileExtractPath the file extract path* param checksum the checksum* return true, if checksum matches;* throws IOException Signals that an I/O exception has occurred.*/public static boolean unzipFilesToPathWithChecksum(final String zipFileName, final String fileExtractPath, final long checksum) throws IOException {boolean checksumMatches false;final FileInputStream fis new FileInputStream(zipFileName);final CheckedInputStream checkStream new CheckedInputStream(fis, new CRC32());final ZipInputStream zis new ZipInputStream(new BufferedInputStream(checkStream));try {ZipEntry entry null;while ((entry zis.getNextEntry()) ! null) {int count;byte[] data new byte[BUFFER];final FileOutputStream fos new FileOutputStream(fileExtractPath PATH_SEP entry.getName());final BufferedOutputStream dest new BufferedOutputStream(fos, BUFFER);while ((count zis.read(data, 0, BUFFER)) ! -1) {dest.write(data, 0, count);}dest.flush();dest.close();}} finally {zis.close();fis.close();checkStream.close();}if(checkStream.getChecksum().getValue() checksum) {checksumMatches true;}return checksumMatches;}} 压缩物件 我们最终没有使用对象压缩但无论如何我还是看了一下。 我做了一些通用的compress / expand util不知道它是否有用。 我将输入参数保留为OutputStream和InputStream因为从理论上讲它可以与从套接字通信到字符串处理的任何流实现一起使用。 这里使用与压缩相关的类 GZIPInputStream –一个输入流过滤器用于读取GZIP文件格式的压缩数据。 GZIPOutputStream –输出流过滤器用于以GZIP文件格式写入压缩数据。 默认内部缓冲区为512如果需要更多请使用BufferedOutputStream 。 package javaitzen.blog;import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream;/*** The Class ObjectCompressionUtil.* * param T the generic type of the serializable object to be compressed*/ public class ObjectCompressionUtilT extends Serializable {/*** Compress object.* * param objectToCompress the object to compress* param outstream the outstream* return the compressed object* throws IOException Signals that an I/O exception has occurred.*/public T compressObject(final T objectToCompress, final OutputStream outstream) throws IOException {final GZIPOutputStream gz new GZIPOutputStream(outstream);final ObjectOutputStream oos new ObjectOutputStream(gz);try {oos.writeObject(objectToCompress);oos.flush();return objectToCompress;}finally {oos.close();outstream.close();}}/*** Expand object.* * param objectToExpand the object to expand* param instream the instream* return the expanded object* throws IOException Signals that an I/O exception has occurred.* throws ClassNotFoundException the class not found exception*/public T expandObject(final T objectToExpand, final InputStream instream) throws IOException,ClassNotFoundException {final GZIPInputStream gs new GZIPInputStream(instream);final ObjectInputStream ois new ObjectInputStream(gs);try {SuppressWarnings(unchecked)T expandedObject (T) ois.readObject();return expandedObject;} finally {gs.close();ois.close();}}} 参考来自Zen的 JCG合作伙伴 Brian的Java压缩 技术 。 编码愉快 拜伦 相关文章 Cajo用Java完成分布式计算的最简单方法 Hibernate映射集合性能问题 Java Code Geeks Andygene Web原型 Servlet 3.0异步处理可将服务器吞吐量提高十倍 翻译自: https://www.javacodegeeks.com/2011/05/java-compression.html
http://www.zqtcl.cn/news/52639/

相关文章:

  • 做美图 网站有哪些东西吗怎么管理wordpress
  • 湖南建设厅网站不良记录简述网站开发的工作流程
  • 丰镇网站建设百度站长工具网站认证
  • 网站服务公司人工成本进什么费用建筑设计主要内容
  • 浙江做网站的公司网站的重要目录对百度进行了封禁
  • 做普通网站需要多少钱网页设计图片代码
  • 新手入门网站建设书籍修改标题下分类 wordpress
  • 网站建设sunmun房地产行业发展前景分析
  • 南京seo整站优化技术天华建筑设计有限公司
  • 北京威凯建设发展招聘网站网络公关团队
  • 网站开发常用的技术如何上传图片到网站
  • 北京商业网站建设广州论坛网站建设
  • 网站建站啥意思一个网站的建设要经过哪几个阶段
  • 山东省建设备案网站审批表做垂直导购网站还行吗
  • 网站排名怎样做有效优秀公司网站
  • 做美团团购网站企业为什么要找会计
  • 网站上的站点地图链接是这么做的网站蜘蛛抓取
  • 涞源县住房和城乡建设局网站西安工作室
  • 简述电子商务网站建设的主要步骤免费一键生成短链接
  • 站嗨免费建站宁波做网站费用
  • 有谁做彩票网站注册公司流程和费用需要哪些条件
  • 只用网站开发VS就安装那些就够了wordpress评论提示
  • 微信制作微网站开发嘉兴制作手机网站
  • phpcms双语网站怎么做教务系统学生登录入口
  • 网站编辑如何做广州分享网站建设
  • 商标注册查询官方网站白云区专业网站建设
  • 怎样解析网站域名卖鞋推广引流方法
  • 做动态图的网站wordpress访客发布审核
  • 企业个性化网站建设费用虚拟商城网站搭建
  • 有哪些好的响应式网站有哪些社保网站哪里做转入