Помогите разобраться с download.
Проблема в следующем: Сервер Tomcat 6. Для закачки использую следующий код:
| Код | public String UploadFile(String url, File file) { String res = "0"; try { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter( CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
String tmpFileUrl = url;
HttpPost httppost = new HttpPost(tmpFileUrl);
MultipartEntity mpEntity = new MultipartEntity();
if (file.exists()) { ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("content", cbFile); }
httppost.setEntity(mpEntity); System.out .println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity ent = response.getEntity(); if ( ent != null) { res = EntityUtils.toString(response.getEntity()); ent.consumeContent(); }
httpclient.getConnectionManager().shutdown();
} catch (Exception e) { Log.Write("DeltaHTTP.UploadFile(String url, File file) = " + e.getMessage()); } return res; }
|
сервлет:
| Код | MultipartRequest mpr = new MultipartRequest(request, dir .getAbsolutePath(), 10 * 1024 * 1024);
|
работает прекрасно, быстро! Это важно.
Для выгрузки файла с сервлета использую следующий код:
| Код | private void doDownload(HttpServletRequest req, HttpServletResponse resp) throws IOException { String filename = req.getParameter("filename"); File f = new File(filename); ServletOutputStream op = resp.getOutputStream();
BufferedInputStream bis = new BufferedInputStream( new FileInputStream(f)); BufferedOutputStream bos = new BufferedOutputStream(op); int readbyte = 0; while ((bis != null) && ((readbyte = bis.read()) != -1)) { bos.write(readbyte); }
bos.flush(); bos.close(); }
|
работает раза в 4 медленнее.
Как ускорить выгрузку ? Может кто подскажет.
|