1 16 package org.apache.commons.vfs.provider.tar; 17 18 import java.io.InputStream ; 19 import java.util.HashSet ; 20 21 import org.apache.commons.compress.archivers.tar.TarEntry; 22 import org.apache.commons.vfs.FileName; 23 import org.apache.commons.vfs.FileObject; 24 import org.apache.commons.vfs.FileSystemException; 25 import org.apache.commons.vfs.FileType; 26 import org.apache.commons.vfs.provider.AbstractFileObject; 27 28 31 public class TarFileObject 32 extends AbstractFileObject 33 implements FileObject 34 { 35 private final HashSet children = new HashSet (); 36 private final TarFileSystem fs; 37 protected TarEntry entry; 38 private FileType type; 39 40 protected TarFileObject(FileName name, 41 TarEntry entry, 42 TarFileSystem fs, 43 boolean tarExists) throws FileSystemException 44 { 45 super(name, fs); 46 this.fs = fs; 47 setTarEntry(entry); 48 if (!tarExists) 49 { 50 type = FileType.IMAGINARY; 51 } 52 } 53 54 57 protected void setTarEntry(final TarEntry entry) 58 { 59 if (this.entry != null) 60 { 61 return; 62 } 63 64 if ((entry == null) || (entry.isDirectory())) 65 { 66 type = FileType.FOLDER; 67 } 68 else 69 { 70 type = FileType.FILE; 71 } 72 73 this.entry = entry; 74 } 75 76 79 protected void attachChild(FileName childName) 80 { 81 children.add(childName.getBaseName()); 82 } 83 84 87 public boolean isWriteable() 88 { 89 return false; 90 } 91 92 95 protected FileType doGetType() 96 { 97 return type; 98 } 99 100 103 protected String [] doListChildren() 104 { 105 return (String []) children.toArray(new String [children.size()]); 106 } 107 108 112 protected long doGetContentSize() 113 { 114 if (entry == null) 115 { 116 return 0; 117 } 118 119 return entry.getSize(); 120 } 121 122 125 protected long doGetLastModifiedTime() throws Exception 126 { 127 if (entry == null) 128 { 129 return 0; 130 } 131 132 return entry.getModTime().getTime(); 133 } 134 135 141 protected InputStream doGetInputStream() throws Exception 142 { 143 return fs.getInputStream(entry); 144 } 145 } 146 | Popular Tags |