Error sending files greater than 4MB please help urgent!!!!!
sathish
Ranch Hand
Joined: Apr 25, 2000
Posts: 33
posted
0
Hi guys Having problems sending files greater than 4MB through my program, it is not able to send it. It looks like the server receive the correct file, but the contents are not going through Attached below is the file Server(Testconn) and client-(Httptest) Please help Thanks sathish ______________________________________________________________ import java.io.*; import java.net.*; import java.util.*; import java.util.zip.ZipFile; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class HttpTest extends Frame implements ActionListener { ZipFile zip = null; java.awt.List list = null; //The zip file name. String filename = null; MenuItem mOpen, mQuit; public static void main(String args[]) { new HttpTest(); } public HttpTest() { setTitle("UnZip Tool");
setLayout(new BorderLayout(3, 3)); add(new Label("Http URL Test: Open a jar/zip file, it will visit your Servlet and go back."), "North"); list = new java.awt.List(20, true); add(list, "Center"); MenuBar mb = new MenuBar(); setMenuBar(mb); Menu mFile = new Menu("File"); mb.add(mFile); mOpen = new MenuItem ("Open", new MenuShortcut('O')); mFile.add(mOpen); mFile.addSeparator(); mQuit = new MenuItem("Quit", new MenuShortcut('Q')); mFile.add(mQuit); mOpen.addActionListener(this); mQuit.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { quit(); } }); setBounds(100,100, 400, 600); show(); } void open() { FileDialog f = new FileDialog(this, "Open a Zip File", FileDialog.LOAD); f.show();
if(f.getFile() == null) { return; } try { filename = new File(f.getDirectory(), f.getFile()).getAbsolutePath(); //FileInputStream fis = new FileInputStream(filename); //ZipInputStream zis = new ZipInputStream(fis); zip = new HTTPComu(new File(filename)).getZipFile(); list.removeAll(); ZipEntry entry; if (zip == null) { return; }
////Send back //ObjectOutputStream out = new ObjectOutputStream(buffer);
res.setBufferSize(data.length + 10240); ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream()); out.writeObject(hash); System.out.println("Start to sending back!"); //FileInputStream filein = new FileInputStream(output); //data = getFileData(filein); //filein.close(); out.writeObject(data); System.out.println("Writing data!"); //res.setBufferSize(buffer.size() + 1024); //res.setContentLength(buffer.size()); out.close(); System.out.println("Sending back finished!" + data.length); } catch (Exception e) { System.out.println("Reading data error " + e); e.printStackTrace(); } } public byte[] getFileData(InputStream in) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = 2048; byte data[] = new byte[size]; int readedSize; long count = 0; while((readedSize = in.read(data, 0, size)) != -1) { out.write(data, 0, readedSize); count += readedSize; } System.out.println("\tReading file ! " + count);
out.close();
return out.toByteArray(); } public String getServletInfo() { return "Echo what it gets from client"; } }
sathish
Ranch Hand
Joined: Apr 25, 2000
Posts: 33
posted
0
the problem occurs when A(Client) ------> Establishes a HttpUrlConnection ---->B(Server) B(Server) -----> Receives the request and sends back ----> A(Client) --->Timeout occurs and not able to send the contents.. Why? Is that related to the file size??? Please help Thanks sathish
sathish
Ranch Hand
Joined: Apr 25, 2000
Posts: 33
posted
0
Is any one out there to help me??? thanks
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
I think people might like to help you, but find the large amount of code you have posted somewhat daunting. Can you put together a smaller code example which demonstrates this (say 30 lines or less?) which the rest of us can easily pick up and run on our own systems to try and work out what the problem is? Remember that everyone here is doing this on a purely voluntary basis, and there are always lots of other questions to answer. The more precise and readable your question is, the more likely someone is to want to answer it.
Please note that The Java Ranch has a naming policy, described here and "sathish" is not a valid name. Please choose one which meets the requirements. Thanks.
asad ali
Greenhorn
Joined: Dec 12, 2000
Posts: 20
posted
0
I tried your application on my PC and it works. Following is my environment 1. Windows NT workstation 4.0 2. Using JRun 3.0 for servlet 3. Using JDK1.2.2 4. My zip file size is 4,965 KB I commented the line res.setBufferSize(data.length + 10240); in your servlet's doPost method as it is not recognized method for response interface.
sathish
Ranch Hand
Joined: Apr 25, 2000
Posts: 33
posted
0
Hi Asad ali Thanks for your reply, but when you comment out the res.setbuffersize line from the doPost method, the first time it executes doesn't work, however, can you try sending files of the size 5.00MB ++? And, if you keep sending files repeatedly, it fails to respond, and i have also submitted it to the sun developer site. Thanks for your reply sathish