1 11 package org.eclipse.ui.internal.wizards.datatransfer; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.IOException ; 16 import java.io.InputStream ; 17 import java.util.Enumeration ; 18 import java.util.zip.GZIPInputStream ; 19 20 27 public class TarFile { 28 private File file; 29 private TarInputStream entryEnumerationStream; 30 private TarEntry curEntry; 31 private TarInputStream entryStream; 32 33 40 public TarFile(File file) throws TarException, IOException { 41 this.file = file; 42 43 InputStream in = new FileInputStream (file); 44 try { 46 in = new GZIPInputStream (in); 47 } catch(IOException e) { 48 in.close(); 51 in = new FileInputStream (file); 52 } 53 entryEnumerationStream = new TarInputStream(in); 54 curEntry = entryEnumerationStream.getNextEntry(); 55 } 56 57 62 public void close() throws IOException { 63 entryEnumerationStream.close(); 64 } 65 66 73 public TarFile(String filename) throws TarException, IOException { 74 this(new File (filename)); 75 } 76 77 82 public Enumeration entries() { 83 return new Enumeration () { 84 public boolean hasMoreElements() { 85 return (curEntry != null); 86 } 87 88 public Object nextElement() { 89 TarEntry oldEntry = curEntry; 90 try { 91 curEntry = entryEnumerationStream.getNextEntry(); 92 } catch(TarException e) { 93 curEntry = null; 94 } catch(IOException e) { 95 curEntry = null; 96 } 97 return oldEntry; 98 } 99 }; 100 } 101 102 110 public InputStream getInputStream(TarEntry entry) throws TarException, IOException { 111 if(entryStream == null || !entryStream.skipToEntry(entry)) { 112 InputStream in = new FileInputStream (file); 113 try { 115 in = new GZIPInputStream (in); 116 } catch(IOException e) { 117 in = new FileInputStream (file); 118 } 119 entryStream = new TarInputStream(in, entry) { 120 public void close() { 121 } 123 }; 124 } 125 if(entryStream == null) { 126 System.out.println("huh?"); } 128 return entryStream; 129 } 130 131 136 public String getName() { 137 return file.getPath(); 138 } 139 } 140 | Popular Tags |