java.lang.IndexOutOfBoundsException at java.io.FileOutputStream.writeBytes(Native Method)
ss
available : 3212
/usr/linkapp/data/linkapp/ddn_1440639847758_temp
1024
1024
java.lang.IndexOutOfBoundsException
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:260)
at com.linkapp.ddn.DDNRestUtil.getData(DDNRestUtil.java:439)
at com.linkapp.ddn.DDNRestUtil.main(DDNRestUtil.java:88)
ss
public static byte[] getData(String oid) {
if (StringUtils.isEmpty(oid)) {
return null;
}
int nFileLength = -1;
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 >= 400) {
processErrorCode(responseCode);
return null; // -2 represent access is error
}
if (responseCode == HttpURLConnection.HTTP_OK) {
if (1==1) {
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 = 0;
int reads;
int onesize = available>1024?1024: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 = 0;
int off = 0;
available = inputStream.available();
byte[] b = new byte[1024];
while ((read = inputStream.read(b))!= -1) {
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;
}
왜 자꾸 안 되지???
이런 간단한 흐름 조작,
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.