1 16 package org.apache.commons.vfs.provider.zip; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystemException; 21 import org.apache.commons.vfs.FileType; 22 import org.apache.commons.vfs.provider.AbstractFileObject; 23 24 import java.io.InputStream ; 25 import java.util.HashSet ; 26 import java.util.zip.ZipEntry ; 27 28 33 public class ZipFileObject 34 extends AbstractFileObject 35 implements FileObject 36 { 37 private final HashSet children = new HashSet (); 38 private final ZipFileSystem fs; 39 protected ZipEntry entry; 41 private FileType type; 42 43 protected ZipFileObject(FileName name, 44 ZipEntry entry, 45 ZipFileSystem fs, 46 boolean zipExists) throws FileSystemException 47 { 48 super(name, fs); 49 this.fs = fs; 50 setZipEntry(entry); 51 if (!zipExists) 52 { 53 type = FileType.IMAGINARY; 54 } 55 } 56 57 60 protected void setZipEntry(final ZipEntry entry) 61 { 62 if (this.entry != null) 63 { 64 return; 65 } 66 67 if ((entry == null) || (entry.isDirectory())) 68 { 69 type = FileType.FOLDER; 70 } 71 else 72 { 73 type = FileType.FILE; 74 } 75 76 this.entry = entry; 77 } 78 79 82 public void attachChild(FileName childName) 83 { 84 children.add(childName.getBaseName()); 85 } 86 87 90 public boolean isWriteable() 91 { 92 return false; 93 } 94 95 98 protected FileType doGetType() 99 { 100 return type; 101 } 102 103 106 protected String [] doListChildren() 107 { 108 return (String []) children.toArray(new String [children.size()]); 109 } 110 111 115 protected long doGetContentSize() 116 { 117 return entry.getSize(); 118 } 119 120 123 protected long doGetLastModifiedTime() throws Exception 124 { 125 return entry.getTime(); 126 } 127 128 134 protected InputStream doGetInputStream() throws Exception 135 { 136 return fs.getZipFile().getInputStream(entry); 137 } 138 } 139 | Popular Tags |