首页 技术 正文
技术 2022年11月12日
0 收藏 890 点赞 4,750 浏览 3043 个字

测试 DDN wos 的时候出现错误:

 available :
/usr/lk/data/linkapp/ddn_1440639847758_tempjava.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; }

为什么总是不行呢???

这样的简单流操作、、

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,497
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298