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 ...
随机推荐
- java对象转换成json
package com.bjs.acrosstime.utils; import java.util.ArrayList; import java.util.Date; import java.uti ...
- ASP.NET 给作为隐藏域的TextBox赋值之后提交表单,无响应?
操作步骤: 给页面隐藏TextBox赋值,然后触发ASP.NET change事件,调用ASP.NET后台方法,调用后执行客户端脚本this.RegisterClientScriptBlock(Dat ...
- python学习 2数学公式
递归 def fact(n): if n <= 1: return 1 else: return n * fact(n - 1) 斐波那契数列: 第0项是0,第1项是1,从第2项开始,每一项都等 ...
- 2016-2-1 Servlet细节
Servlet的一些细节(韩顺平老师视频讲解)(1)由于客户端是通过URL地址访问web服务器中的资源,所以Servlet程序想要被外界访问,必须把servlet程序映射到一个URL地址上.这个工作在 ...
- Proxy setting
1. git git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 2. gradleScena ...
- Python for Infomatics 第13章 网页服务三(译)
注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 13.6 应用程序接口API 现 ...
- [BZOJ1997][HNOI2010] 平面图判定
Description Input Output 是的..BZOJ样例都没给. 题解(from 出题人): 如果只考虑简单的平面图判定,这个问题是非常不好做的. 但是题目中有一个条件— ...
- oracle 和c3p0 数据库的Time_Wait 过多问题的一个解决方案。
项目是B/S模式,放在linux服务器上,tomcat和oracle11g在一台服务器上,tomcat读取数据库采用C3P0连接池,一直比较稳定,所以也没有去管.后来把tomcat放在一台win200 ...
- 【Java】JDK类 CountDownLatch
一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数 初始化 CountDownLatch.由于调用了 countDown() 方法,所以在当前计数到达 ...
- jquery checked
jquery判断checked的三种方法:.attr('checked): //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false.prop('c ...