测试 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)的更多相关文章

  1. Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)

    使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下: Caused by: java.lang.IllegalStateExcepti ...

  2. 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

    Spring接受前台的数据超过256出现例如以下异常: org.springframework.beans.InvalidPropertyException: Invalid property 'sp ...

  3. 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 ...

  4. Spring的java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!异常处理方法

    使用Spring提供的模板类HibernateDaoSupport,如果单纯的使用'命名参数'的形式编写HQL语句如: public class UserDaoImpl extends Hiberna ...

  5. 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30

    RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...

  6. listview 遇到问题java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

    开发的时候 遇到 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 这个异常有时候会有,有时候正常 不太好捕捉 猜测 已经 ...

  7. 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 ...

  8. mybatis 插入 含有美元符号($) 字符串 报 java.lang.IndexOutOfBoundsException: No group 2 的问题

    一:问题描述: 在springboot-security框架生成BCryptPasswordEncoder()方法生成加密后的密码后,带有$符号,导致新增用户的时候插入不了,报(IndexOutOfB ...

  9. 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 ...

随机推荐

  1. Oracle VM VirtualBox 安装CentOS 配置图形界面记录

    su yum groupinstall "X Window System" -y yum groupinstall "Desktop" -y 最后运行#star ...

  2. 基于暗通道优先算法的去雾应用(Matlab/C++)

    基于暗通道优先的单幅图像去雾算法(Matlab/C++) 算法原理:             参见论文:Single Image Haze Removal Using Dark Channel Pri ...

  3. solr update接口常用方法

    solr索引数据更新接口:http://localhost:8080/solr/update 有以下一些操作可以通过update接口完成,只能使用post的形式提交数据. 1.添加索引 确保field ...

  4. JavaScript对象状态

    有限状态机(Finite-state machine)是一个非常有用的模型,可以模拟世界上大部分事物. 简单说,它有三个特征: * 状态总数(state)是有限的. * 任一时刻,只处在一种状态之中. ...

  5. asp.net两种方式的短信接口使用(提供接口的都是收费的)

    一种是http请求的方式,另一种就是提供WebService接口供调用的. //服务商 sms.webchinese.cn //sms_url="http://sms.webchinese. ...

  6. Linux培训薪资过万是真事 星创客为嵌入式高端培训树标杆

    10月26日,是华清远见星创客嵌入式精英训练营首期班结业后的第15个工作日,虽然目前的学员就业成果已经超出了训练营老师们的预期,但就业工作仍然在继续进行着没有停止. 从训练营老师方面得出的统计数据,截 ...

  7. JDBC驱动自身问题引发的FullGC

    公众号HelloJava刊出一篇<MySQL Statement cancellation timer 故障排查分享>,作者的某服务的线上机器报 502(502是 nginx 做后端健康检 ...

  8. C#SerialPort如何读取串口数据并显示在TextBox上

    SerialPort中串口数据的读取与写入有较大的不同.由于串口不知道数据何时到达,因此有两种方法可以实现串口数据的读取.一.线程实时读串口:二.事件触发方式实现. 由于线程实时读串口的效率不是十分高 ...

  9. Linux Shell 重定向与管道【转帖】

    by 程默 在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以 ...

  10. Java序列化、反序列化和单例模式

    学习JAVA的时候,特别是涉及到网络编程时,我们时常让我们的实体类实现一个接口 public class Entity implements Serializable{ } 这样子我们可以通过输入输出 ...