java.lang.IndexOutOfBoundsException at java.io.FileOutputStream.writeBytes(Native Method)
测试 DDN wos 的时候出现错误:
available :
/usr/lk/data/linkapp/ddn_1440639847758_temp java.lang.IndexOutOfBoundsException
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:)
at com.lk.ddn.DDNRestUtil.getData(DDNRestUtil.java:)
at com.lk.ddn.DDNRestUtil.main(DDNRestUtil.java:)
相关代码是:
public static byte[] getData(String oid) {
if (StringUtils.isEmpty(oid)) {
return null;
}
int nFileLength = -;
String meta = "";
byte[] fileData = null;
try {
String httpurl = "http://"+host+"/cmd/get";
httpurl = "http://localhost/disk/myFileList.action";
httpurl = "http://localhost/register.jsp";
URL url = new URL(httpurl);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("GET");
// httpConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 " +
// "(KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36");
httpConnection.setRequestProperty("content-type", "application/octet-stream");
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true); int responseCode = httpConnection.getResponseCode();
if (responseCode >= ) {
processErrorCode(responseCode);
return null; // -2 represent access is error
} if (responseCode == HttpURLConnection.HTTP_OK) {
if (==) { InputStream inputStream = null;
try {
// inputStream = httpConnection.getInputStream();
// int available = inputStream.available();
// System.out.println(" available : " + available);
// fileData = new byte[available];
// int read = inputStream.read(fileData);
// System.out.println(" read : " + read);
// int read = 0;
// while ((read = inputStream.read(fileData)) != -1) {
//
// } // String contentEncoding = httpConnection.getContentEncoding();
// System.out.println(" contentEncoding : " + contentEncoding);
//
// inputStream = httpConnection.getInputStream();
// int available = inputStream.available();
// fileData = new byte[nFileLength];
// int read = inputStream.read(fileData);
// System.out.println(" read : " + read);
// while ((read = inputStream.read(fileData)) != -1) {
//
// } inputStream = httpConnection.getInputStream();
int available = inputStream.available();
System.out.println(" available : " + available); int offset = ;
int reads;
int onesize = available>?:available;
// fileData = new byte[nFileLength];
// fis.reset();
// while ((reads = inputStream.read(fileData,offset,onesize)) != -1) {
// //System.out.println(new String(b));
// offset += reads;
// if (onesize >= available - offset) {
// onesize = available - offset;
// if (onesize <= 0) {
// break;
// }
// }
// }
// while ((reads = inputStream.read(fileData)) != -1) {
// //System.out.println(new String(b));
// offset += reads;
// } String downlowdPath = getTempFileDownlowdPath();
System.out.println(downlowdPath);
FileOutputStream fos = new FileOutputStream(downlowdPath);
int read = ; int off = ;
available = inputStream.available();
byte[] b = new byte[];
while ((read = inputStream.read(b))!= -) {
System.out.println(read);
fos.write(b,off,read);
off += read;
}
if (b != null) {
// fos.write(b);
}
System.out.println("readed : " + read);
inputStream.close();
fos.flush();
fos.close();
//
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
inputStream.close();
}
} }
} } catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return fileData; }
为什么总是不行呢???
这样的简单流操作、、
java.lang.IndexOutOfBoundsException at java.io.FileOutputStream.writeBytes(Native Method)的更多相关文章
- Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)
使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...
- 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
Spring接受前台的数据超过256出现例如以下异常: org.springframework.beans.InvalidPropertyException: Invalid property 'sp ...
- hive脚本出现Error: java.lang.RuntimeException: Error in configuring object和Caused by: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
是在reduce阶段报的错误,详细错误信息是 朱传豪 19:04:48 Diagnostic Messages for this Task: Error: java.lang.RuntimeExcep ...
- Spring的java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!异常处理方法
使用Spring提供的模板类HibernateDaoSupport,如果单纯的使用'命名参数'的形式编写HQL语句如: public class UserDaoImpl extends Hiberna ...
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...
- listview 遇到问题java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
开发的时候 遇到 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 这个异常有时候会有,有时候正常 不太好捕捉 猜测 已经 ...
- Caused by: java.lang.ClassNotFoundException: flex.messaging.io.BeanProxy
1.错误描述 2014-7-13 1:34:46 org.apache.catalina.startup.HostConfig undeploy 信息: Undeploying context [/b ...
- mybatis 插入 含有美元符号($) 字符串 报 java.lang.IndexOutOfBoundsException: No group 2 的问题
一:问题描述: 在springboot-security框架生成BCryptPasswordEncoder()方法生成加密后的密码后,带有$符号,导致新增用户的时候插入不了,报(IndexOutOfB ...
- maven发布到tomcat报错: Publishing failed Could not publish to the server. java.lang.IndexOutOfBoundsException
eclipse中将maven项目发布到tomcat报错时: Publishing failed Could not publish to the server. java.lang.IndexOutO ...
随机推荐
- 该不该在C#中使用var关键词
作为一个并不勤快的程序猿,在项目开发过程中总是想尽办法少写代码,对var关键词的使用自然不会放过,几乎在每个能使用var的地方都用了var,对此,很多朋友同事给出了不同的建议,觉得能不使用var关键词 ...
- POJ 1160 题解
Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18835 Accepted: 10158 Des ...
- BestCoder Round 70
惨败,不能再嘲笑别人了,否则自己也会像别人那样倒霉 HDU 5615:http://acm.hdu.edu.cn/showproblem.php?pid=5615 求ax^2+bx+c能否拆成(px+ ...
- Java jvisualvm简要说明
jvisualvm能干什么:监控内存泄露,跟踪垃圾回收,执行时内存.cpu分析,线程分析... jvisualvm已经被集成在jdk1.6以上的版本中(不是jre).自身运行需要最低jdk1.6版本, ...
- C# base64 Img 互转
[AcceptVerbs(HttpVerbs.Post)] public JsonResult Upload(HttpPostedFileBase fileData) { try { if (file ...
- bootstrap之排版类
bootstrap之排版类
- xcode8 升级后注释快键键不能使用的解决方法
1.这个是因为苹果解决xcode ghost.把插件屏蔽了.解决方法 命令运行: sudo /usr/libexec/xpccachectl 然后必须重启电脑后生效 2.option+command ...
- Salesforce学习资料
官方文档下载网址:https://developer.salesforce.com/docs 关于Salesforce的所有官方文档都在以上的地址之中,可以进行在线预览和下载 推荐新手学习以下几本文档 ...
- ORA-12560: TNS: 协议适配器错误
解决方案: 在开始菜单搜索 services.msc,进入本地服务 将 OracleOraDb11g_home1ClrAgent,OracleOraDb11g_home1TNSListener,Ora ...
- 【Beta】Daily Scrum Meeting第七次
1.任务进度 学号 已完成 接下去要做 502 发布任务到服务器 测试 509 将各api的处理逻辑放到类里面 让主api调用这些类 517 删除任务和教师的控件及逻辑 提交报课审核信息 530 完善 ...