1 21 22 46 package com.izforge.izpack; 47 48 import java.io.File ; 49 import java.io.FileNotFoundException ; 50 import java.io.Serializable ; 51 import java.util.List ; 52 import java.util.Map ; 53 54 60 public class PackFile implements Serializable 61 { 62 63 static final long serialVersionUID = -834377078706854909L; 64 65 public static final int OVERRIDE_FALSE = 0; 66 67 public static final int OVERRIDE_TRUE = 1; 68 69 public static final int OVERRIDE_ASK_FALSE = 2; 70 71 public static final int OVERRIDE_ASK_TRUE = 3; 72 73 public static final int OVERRIDE_UPDATE = 4; 74 75 76 public transient String sourcePath = null; 79 protected String relativePath = null; 80 81 82 private String targetPath = null; 83 84 85 private List osConstraints = null; 86 87 88 private long length = 0; 89 90 91 private long mtime = -1; 92 93 94 private boolean isDirectory = false; 95 96 97 private int override = OVERRIDE_FALSE; 98 99 100 private Map additionals = null; 101 102 public int previousPackNumber = -1; 103 104 public long offsetInPreviousPack = -1; 105 106 116 public PackFile(File baseDir, File src, String target, List osList, int override) 117 throws FileNotFoundException 118 { 119 this(src, computeRelativePathFrom(baseDir, src), target, osList, override, null); 120 } 121 122 133 public PackFile(File src, String relativeSourcePath, String target, List osList, int override, Map additionals) 134 throws FileNotFoundException 135 { 136 if (!src.exists()) throw new FileNotFoundException ("No such file: " + src); 138 139 if ('/' != File.separatorChar) target = target.replace(File.separatorChar, '/'); 140 if (target.endsWith("/")) target = target.substring(0, target.length() - 1); 141 142 this.sourcePath = src.getPath(); 143 this.relativePath = relativeSourcePath; 144 145 this.targetPath = target; 146 this.osConstraints = osList; 147 this.override = override; 148 149 this.length = src.length(); 150 this.mtime = src.lastModified(); 151 this.isDirectory = src.isDirectory(); 152 this.additionals = additionals; 153 } 154 155 166 public PackFile(File baseDir, File src, String target, List osList, int override, Map additionals) 167 throws FileNotFoundException 168 { 169 this(src, computeRelativePathFrom(baseDir, src), target, osList, override, additionals); 170 } 171 172 178 public static String computeRelativePathFrom(File baseDir, File file) { 179 if (baseDir==null || file == null) return null; 180 try{ if (file.getCanonicalPath().startsWith(baseDir.getCanonicalPath())) 182 { 183 return file.getCanonicalPath().substring(baseDir.getCanonicalPath().length()); 184 } 185 } 186 catch(Exception x) { 188 x.printStackTrace(); 190 } 191 192 return null; 194 } 195 196 public void setPreviousPackFileRef(int previousPackNumber, long offsetInPreviousPack) 197 { 198 this.previousPackNumber = previousPackNumber; 199 this.offsetInPreviousPack = offsetInPreviousPack; 200 } 201 202 203 public final List osConstraints() 204 { 205 return osConstraints; 206 } 207 208 209 public final long length() 210 { 211 return length; 212 } 213 214 215 public final long lastModified() 216 { 217 return mtime; 218 } 219 220 221 public final int override() 222 { 223 return override; 224 } 225 226 public final boolean isDirectory() 227 { 228 return isDirectory; 229 } 230 231 public final boolean isBackReference() 232 { 233 return (previousPackNumber >= 0); 234 } 235 236 237 public final String getTargetPath() 238 { 239 return targetPath; 240 } 241 242 244 public String getRelativeSourcePath() 245 { 246 return relativePath; 247 } 248 249 254 public Map getAdditionals() 255 { 256 return additionals; 257 } 258 259 } 260 | Popular Tags |