使用TarOutputStream出现 request to write '1024' bytes exceeds size in header错误的解决方法
因为测试流程中,所测客户端会根据服务器A返回的response决定发送给服务器B的请求里各参数的值,所以现在需要模拟服务器的响应。而这个项目服务器A的响应式返回一个流,一个GZIP压缩格式流,压缩的是多个文件,所以需要编写相应的groovy脚本。我这里使用了apache的ant包。不过在运行的时候出错了。错误提示如下
Caught: java.io.IOException: request to write '1024' bytes exceeds size in header of '29886' bytes for entry 'rate.csv'
java.io.IOException: request to write '1024' bytes exceeds size in header of '29886' bytes for entry 'rate.csv'
at org.apache.tools.tar.TarOutputStream.write(TarOutputStream.java:279)
at org.apache.tools.tar.TarOutputStream.write(TarOutputStream.java:260)
at org.apache.tools.tar.TarOutputStream$write.call(Unknown Source)
at temp.packFile(temp.groovy:26)
at temp.process(temp.groovy:51)
at temp.run(temp.groovy:55)。
按照字面意思,然后仔细看了下api文档read(byte[] b), read(byte[] b,int off, int len), write(byte[] wBuf), write(byte[] wBuf, int wOffset, int numToWrite)的相关解释后, 经过尝试,终于解决了。看来我以前读取文件和写入文件使用一个参数的方法的习惯不好,虽然之前都没有出问题,但是这次就出现了,以后还是使用read(byte[] b,int off, int len)和write(byte[] wBuf, int wOffset, int numToWrite),这样就能避免这个错误的再次发生了。
附上代码
import java.util.zip.GZIPOutputStream
import org.apache.tools.tar.TarEntry
import org.apache.tools.tar.TarOutputStream
public void packFile(String... filePath){
int num=filePath.length;
String targetPath=filePath[num-1]
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(targetPath));
TarOutputStream tos=new TarOutputStream(bos);
tos.setLongFileMode(TarOutputStream.LONGFILE_GNU);
for(int i=0;i<num-1;i++){
File sourceFile=new File(filePath[i]);
TarEntry te=new TarEntry(sourceFile.getName());
te.setSize(sourceFile.length());
println(sourceFile.length())
tos.putNextEntry(te);
byte[] buffer=new byte[1024];
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(sourceFile));
int count=0
while((count=bis.read(buffer,0,1024))>-1){
tos.write(buffer,0,count);
}
tos.closeEntry();
tos.flush();
bis.close();
}
tos.close();
}
public void compressFile(String filePath){
FileInputStream fis=new FileInputStream(filePath);
GZIPOutputStream gos=new GZIPOutputStream(new FileOutputStream(filePath+".gz"));
byte[] buffer=new byte[1024];
while(fis.read(buffer)>-1){
gos.write(buffer);
}
fis.close();
gos.finish();
gos.close();
}
public void process() {
String sourcePath1="D:/rate.csv";
String sourcePath2="D:/plan.csv";
String tarPath="D:/test/test.tar";
packFile(sourcePath1,sourcePath2,tarPath);
compressFile(tarPath);
}
process();
使用TarOutputStream出现 request to write '1024' bytes exceeds size in header错误的解决方法的更多相关文章
- Got a packet bigger than‘max_allowed_packet’bytes错误的解决方法
通常项目上线前都有一些初始化数据需要导入,在今天博客系统发布前我使用sqlyog工具远程登录服务器的Mysql数据库,执行sql脚本对初始数据进行导入的时候报错: Got a packet bigge ...
- .NET上传大文件时提示Maximum request length exceeded错误的解决方法
使用IIS托管应用程序时,当我们需要上传大文件(4MB以上)时,应用程序会提示Maximum request length exceeded的错误信息.该错误信息的翻译:超过最大请求长度. 解决方法: ...
- 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法
今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...
- 今天发现猎豹浏览器的一个大坑 Request.IsAuthenticated 一直为 false;另外附加原因以及临时的解决方法
今天掉到了一个大坑里面,爬了1个多小时才发现不是代码的问题,居然是浏览器的问题… 下面是问题的发生过程 单点登陆 有2个站点 http://a.abc.com http://b.abc.com ...
- Request method 'POST' not supported错误和解决方法
在使用SpringBoot的时候,在html页面用form表单post提交数据的时候报错: Request method 'POST' not supported 错误解析: 我是用的前端页面是HTM ...
- 网页出现400 Bad Request Request Header Or Cookie Too Large错误的解决方法
在开发项目过程中,突然遇到400 Bad Request Request Header Or Cookie Too Large的报错,我也是第一次出现这样的错误,感觉还是挺新奇的. 分析下出现错误的原 ...
- MySQL导入数据报 Got a packet bigger than‘max_allowed_packet’bytes 错误的解决方法
MySQL根据配置文件会限制Server接受的数据包大小.有时候大的插入和更新会受 max_allowed_packet 参数限制,导致大数据写入或者更新失败. 通过终端进入mysql控制台,输入如下 ...
- nginx过一段时间出现400 Bad Request 错误的解决方法
tomcat整合nginx成功后,等访问一段时间后,会出现 Bad Request (Invalid Hostname)的错误, 因为是已经成功的配置,所以判定可能是哪里的限制设置有问题,最后在官方网 ...
- 【Azure 应用服务】PHP应用部署在App Service for Linux环境中,上传文件大于1MB时,遇见了413 Request Entity Too Large 错误的解决方法
问题描述 在PHP项目部署在App Service后,上传文件如果大于1MB就会遇见 413 Request Entity Too Large 的问题. 问题解决 目前这个问题,首先需要分析应用所在的 ...
随机推荐
- STL(multiset) UVA 11020 Efficient Solutions
题目传送门 题意:训练指南P228 分析:照着书上的做法,把点插入后把它后面不占优势的点删除,S.size ()就是优势的人数,时间复杂度O (nlogn) #include <bits/std ...
- iOS UITextField的returnkey点击事件
关于隐藏软键盘,网上的办法良莠不齐,大多是通过实现UITextFieldDelegate来隐藏软键盘,该方法代码较多,且在文本框很多的时不好处理.我经过搜索与摸索,找到了最佳的处理办法.(引用的) ...
- CSS font 复合属性的顺序
CSS 参考手册 实例 在一个声明中设置所有字体属性: p.ex1 { font:italic arial,sans-serif; } p.ex2 { font:italic bold 12px/20 ...
- BestCoder#15 A-LOVE(暴力)
Love Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- ural 1070. Local Time
1070. Local Time Time limit: 1.0 secondMemory limit: 64 MB Soon the USU team will go to Vancouver to ...
- sqlite 数据类型 全面
http://blog.csdn.net/jin868/article/details/5961263 一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断.SQ ...
- 【CF】438E. The Child and Binary Tree
http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...
- 两种不同png图片的在项目中的运用
png图片主要分为两种 png-8和png-24. PNG8和PNG24后面的数字则是代表这种PNG格式最多可以索引和存储的颜色值.”8″代表2的8次方也就是256色,而24则代表2的24次方大概有1 ...
- C#_生成HTML
#region 生成静态页 /// <summary> /// 生成静态页 /// </summary> /// <param name="URL"& ...
- python 之redis
redis是一个key-value存储系统,与memcached类似,它支持存储到value类型相对更多,包括string(字符串),list(列表),set(集合),zset(sorted set ...