Legal,

é possível, uma vez criado package e repositório jar em uma aplicação para applet, ocorrer a descompactação automaticamente melhorando o desempenho de um applet? Caso negativo, qual a solução.

  Claudio Miranda <[EMAIL PROTECTED]> escreveu:


Aqui está uma classe que tenho há muito tempo, por favor se
melhorarem ela (sei que faltam algumas coisas) enviem de volta.

[]'s

Claudio


/*-------------------------------------------------------------------------*/
import java.util.zip.*;
import java.util.*;
import java.io.*;

/**
* This is an utility class to work with zip files.


*
* Basically has static methods for compress, uncompress.


*


*
* The default buffer size is 4096 bytes.


*
*


*
*@date 20/10/2000
*/
public class ZipHandler {

/**
* The default buffer size is 4096 bytes.
*/
public final static int BUFFER_SIZE = 4096;


// private instances can instantiate this class.
private ZipHandler() { }


/**
* This will compress all files contained in directory passed in
completePath
* parameter and the output is a zipped file specified by
destiny
* parameter.


*
* Example:



*


*
* File dir = new File ("/home/claudio/dir");

* File zippedFile = new File
("/home/claudio/myZippedFile.zip");

*

* ZipHandler.compress (dir, zippedFile);


*
*@param completePath a directory complete path. All filed inside
it will be
* compressed.
*@param destiny a complete file name path. The zipped file name.
*/
public static void compress(File completePath, File destiny) {
FileOutputStream fos = null;
ZipOutputStream zos = null;
try {
File[] f = completePath.listFiles();
fos = new FileOutputStream(destiny);
zos = new ZipOutputStream(fos);
for (int i = 0; i < f.length; i++) {
if (!f[i].isDirectory()) {
String fileName = f[i].getAbsolutePath();

FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(fileName);
bis = new BufferedInputStream(fis);

ZipEntry ze = new ZipEntry(f[i].getName());
zos.putNextEntry(ze);

byte[] block = new byte[BUFFER_SIZE];
int bytes_read = 0;
while ((bytes_read = bis.read(block)) != -1) {
zos.write(block, 0, bytes_read);
}
} finally {
zos.closeEntry();
close(bis);
close(fis);
}

}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
close(zos);
close(fos);
}
}



/**
* This will uncompress the file specified by zipFileName
* parameter and extract the files in tmp directory.


*
* Example:



*


*
* File zippedFile = new File
("/home/claudio/myZippedFile.zip");

*

* ZipHandler.uncompress (zippedFile);


*
*@param zipFileName the zipped file.
*/
public static void uncompress(File zipFileName) {
String fileName = zipFileName.getName().substring(0,
zipFileName.getName().lastIndexOf('.'));
File outputDir = new File(fileName);
outputDir.mkdirs();

uncompress(zipFileName, outputDir);
}

/**
* This will uncompress the file specified by zipFileName
* parameter and extract the files in tmp directory.


*
* Example:



*


*
* File zippedFile = new File
("c:\\any\\directory\\myZippedFile.zip");

*

* ZipHandler.uncompress (zippedFile);


*
*@param zipFileName the zipped file.
*/
public static void uncompress(File zipFileName, File outputDir) {
ZipFile zf = null;
try {
zf = new ZipFile(zipFileName);
Enumeration entries = zf.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();

// this will get ONLY the file name, without the path.
String entryName = new File(ze.getName()).getName();
InputStream in = null;
BufferedInputStream bis = null;
FileOutputStream fout = null;
try {
in = zf.getInputStream(ze);
bis = new BufferedInputStream(in);
fout = new FileOutputStream(new File(outputDir,
entryName));

int bytes_read = 0;
byte[] block = new byte[BUFFER_SIZE];
while ((bytes_read = bis.read(block)) != -1) {
fout.write(block, 0, bytes_read);
}
} finally {
close(bis);
close(in);
close(fout);
}

}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
zf.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

private static void close(InputStream in) {
try {
in.close();
} catch (IOException ioe) {
Log.println("IOException while closing a InputStream >> " +
ioe);
}
}


private static void close(OutputStream out) {
try {
out.close();
} catch (IOException ioe) {
Log.println("IOException while closing a OutputStream >> " +
ioe);
}
}
}



Vladimir wrote:

> Onde encontro essas classes?
>
> ----- Original Message -----
> *From:* Rodrigo Campos
> *To:* [EMAIL PROTECTED]
> *Sent:* Monday, June 10, 2002 7:57 AM
> *Subject:* RE: [java-list] Fazer Arquivo Zip.
>
> Tiago
>
> Com as classes :
>
> ZipOutputStream
> ZipEntry
> FileOutputStream
>
> voce consegue gerar um zip em java, no javadoc dessas classes
> existe exemplos e é bem simples de usar.
>
>
> -----Original Message-----
> *From:* Thiago Lutti [mailto:[EMAIL PROTECTED]]
> *Sent:* Friday, June 07, 2002 10:41 AM
> *To:* [EMAIL PROTECTED]
> *Subject:* [java-list] Fazer Arquivo Zip.
>
> Ola, estou tentando compactar uma pasta inteira, alguem sabe
> como fazer isso ??
>
> Obrigado,
>
> Thiago Ramalho Lutti
> PadTec - Optical Components and Systems
> Campinas / SP
> e-mail : [EMAIL PROTECTED]
> http://www.padtec.com.br
>
>



------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------


   ))    []s, Soares     http.vivavida!com
C|~~|
.`--'  http.macrosoft.tbm



Copa 2002
Yahoo! - Patrocinador oficial da Copa do Mundo da FIFA 2002

Responder a