0

      
       Язык Java 
      
     
      
       Работа с архивами 
       java.util.zip 
       java.util.jar 
      ...

      
       GZipInputStream 
      
     
      
       <ul>
        
         <li>class GZIPInputStream extends Inflat...

      
       GZipOutputStream 
      
     
      
       <ul>
        
         <li>class GZIPOutputStream extends Defl...

      
       Пример использования (упаковка) 
      
     
      
       <ul>
        
         <li>FileInputStream fi=n...

      
       Пример использования (распаковка)  
      
     
      
       <ul>
        
         <li>BufferedOutputStr...

      
       ZipInputStream 
      
     
      
       <ul>
        
         <li>class ZipInputStream extends Inflater...

      
       ZipOutputStream 
      
     
      
       <ul>
        
         <li>class ZipOutputStream extends Deflat...

      
       ZipEntry 
      
     
      
       <ul>
        
         <li>class ZipEntry implements ZipConstants, Clo...

      
       Пример использования 
      
     
      
       <ul>
        
         <li>public void createZip() {   try...

      
       Пример использования (продолжение) 
      
     
      
       <ul>
        
         <li>public void addFo...

      
       Пример использования (продолжение) 
      
     
      
       <ul>
        
         <li>public void addFi...

      
       Конец 
      
     
      
       Вопросы 
       e-mail: a.bovanenko@gmail.com
Upcoming SlideShare
Loading in...5
×

ZIP, GZIP Streams in java

1,469

Published on

It's about gzip and zip streams in java se.

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,469
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide




























































  • Transcript of "ZIP, GZIP Streams in java"

    1. 1. Язык Java Работа с архивами java.util.zip java.util.jar
    2. 2. GZipInputStream <ul> <li>class GZIPInputStream extends InflaterInputStream </ul> <ul> <li>public GZIPInputStream(InputStream in, int size) throws IOException </ul> <ul> <li>public GZIPInputStream(InputStream in) throws IOException </ul> <ul> <li>public int read(byte[] buf, int off, int len) throws IOException </ul> <ul> <li>public void close() throws IOException </ul>
    3. 3. GZipOutputStream <ul> <li>class GZIPOutputStream extends DeflaterOutputStream </ul> <ul> <li>public GZIPOutputStream(OutputStream out, int size) </ul> <ul> <li>public GZIPOutputStream(OutputStream out) throws IOException </ul> <ul> <li>public synchronized void write(byte[] buf, int off, int len) throws IOException </ul> <ul> <li>public void finish() throws IOException </ul>
    4. 4. Пример использования (упаковка) <ul> <li>FileInputStream fi=null; try{ try{ fi=new FileInputStream(&quot;in.txt&quot;); go=new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(&quot;out.gz&quot;))); int l=fi.available(); byte[] b=new byte[l]; fi.read(b); go.write(b); } finally{ if(go!=null) go.close(); if(fi!=null) fi.close(); } }catch(Exception e) { System.out.println(e); } </ul>
    5. 5. Пример использования (распаковка) <ul> <li>BufferedOutputStream bo = null; try { try { gi = new GZIPInputStream(new BufferedInputStream(new FileInputStream(&quot;out.gz&quot;))); int i=0; bo = new BufferedOutputStream(new FileOutputStream(&quot;out2.txt&quot;)); while((i=gi.read())!=-1) bo.write(i); } finally { if (gi != null) gi.close(); if (bo != null) bo.close(); } } catch (Exception e) { System.out.println(e); } </ul>
    6. 6. ZipInputStream <ul> <li>class ZipInputStream extends InflaterInputStream implements ZipConstants </ul> <ul> <li>public ZipInputStream(InputStream in) </ul> <ul> <li>public ZipEntry getNextEntry() throws IOException </ul> <ul> <li>public void closeEntry() throws IOException </ul> <ul> <li>public int available() throws IOException </ul> <ul> <li>public int read(byte[] b, int off, int len) throws IOException </ul> <ul> <li>public long skip(long n) throws IOException </ul> <ul> <li>public void close() throws IOException </ul>
    7. 7. ZipOutputStream <ul> <li>class ZipOutputStream extends DeflaterOutputStream implements ZipConstants </ul> <ul> <li>public ZipOutputStream(OutputStream out) </ul> <ul> <li>public void setComment(String comment) </ul> <ul> <li>public void setMethod(int method) </ul> <ul> <li>public void setLevel(int level) </ul> <ul> <li>public void putNextEntry(ZipEntry e) throws IOException </ul> <ul> <li>public void closeEntry() throws IOException </ul> <ul> <li>public synchronized void write(byte[] b, int off, int len) </ul> <ul> <li>public void finish() throws IOException </ul> <ul> <li>public void close() throws IOException </ul>
    8. 8. ZipEntry <ul> <li>class ZipEntry implements ZipConstants, Cloneable </ul> <ul> <li>public ZipEntry(String name) </ul> <ul> <li>public ZipEntry(ZipEntry e) </ul> <ul> <li>public String getName() </ul> <ul> <li>public void setTime(long time) </ul> <ul> <li>public long getTime() </ul> <ul> <li>public void setSize(long size) </ul> <ul> <li>public long getSize() </ul> <ul> <li>public long getCompressedSize() </ul> <ul> <li>public void setCompressedSize(long csize) </ul> <ul> <li>public void setMethod(int method) </ul> <ul> <li>public int getMethod() </ul> <ul> <li>public void setExtra(byte[] extra) </ul> <ul> <li>public byte[] getExtra() </ul> <ul> <li>public void setComment(String comment) </ul> <ul> <li>public String getComment() </ul>
    9. 9. Пример использования <ul> <li>public void createZip() { try { try { zo = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(s+&quot;.zip&quot;))); File f=new File(s); String s1=f.getPath(); addFolderToZip(zo,f.getName(),f); } finally { if (zo != null) { zo.close(); } } } catch (Exception e) { System.out.println(e); } } </ul>
    10. 10. Пример использования (продолжение) <ul> <li>public void addFolderToZip(ZipOutputStream zo, String path, File dir) { File[] fs = dir.listFiles(); for (File f : fs) { if (f.isFile()) { addFile(zo, path, f); } else { addFolderToZip(zo, path+&quot;amp;quot;+f.getName(), f); } } } </ul>
    11. 11. Пример использования (продолжение) <ul> <li>public void addFile(ZipOutputStream zo, String path, File f) { ZipEntry ze = new ZipEntry(path+&quot;amp;quot;+f.getName()); BufferedInputStream bi = null; try { try { zo.putNextEntry(ze); bi = new BufferedInputStream(new FileInputStream(f.getPath())); byte[] b = new byte[1024]; int i = 0; while ((i = bi.read(b)) != -1) zo.write(b, 0, i); } finally { zo.closeEntry(); if (bi != null) bi.close(); } } catch (IOException e) { System.out.println(e); } } </ul>
    12. 12. Конец Вопросы e-mail: a.bovanenko@gmail.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×