1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
news = new URL(adresse);
if (LOGGER.isDebugEnabled())
LOGGER.debug("-------****** news: " + news);
HttpURLConnection urlconnection = (HttpURLConnection)news.openConnection();
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
urlconnection.setUseCaches (false);
urlconnection.setDefaultUseCaches (false);
urlconnection.setChunkedStreamingMode(chunk_size);
urlconnection.setRequestProperty("uris", sb.toString());
urlconnection.setReadTimeout(0);
OutputStreamWriter out = new OutputStreamWriter(urlconnection.getOutputStream());
out.write(sb.toString());
InputStream is = urlconnection.getInputStream();
int f = -1;
File tmpFile = File.createTempFile("documentation", ".zip");
byte buf[] = new byte[buf_size];
int length = 0;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile));
while ((length = is.read(buf)) > 0) {
bos.write(buf, 0, length);
}
bos.close();
is.close();
LOGGER.info("-------****** response: " + response.getOutputStream().toString());
response.setContentType("application/zip");
response.addHeader("Content-Disposition", "attachment; filename=" + tmpFile.getName());
response.setHeader("Cache-Control","max-age=" + 90000);
response.addHeader("Content-description","My Description");
byte[] docfile = loadFile(tmpFile.getPath());
response.setContentLength(docfile.length);
f = -1;
is = new FileInputStream(tmpFile);
copy(is, response.getOutputStream());
response.getOutputStream().flush();
is.close(); |
Partager