OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 141 → Rev 142

/trunk/OpenConcerto/src/org/openconcerto/utils/Zip.java
16,6 → 16,7
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
23,9 → 24,12
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.Set;
import java.util.zip.CRC32;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
38,6 → 42,44
*/
public class Zip {
 
static public byte[] deflate(final String s) throws IOException {
return deflate(s.getBytes(StringUtils.UTF8));
}
 
static public byte[] deflate(final byte[] b) throws IOException {
final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
final DeflaterOutputStream out = new DeflaterOutputStream(bOut);
out.write(b);
out.close();
return bOut.toByteArray();
}
 
static public ByteBuffer deflateToBuffer(final String s) throws IOException {
return ByteBuffer.wrap(deflate(s));
}
 
static public String inflateToString(final ByteBuffer payload) throws IOException {
return inflateToString(payload, payload.remaining());
}
 
static public String inflateToString(final ByteBuffer payload, final int length) throws IOException {
final byte[] b = new byte[length];
payload.get(b);
return inflateToString(b);
}
 
static public String inflateToString(final byte[] b) throws IOException {
return new String(inflate(b), StringUtils.UTF8);
}
 
static public byte[] inflate(final byte[] b) throws IOException {
final InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(b));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtils.copy(in, out);
out.close();
return out.toByteArray();
}
 
/**
* Copie de from dans to seulement les entrées dont le nom n'est pas dans
* <code>excludedEntries</code>.
50,12 → 92,12
* @throws ZipException
* @throws IOException
*/
static public Zip createFrom(File from, File to, Set excludedEntries) throws ZipException, IOException {
static public Zip createFrom(File from, File to, Set<String> excludedEntries) throws ZipException, IOException {
Unzip unz = new Unzip(from);
Zip res = new Zip(to);
final Enumeration en = unz.entries();
final Enumeration<? extends ZipEntry> en = unz.entries();
while (en.hasMoreElements()) {
ZipEntry entry = (ZipEntry) en.nextElement();
final ZipEntry entry = en.nextElement();
if (!excludedEntries.contains(entry.getName())) {
res.zip(entry.getName(), unz.getInputStream(entry));
}
73,7 → 115,7
* @throws ZipException
* @throws IOException
*/
static public void delete(File src, Set entriesName, File dest) throws ZipException, IOException {
static public void delete(File src, Set<String> entriesName, File dest) throws ZipException, IOException {
if (dest.exists())
dest.delete();
createFrom(src, dest, entriesName).close();