• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Applet & ZIp (The party is on)

 
carlos sanchez
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm developing an app n I'm stuck. I want to transfer a zip file through a signed applet (that's done).
I'm reading the responseOutputStream & trying to buiid the zip again, but It's no good .
This is a piece of the servlet.
---------------------------------
response.setContentType("application/zip ");
//response.setContentType("application/x-zip/compressed");
FileInputStream fis = new FileInputStream("C:\\Archivos de programa\\Apache Tomcat 4.0\\webapps\\ejemploApplet\\ejemploweb.zip");
BufferedInputStream in = new BufferedInputStream(fis);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
ServletOutputStream sos = response.getOutputStream();
int j;
while ((j = reader.read()) != -1)
sos.write(j);
reader.close();
sos.close();
--------------------------------------------------------
And this is the applet.
//Realizamos la conexion con el servlet que nos proporciona el stream.
URL url = new URL("http://localhost:8080/ejemploApplet/FicheroServlet");
URLConnection urlconnection = url.openConnection();

//Recuperamos el content type para cerciorarnos
mimetype = urlconnection.getContentType();

//Recuperamos el ZipInputStream con el que escribiremos en el fichero.
ZipInputStream in = new ZipInputStream(urlconnection.getInputStream());
ZipEntry myfile = in.getNextEntry();

System.out.println("Recuperando fichero: " + myfile.getName());
//Creamos el ZipOutputStream donde incluiremos el fichero.
FileOutputStream fos = new FileOutputStream("fichero.zip");
ZipOutputStream osw = new ZipOutputStream(fos);
//OutputStreamWriter osw = new OutputStreamWriter(fos);

int s3;
while ((s3 = in.read())> 0)
{
// como no tienen que ser m´┐Żltiplos, el final puede ser menos de 8K
osw.write(s3);
}
in.close();
osw.close();
fos.close();
---------------------------------------------------
I'm getting messed with wich streams to use. Thanks
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are just transferring a file, use the plain File*putStream classes. The Zip*putStream classes are for placing files into and retrieving files out of an archive file.
 
carlos sanchez
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that's what I've done, and finally I've been able to copy it.
Thanks!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!