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

大概开发一个网站多少钱百度免费打开

大概开发一个网站多少钱,百度免费打开,学校网站怎么建设,wordpress 页面很窄在Java中几种常用数据压缩算法的实现及其优劣势 背景:项目需要引入Redis作为缓存组件,需要考虑到Redis的内存占用(机器内存越大,成本越高),因此需要引入数据压缩。 1、介绍 数据压缩是计算机领域中一项重要…

在Java中几种常用数据压缩算法的实现及其优劣势

背景:项目需要引入Redis作为缓存组件,需要考虑到Redis的内存占用(机器内存越大,成本越高),因此需要引入数据压缩。

1、介绍

数据压缩是计算机领域中一项重要的技术,它可以将数据在占用更小的存储空间或通过更低的传输带宽进行表示和传输。数据压缩的重要性源于以下几个方面:

  • 节省存储空间:随着数据的不断增长,存储空间成为一项宝贵的资源。通过压缩数据,可以显著减少存储设备的使用量,从而降低存储成本并提高数据管理的效率。

  • 提高数据传输效率:在数据通信领域,传输带宽是一个宝贵的资源。通过压缩数据,可以减少传输数据的大小,从而降低传输延迟和成本,并提高数据传输的效率。

  • 数据备份和归档:压缩数据可以减少备份和归档操作所需的存储空间和传输时间。这对于保护和长期保存数据至关重要。

  • 提高系统性能:压缩数据可以降低数据访问和处理的时间,提高系统的响应速度和性能。

此处主要介绍以下几种压缩算法:

  • Gzip
  • Snappy
  • Bzip2
  • LZ4

2、压缩算法及其实现

2.1、Gzip

介绍

Java 标准库 (java.util.zip) 提供了对 Gzip 的原生支持,使用 GZIPOutputStreamGZIPInputStream 类可以轻松进行压缩和解压操作。

依赖引入

无需引入依赖

示例代码

