Tag: gzip

压缩和解压缩java中的大型数据?

我需要压缩/解压缩文件夹中包含的不同类型的文件,该文件夹的大小可能超过10-11 GB。 我使用了以下代码,但这需要很长时间来压缩数据。 BufferedReader in = new BufferedReader(new FileReader(“D:/ziptest/expansion1.MPQ”)); BufferedOutputStream out = new BufferedOutputStream( new GZIPOutputStream(new FileOutputStream(“test.gz”))); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); 请教我一些java中的快速压缩和解压缩库,我也想将大文件分成不同的部分,例如每个100MB的块。

从C#中的压缩字符串中解压缩java中的字符串

我正在寻找正确的解决方案来解压缩来自c#code的java中的字符串。我尝试使用java中的许多技术(gzip,inflatter等)。但是没有得到解决方案。我在尝试时遇到了一些错误从c#代码压缩字符串解压缩java中的字符串。 压缩字符串的我的C#代码是, public static string CompressString(string text) { byte[] byteArray = Encoding.GetEncoding(1252).GetBytes(text);// Encoding.ASCII.GetBytes(text); using (var ms = new MemoryStream()) { // Compress the text using (var ds = new DeflateStream(ms, CompressionMode.Compress)) { ds.Write(byteArray, 0, byteArray.Length); } return Convert.ToBase64String(ms.ToArray()); } } 并在java中解压缩字符串, private static void compressAndDecompress(){ try { // Encode a String into bytes String string […]

Java压缩大文件

我正在开发一个适用于一些非常大的文件的应用程序,每个文件大约180mb,其中有3个。 我想在我的应用程序中添加一个选项,通过压缩zip或tar或其他东西来备份这些文件。 什么是最好的选择是在Java中尽可能地压缩它们? 柏油? 压缩? gzip的?

压缩hadoop mapreduce输出的最简单有效的方法

我可以用map压缩mapreduce输出到gzip “mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec” 是否可以直接为hadoop实现zip编解码器? Zip是容器,但每个存档只需要一个文件,那么使用CompressionCodec接口创建ZipCodec会很容易吗? 或者,也许有一种将gz文件转换为zip的有效方法,因为它们可以使用相同的deflate算法?

java gzip无法保留原始文件的扩展名

我正在使用GZIPOutputStream将一个xml文件gzip到gz文件,但是在压缩后我发现gz文件层次结构中缺少xml文件(.xml)的扩展名。 我需要保留扩展名,因为压缩的gz文件将被第三方系统使用,它希望在解压缩gz文件后获得.xml文件。 这有什么解决方案吗? 我的测试代码是: public static void main(String[] args) { compress(“D://test.xml”, “D://test.gz”); } private static boolean compress(String inputFileName, String targetFileName){ boolean compressResult=true; int BUFFER = 1024*4; byte[] B_ARRAY = new byte[BUFFER]; FileInputStream fins=null; FileOutputStream fout=null; GZIPOutputStream zout=null; try{ File srcFile=new File(inputFileName); fins=new FileInputStream (srcFile); File tatgetFile=new File(targetFileName); fout = new FileOutputStream(tatgetFile); zout = new GZIPOutputStream(fout); […]

如何从S3下载GZip文件?

我查看了AWS S3 Java SDK – 下载文件帮助和使用Java中的Zip和GZip文件 。 虽然它们提供了分别从S3和GZipped文件下载和处理文件的方法,但这些方法无法处理位于S3中的GZipped文件。 我该怎么办? 目前我有: try { AmazonS3 s3Client = new AmazonS3Client( new ProfileCredentialsProvider()); String URL = downloadURL.getPrimitiveJavaObject(arg0[0].get()); S3Object fileObj = s3Client.getObject(getBucket(URL), getFile(URL)); BufferedReader fileIn = new BufferedReader(new InputStreamReader( fileObj.getObjectContent())); String fileContent = “”; String line = fileIn.readLine(); while (line != null){ fileContent += line + “\n”; line = fileIn.readLine(); […]

在Java中将字符串压缩为gzip

public static String compressString(String str) throws IOException{ if (str == null || str.length() == 0) { return str; } ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(str.getBytes()); gzip.close(); Gdx.files.local(“gziptest.gzip”).writeString(out.toString(), false); return out.toString(); } 当我将该字符串保存到文件,并在unix中运行gunzip -d file.txt时,它会抱怨: gzip: gzip.gz: not in gzip format

使用jzlib创建gzip文件

我正在尝试使用jzlib创建一个gzip文件,这是一个开源的。 Java GZIPOutputStream有点问题,CPU越来越高,从未发布过。 JZlib的问题是文件无法通过winrar打开,似乎缺少标题。 知道怎么解决吗?

使用Linux上的Apache Commons Compression压缩文件时编码错误

我正在使用Apache Commons API Compression压缩文件。 Windows 7工作正常,但在Linux(ubuntu 10.10 – UTF8)中,文件名和文件夹名称中的字符(例如“º”)将替换为“?”。 在压缩时,或者在解压缩tar时,我应该将任何参数传递给API吗? 我使用tar.gz格式,遵循API示例。 我正在尝试压缩的文件是在windows中创建的……有什么问题吗? 代码: public class TarGzTest { public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { System.out.println(“Criando tar.gz da pasta ” + directoryPath + ” em ” + tarGzPath); FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = […]

在Wildfly配置GZip

我在Wildfly服务器中配置GZip时遇到问题,在服务器上使用了以下配置: 并且正确地成为了请求的Zip文件,但是我想设置要压缩的文件的最小大小以及我很难,任何人都知道如何设置服务器的最小大小然后将它们发送到顾客?