62,614
社区成员
发帖
与我相关
我的任务
分享
File newFile = new File("../../spa_client/" + appName);
long length = newFile.length();
System.out.println(appName + ":" + length);
oos.writeLong(length);
oos.flush();
String md5Str = DigestUtils.md5Hex(new FileInputStream(newFile));
oos.writeUTF(md5Str);
oos.flush();
if (SystemTray.isSupported()) {
textArea.append(appName + ":" + length+ "\n");
}
DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(newFile)));
ps = new DataOutputStream(socket.getOutputStream());
int bufferSize = 8192;
byte[] buf = new byte[bufferSize];
int s = 0;
while (true) {
int read = 0;
if (fis != null) {
read = fis.read(buf);
s += read;
}
if (read == -1) {
break;
}
ps.write(buf, 0, read);
ps.flush();
}
fis.close();
File newFile = new File(fileName);
FileOutputStream fos = new FileOutputStream(newFile);
dis = new DataInputStream(socket.getInputStream());
String oldMd5 = ois.readUTF();
byte[] b = new byte[1024];
int length = 0;
if (SystemTray.isSupported()) {
textArea.append("Downloading " + runningFileName + "..." + "\n");
}
logger.info("Downloading the " + runningFileName + " from server");
System.out.println("Downloading the " + runningFileName + " from server");
int fileLong = 0;
while ((length = dis.read(b)) != -1) {
fileLong += length;
fos.write(b, 0, length);
fos.flush();
System.out.println(fileLong);
if (fileLong == fileLength) {
break;
}
}
fos.close();
httpclient = HttpClients.custom().build();
response = httpclient
.execute(SendRecJsonUtil.downloadFile(ConvertUtil.updateURL, installUrl));
entity = response.getEntity();
byte[] buffer = new byte[1024];
int size = 0;
is = entity.getContent();
bis = new BufferedInputStream(is);
fos = new FileOutputStream(newFile);
logger.info("Downloading the " + runningFileName + " from network");
System.out.println("Downloading " + runningFileName);
// save file
while ((size = bis.read(buffer)) != -1) {
fos.write(buffer, 0, size);
fos.flush();
}
logger.info(runningFileName + " download complete");
System.out.println("Download completed!Sending " + runningFileName);
DataInputStream fis = new DataInputStream(
new BufferedInputStream(new FileInputStream(newFile)));
// DataOutputStream ps = new
// DataOutputStream(socket.getOutputStream());
long fileLength = newFile.length();
oos.writeLong(fileLength);
oos.flush();
int bufferSize = 8192;
byte[] buf = new byte[bufferSize];
while (true) {
int read = 0;
if (fis != null) {
read = fis.read(buf);
}
if (read == -1) {
break;
}
ps.write(buf, 0, read);
}
ps.flush();
fos.close();
bis.close();
is.close();
fis.close();
httpclient.close();
这是从网上下载文件下来再发送过去,同样的接收端,但这个却没问题