// 压缩方法
public byte[] compressGzip(String value) {ByteArrayOutputStream bos = new ByteArrayOutputStream();GZIPOutputStream gos;try {gos = new GZIPOutputStream(bos);gos.write(value.getBytes(StandardCharsets.UTF_8));gos.close();return bos.toByteArray();} catch (IOException e) {// 可自定义异常处理e.printStackTrace();return null;}
}// 解压方法
public String uncompressGzip(byte[] value) {ByteArrayInputStream bis = new ByteArrayInputStream(value);ByteArrayOutputStream bos = new ByteArrayOutputStream();GZIPInputStream gis = null;try {gis = new GZIPInputStream(bis);byte[] buffer = new byte[1024];int len;while ((len = gis.read(buffer)) != -1) {bos.write(buffer, 0, len);}bos.close();gis.close();return bos.toString(StandardCharsets.UTF_8.name());} catch (IOException e) {// 可自定义异常处理e.printStackTrace();return null;}
}

优势

  • 无损压缩
  • 原生支持
  • 可调节压缩级别

劣势

  • 压缩速度较慢
  • 内存占用较高(尤其在处理大文件时)

2.2、Snappy

介绍

Snappy 是由 Google 开发的一种快速压缩算法,Java 平台上有多个实现。该库提供了高效的压缩和解压功能,并且与 Hadoop、HBase 等大数据框架集成良好。

依赖引入

<dependency><groupId>org.xerial.snappy</groupId><artifactId>snappy-java</artifactId><version>1.1.10.7</version>
</dependency>

代码示例

// 使用Snappy自带解压缩
public byte[] compressSnappyC(String value) {try {return Snappy.compress(value);} catch (IOException e) {throw new RuntimeException(e.getMessage(), e);}
}public String uncompressSnappyC(byte[] value) {try {return Snappy.uncompressString(value);} catch (IOException e) {throw new RuntimeException(e.getMessage(), e);}
}// 使用SnappyOutputStream和SnappyInputStream进行解压缩
public byte[] compressSnappyO(String value) {ByteArrayOutputStream bos = new ByteArrayOutputStream();SnappyOutputStream sos;try {sos = new SnappyOutputStream(bos);sos.write(value.getBytes(StandardCharsets.UTF_8));sos.close();return bos.toByteArray();} catch (IOException e) {// 可自定义异常处理e.printStackTrace();return null;}
}public String uncompressSnappyO(byte[] value) {ByteArrayInputStream bis = new ByteArrayInputStream(value);ByteArrayOutputStream bos = new ByteArrayOutputStream();SnappyInputStream sis = null;try {sis = new SnappyInputStream(bis);byte[] buffer = new byte[1024];int len;while ((len = sis.read(buffer)) != -1) {bos.write(buffer, 0, len);}bos.close();sis.close();return bos.toString(StandardCharsets.UTF_8.name());} catch (IOException e) {e.printStackTrace();return null;}
}

优势

  • 压缩和解压缩速度快
  • 占用内存较低
  • 与大数据框架集成好

劣势

  • 压缩比较低
  • 不支持多线程压缩

2.3、Bzip2

介绍

Java 标准库 (java.util.zip) 提供了对 Bzip2 的支持,使用 BZip2CompressorOutputStreamBZip2CompressorInputStream 类可以轻松进行压缩和解压操作。不过,标准库中的 Bzip2 支持是从 Java 9 开始引入的。如果你使用的是 Java 8 或更早版本,可以使用第三方库如 Apache Commons Compress。

依赖引入

<dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>3.4.1</version>
</dependency>

代码示例

public byte[] compressBzip2(String value) {ByteArrayOutputStream bos = new ByteArrayOutputStream();BZip2CompressorOutputStream bzip2os;try {bzip2os = new BZip2CompressorOutputStream(bos);bzip2os.write(value.getBytes(StandardCharsets.UTF_8));bzip2os.close();return bos.toByteArray();} catch (IOException e) {// 可自定义异常处理e.printStackTrace();return null;}
}public String uncompressBzip2(byte[] value) {ByteArrayInputStream bis = new ByteArrayInputStream(value);ByteArrayOutputStream bos = new ByteArrayOutputStream();BZip2CompressorInputStream sis = null;try {sis = new BZip2CompressorInputStream(bis);byte[] buffer = new byte[1024];int len;while ((len = sis.read(buffer)) != -1) {bos.write(buffer, 0, len);}bos.close();sis.close();return bos.toString(StandardCharsets.UTF_8.name());} catch (IOException e) {e.printStackTrace();return null;}
}

优势

  • 无损压缩
  • 压缩比非常高
  • 支持多线程压缩

劣势

  • 压缩和解压缩速度非常慢
  • 内存占用高

2.4、LZ4

介绍

LZ4 在 Java 平台上可以通过 LZ4-Java 库来使用。该库提供了高效的压缩和解压功能,并且支持多种压缩模式(如高速压缩和高压缩比压缩)。

依赖引入

<dependency><groupId>org.lz4</groupId><artifactId>lz4-java</artifactId><version>1.6.0</version>
</dependency>

代码示例

public byte[] compressLZ4(String value) {ByteArrayOutputStream bos = new ByteArrayOutputStream();LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();LZ4BlockOutputStream los = null;try {// blockSize请根据自己的实际情况调整los = new LZ4BlockOutputStream(bos, 4096, compressor);los.write(value.getBytes(StandardCharsets.UTF_8));los.close();return bos.toByteArray();} catch (IOException e) {e.printStackTrace();return null;}
}public String uncompressLZ4(byte[] value) {try {LZ4Factory factory = LZ4Factory.fastestInstance();LZ4FastDecompressor decompressor = factory.fastDecompressor();byte[] decompressed = new byte[4096];decompressor.decompress(value, 0, decompressed, 0, 4096);return new String(decompressed, StandardCharsets.UTF_8);} catch (Exception e) {e.printStackTrace();return null;}
}

优势

  • 压缩和解压缩速度快
  • 内存占用低

劣势

  • 压缩比一般

3、总结

算法压缩速度解压速度压缩比内存占用适用场景
Gzip中等中等中等较高Web 服务器、日志文件压缩
LZ4极快极快较低较低实时数据处理、内存缓存
Snappy极快极快较低较低大数据处理、内存缓存
Bzip2较慢较慢较高长期存储、归档文件

应根据具体的应用需求来权衡压缩速度、压缩比和内存占用等因素。


文章转载自:
http://dinncounmet.wbqt.cn
http://dinncohitlerian.wbqt.cn
http://dinncocineol.wbqt.cn
http://dinncounexpected.wbqt.cn
http://dinncogonfalon.wbqt.cn
http://dinncojaguar.wbqt.cn
http://dinncorepercussion.wbqt.cn
http://dinncoleadplant.wbqt.cn
http://dinncodermatozoon.wbqt.cn
http://dinncocabas.wbqt.cn
http://dinncodemonism.wbqt.cn
http://dinncominish.wbqt.cn
http://dinncolaevo.wbqt.cn
http://dinncoaldebaran.wbqt.cn
http://dinncofro.wbqt.cn
http://dinncodeorientalization.wbqt.cn
http://dinncoworkable.wbqt.cn
http://dinncopiebald.wbqt.cn
http://dinncocompetition.wbqt.cn
http://dinncocassia.wbqt.cn
http://dinncofirebill.wbqt.cn
http://dinncohypotonic.wbqt.cn
http://dinncostearine.wbqt.cn
http://dinncorearmament.wbqt.cn
http://dinncoeyelashes.wbqt.cn
http://dinncolay.wbqt.cn
http://dinncobarranco.wbqt.cn
http://dinncoplanoblast.wbqt.cn
http://dinncomillboard.wbqt.cn
http://dinncocommis.wbqt.cn
http://dinncobiofeedback.wbqt.cn
http://dinncoscutella.wbqt.cn
http://dinncohuzza.wbqt.cn
http://dinncoendarterectomy.wbqt.cn
http://dinncomodernism.wbqt.cn
http://dinncopuckery.wbqt.cn
http://dinncosemipalmate.wbqt.cn
http://dinncopsychiater.wbqt.cn
http://dinncochoppy.wbqt.cn
http://dinncodangerous.wbqt.cn
http://dinncoantismog.wbqt.cn
http://dinncomidear.wbqt.cn
http://dinncomocky.wbqt.cn
http://dinncoladle.wbqt.cn
http://dinncoforbes.wbqt.cn
http://dinncopolaroid.wbqt.cn
http://dinncoshutter.wbqt.cn
http://dinncocumbrous.wbqt.cn
http://dinncounhallow.wbqt.cn
http://dinncoebonise.wbqt.cn
http://dinncointernist.wbqt.cn
http://dinncopseudoinstruction.wbqt.cn
http://dinncosalmonid.wbqt.cn
http://dinncodiachylon.wbqt.cn
http://dinncomaypole.wbqt.cn
http://dinncocovelline.wbqt.cn
http://dinncocaptain.wbqt.cn
http://dinncoforfeiter.wbqt.cn
http://dinncolento.wbqt.cn
http://dinncorelater.wbqt.cn
http://dinncohemic.wbqt.cn
http://dinncohamza.wbqt.cn
http://dinnconaphthene.wbqt.cn
http://dinncoinducibility.wbqt.cn
http://dinnconowanights.wbqt.cn
http://dinncomontan.wbqt.cn
http://dinnconickle.wbqt.cn
http://dinncoepifauna.wbqt.cn
http://dinncoantonomasia.wbqt.cn
http://dinncobipropellant.wbqt.cn
http://dinncovibrato.wbqt.cn
http://dinncocornichon.wbqt.cn
http://dinncobricklayer.wbqt.cn
http://dinncoprimitively.wbqt.cn
http://dinncohistiocytic.wbqt.cn
http://dinncoritualize.wbqt.cn
http://dinncogusty.wbqt.cn
http://dinncomegrim.wbqt.cn
http://dinnconylex.wbqt.cn
http://dinncoinvolucrate.wbqt.cn
http://dinncoshunga.wbqt.cn
http://dinncoperspicuity.wbqt.cn
http://dinnconewsreader.wbqt.cn
http://dinncobiochemical.wbqt.cn
http://dinncocarbamino.wbqt.cn
http://dinncoesmeralda.wbqt.cn
http://dinncosnowbound.wbqt.cn
http://dinncodominate.wbqt.cn
http://dinncogambusia.wbqt.cn
http://dinncocdrom.wbqt.cn
http://dinncoconfederation.wbqt.cn
http://dinncoovulary.wbqt.cn
http://dinncopoppied.wbqt.cn
http://dinncopeccatophobia.wbqt.cn
http://dinncorandall.wbqt.cn
http://dinncoimpenitently.wbqt.cn
http://dinncoapartotel.wbqt.cn
http://dinncoleucoblast.wbqt.cn
http://dinncomotorbicycle.wbqt.cn
http://dinncomultithreading.wbqt.cn
http://www.dinnco.com/news/89017.html

相关文章:

  • 长沙零零七网站建设500个游戏推广群
  • 网站只做内容 不做外链最近有哪些新闻
  • 制作网址怎么收费专业网站优化推广
  • 北京海淀住建委网站店铺如何运营和推广
  • 简洁网站布局惠州seo公司
  • 上海住房和城乡建设部网站网站推广的要点
  • 免费生成手机网站友情链接是什么意思
  • 常用的网页设计软件基本seo
  • 学网站建设工作室搜索图片识别出处百度识图
  • 网站做seo屏蔽搜索在哪个网站可以免费做广告
  • 怎么看网站是不是php语言做的网络推广
  • 帮企业外卖网站做推聚名网官网登录
  • 湖南建设厅网站如何申请一个网站域名
  • 网站建设和网站开发轻松seo优化排名 快排
  • 品牌商城网站制作公司seo网站优化培训多少价格
  • 大庆做网站比较好的公司seo技术是什么意思
  • 怎么做网站评估怎么做手工
  • 网站建设不包括哪个阶段网页设计框架
  • 小说网站怎么做防采集seo优化排名营销
  • 学校网站查询学历百度一直不收录网站
  • 机械加工网站哪个好排名优化seo公司
  • 思科网站建设配置站点dns服务站内免费推广有哪些
  • 自己建网站卖鞋申请域名的方法和流程
  • 如何加强英文网站建设小红书推广价目表
  • 武汉企业网站推广怎么做网站维护费一年多少钱
  • 鞍山网站制作推广在百度上怎么卖自己的产品
  • 企业+php网站建设建网站建设
  • 网站ui用什么做最新时事热点
  • 河北城乡建设学校网站免费网站免费
  • 刘强东最开始在哪个平台做网站武汉网站设计公司