Bonjour à tous,
Je en train d'effectuer un test de décompression d'un fichier de format .xml.gz en extension .xml que j'ai téléchargé par un de mes programmes java.
Seulement voilà j'ai une erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 try{ InputStream is = new FileInputStream(FichierZippe); CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is); IOUtils.copy(in, new FileOutputStream("E:/dossier/liste.xml")); in.close(); } catch(Exception e){ e.printStackTrace(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 Response content length: 1191994 java.util.zip.ZipException: oversubscribed literal/length tree at java.util.zip.InflaterInputStream.read(Unknown Source) at java.util.zip.GZIPInputStream.read(Unknown Source) at java.util.zip.InflaterInputStream.read(Unknown Source) at org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream.read(GzipCompressorInputStream.java:51) at java.io.InputStream.read(Unknown Source) at java.io.InputStream.read(Unknown Source) at org.apache.commons.compress.utils.IOUtils.copy(IOUtils.java:66) at org.apache.commons.compress.utils.IOUtils.copy(IOUtils.java:47) at org.apache.http.examples.client.ClientAuthentication.decompresseGZ(ClientAuthentication.java:288) at org.apache.http.examples.client.ClientAuthentication.main(ClientAuthentication.java:176)
Je voudrais savoir l'origine de cet erreur ?
Voici les packages utilisés provenant d'Apache :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HeaderElement; import org.apache.commons.httpclient.HttpException; import org.apache.http.HttpEntity; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpResponseInterceptor; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient;
Je vous montre également le code que j'utilise pour télécharger le fichier xml compressé par le protocole http avec authentification :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public static void main(String[] args) { try{ DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials( new AuthScope("siteweb.com", 80), new UsernamePasswordCredentials("utilisateur", "motdepasse")); HttpGet httpget = new HttpGet("http://siteweb.com/dossier/liste.xml.gz"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } if(entity != null){ BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent())); BufferedWriter out = new BufferedWriter(new FileWriter("E:/dossier/liste.xml.gz")); String chaine = null; chaine = in.readLine(); while(chaine != null) { out.write(chaine); chaine = in.readLine(); } in.close (); out.close(); } if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); decompresseGZ("E:/dossier/liste.xml.gz","E:/dossier/"); }catch(Exception e){ e.printStackTrace(); } }
Cordialement .
Partager