Hello All !

I have a problem when i am trying to  zip and send data over the internet
using the URLConnection Object.It works fine up to 12 MB but after that it
throws an OutofMemoryError.Actually the same code works for any amount of
data when i used Sockets ...but it doesnt work when i use URL Connection
Object.Here is my code ..which zips the data and writes it to an
OutputStream byte by byte .
Any help will be greately Appreciated .
It works fine when  i increase the Java heap Size but thats not what i am
looking for .I also noticed that When i used the URLConnection Object ,its
trying to read the whole data before it writes and flushes the OutputStream
...but with normal sockets it was flushed immediately so i could read and
write any amount of data .Please tell me if thers a work around.
Thanx in Advance

try{
       byte[] buf = new byte[1024];
       URL url=new URL("http://localhost/servlet/ZipServlet");
       URLConnection  con;
       con =url.openConnection();
       con.setDoOutput(true);
       con.setDoInput(true);
       con.setAllowUserInteraction(true);
       con.setUseCaches(false);
       con.setRequestProperty("Content-Type","application/octet-stream");
       OutputStream ostream =con.getOutputStream();
       ZipOutputStream out = new ZipOutputStream(ostream);
       // Add ZIP entry to output stream.
       double TotalBytes=0.0;
       for(int i=0;i<args.length;i++){
           File zipentryFile=new File(args[i]);
           FileInputStream in = new FileInputStream(zipentryFile);
           ZipEntry entry=new ZipEntry(args[i]);
           out.putNextEntry(entry);
           int len;
           while ((len = in.read(buf)) > 0) {
                  out.write(buf, 0, len);
                  out.flush();//at this point its supposed to flush the
output stream but its not doing so
               TotalBytes=TotalBytes+len;
           }
           out.closeEntry();
           in.close();
       }
       out.close();
       System.out.println("Total number of bytes Sent"+TotalBytes);
       System.out.println("Waiting for Server Response....");
       BufferedReader reader =new BufferedReader(new
InputStreamReadercon.getInputStream()));
                  boolean more=true;
                  while(more){
                       String line=reader.readLine();
                       if(line==null){
                          more=false;
                       }
                       else
                       System.out.println(line);
                  }
           }
           catch (IOException e) {
               System.out.println(e);
               e.printStackTrace();
           }




________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to