Bom, acho que estou postando no lugar certo...
O seguinte, fiz um script de download de arquivo, mas claro, isso é básico, o que estou com problemas é, caso a pessoa interrompa o download, quero saber se tem como ele continuar tal download mais tarde
O link de download pega ID do arquivo encriptado, por exemplo, http://XXXXX/d/ID_DO_ARQUIVO
A função de download seria essa
private void doDownload(File fileDown, FileInstance fileInst, AccountInstance user, HttpServletResponse response, String clientIp)
{
DownloadLog downLog = DownloadLog.getInstance();
response.setContentType(fileInst.getMime());
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileInst.getName() + "\"");
response.setContentLength((int) fileDown.length());
InputStream inFile = null;
OutputStream outFile = null;
long startTime = System.currentTimeMillis();
long endTime;
int downSpeed = Config.MAX_CLIENT_DSPEED;
int fileId = fileInst.getObjectId();
long fileSize = fileInst.getSize();
long readSize = 0;
int userId = (user != null) ? user.getObjectId() : 0;
if (user != null && user.getPremiumTime() > startTime)
downSpeed = (int) fileDown.length();
int cLogId = downLog.newCDLog(fileId, startTime, 0, userId, clientIp);
try
{
outFile = response.getOutputStream();
inFile = new FileInputStream(fileDown);
//System.out.println(inFile);
int i = 0;
byte buffer[] = new byte[downSpeed * 1024];
while ((i = inFile.read(buffer)) != -1)
{
outFile.write(buffer, 0, i);
outFile.flush();
readSize += i;
downLog.updCDLog(1, cLogId);
Thread.sleep(1000);
}
}
catch (IOException ex) { }
catch (Exception ex) { }
finally
{
endTime = System.currentTimeMillis();
downLog.updCDLog(2, cLogId);
if (readSize >= fileSize)
downLog.newDLog(fileId, startTime, endTime, userId, clientIp);
if (outFile != null)
{
try
{
outFile.flush();
outFile.close();
}
catch (IOException ex) {}
}
if (inFile != null)
{
try
{
inFile.close();
}
catch (IOException ex) {}
}
}
}