线程“Smack-Cached Executor 10(0)”java.lang.IndexOutOfBoundsException中的异常是什么?
我使用Smack库在桌面应用程序的java中创建了一个客户端,并从Spark客户端接收文件会抛出此异常:
Exception in thread "Smack-Cached Executor 0 (0)" java.lang.IndexOutOfBoundsException
At java.io.FileOutputStream.writeBytes (Native Method)
At java.io.FileOutputStream.write (FileOutputStream.java:326)
At java.io.DataOutputStream.write (DataOutputStream.java:107)
At model.MessagingManagment $ 2.fileTransferRequest (MessagingManagment.java:171)
At org.jivesoftware.smackx.filetransfer.FileTransferManager $ 1.handleIQRequest (FileTransferManager.java:80)
At org.jivesoftware.smack.AbstractXMPPConnection $ 2.run (AbstractXMPPConnection.java:1061)
At java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
At java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617)
At java.lang.Thread.run (Thread.java:745)
这是接收我收到的文件的代码:
private void IncomingFileTransfer(){
FileTransferManager fileManage = FileTransferManager.getInstanceFor(ChatRoomConstants.connection);
fileManage.addFileTransferListener(new FileTransferListener() {
@Override
public void fileTransferRequest(FileTransferRequest request) {
try {
if (JOptionPane.showConfirmDialog(null,"receive the file?")==JOptionPane.YES_OPTION) {
IncomingFileTransfer transfer = request.accept();
InputStream inputStrea = transfer.recieveFile();
String filePath = new File(".").getCanonicalPath()+"\\ChatFiles";
File file = new File(filePath);
file.mkdirs();
File files = new File(filePath, transfer.getFileName());
DataOutputStream dataStream = new DataOutputStream(new FileOutputStream(files));
int reader;
byte[] buffer = new byte[2048]; //sujeto al tamaño disponible por el cache de lectura del DD
while ((reader=inputStrea.read(buffer,0,buffer.length))!=1) {
dataStream.write(buffer, 0, reader);
}
dataStream.flush();
dataStream.close();
}else{
request.reject();
}
} catch (SmackException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}finally{
}
}
});
}