|
|
@ -85,24 +85,35 @@ public class PluginUtils { |
|
|
|
public static void downloadShopScripts(String id, Process<Double> p) throws Exception { |
|
|
|
public static void downloadShopScripts(String id, Process<Double> p) throws Exception { |
|
|
|
HttpClient httpClient = new HttpClient(getDownloadPath(id)); |
|
|
|
HttpClient httpClient = new HttpClient(getDownloadPath(id)); |
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
int totalSize = httpClient.getContentLength(); |
|
|
|
InputStream reader = null; |
|
|
|
InputStream reader = httpClient.getResponseStream(); |
|
|
|
FileOutputStream writer = null; |
|
|
|
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); |
|
|
|
try { |
|
|
|
StableUtils.makesureFileExist(new File(temp)); |
|
|
|
int totalSize = httpClient.getContentLength(); |
|
|
|
FileOutputStream writer = new FileOutputStream(temp); |
|
|
|
reader = httpClient.getResponseStream(); |
|
|
|
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); |
|
|
|
int bytesRead = 0; |
|
|
|
StableUtils.makesureFileExist(new File(temp)); |
|
|
|
int totalBytesRead = 0; |
|
|
|
writer = new FileOutputStream(temp); |
|
|
|
|
|
|
|
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
while ((bytesRead = reader.read(buffer)) > 0) { |
|
|
|
int bytesRead = 0; |
|
|
|
writer.write(buffer, 0, bytesRead); |
|
|
|
int totalBytesRead = 0; |
|
|
|
buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
|
|
|
|
totalBytesRead += bytesRead; |
|
|
|
while ((bytesRead = reader.read(buffer)) > 0) { |
|
|
|
p.process(totalBytesRead / (double) totalSize); |
|
|
|
writer.write(buffer, 0, bytesRead); |
|
|
|
|
|
|
|
buffer = new byte[PluginConstants.BYTES_NUM]; |
|
|
|
|
|
|
|
totalBytesRead += bytesRead; |
|
|
|
|
|
|
|
p.process(totalBytesRead / (double) totalSize); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
throw new Exception(); |
|
|
|
|
|
|
|
}finally { |
|
|
|
|
|
|
|
if(null != reader){ |
|
|
|
|
|
|
|
reader.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(null != writer){ |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
|
|
|
|
writer.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
|
|
|
|
writer.close(); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); |
|
|
|
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); |
|
|
|
} |
|
|
|
} |
|
|
|