|
37 | 37 | import java.util.Random; |
38 | 38 |
|
39 | 39 | import swingjs.JSFileSystem.JSPath; |
40 | | -import swingjs.JSTempFile; |
41 | 40 |
|
42 | 41 |
|
43 | 42 |
|
@@ -143,6 +142,8 @@ public class File |
143 | 142 |
|
144 | 143 |
|
145 | 144 | public byte[] 秘bytes; // filled in by SwingJS ajax call or drag-drop from JSDnD |
| 145 | + |
| 146 | + public boolean 秘isTempFile; |
146 | 147 | // |
147 | 148 | // /** |
148 | 149 | // * The FileSystem object representing the platform's local file system. |
@@ -232,34 +233,6 @@ public File(String pathname) { |
232 | 233 | // this.prefixLength = fs.prefixLength(this.path); |
233 | 234 | } |
234 | 235 |
|
235 | | - /** |
236 | | - * Internal constructor for already-normalized pathname strings. |
237 | | - */ |
238 | | - private File(String pathname, int prefixLength) { |
239 | | - this.path = pathname; |
240 | | - this.prefixLength = prefixLength; |
241 | | - } |
242 | | - |
243 | | - /** |
244 | | - * Internal constructor for already-normalized pathname strings. |
245 | | - * The parameter order is used to disambiguate this method from the |
246 | | - * public(File, String) constructor. |
247 | | - */ |
248 | | - private File(String child, File parent) { |
249 | | - assert parent.path != null; |
250 | | - assert (!parent.path.equals("")); |
251 | | - this.path = resolve(parent.path, child); |
252 | | - this.prefixLength = parent.prefixLength; |
253 | | - } |
254 | | - |
255 | | - private String resolve(String path, String child) { |
256 | | - if (path == "." && child.startsWith("./")) |
257 | | - return child; |
258 | | - if (child.length() > 0 && !child.startsWith("/") && !path.endsWith("/")) |
259 | | - path += "/"; |
260 | | - return path + child; |
261 | | - } |
262 | | - |
263 | 236 | /* Note: The two-argument File constructors do not interpret an empty |
264 | 237 | parent abstract pathname as the current user directory. An empty parent |
265 | 238 | instead causes the child to be resolved against the system-dependent |
@@ -298,14 +271,12 @@ public File(String parent, String child) { |
298 | 271 | } |
299 | 272 | if (parent != null) { |
300 | 273 | if (parent.equals("") && !child.startsWith("/")) { |
301 | | - this.path = resolve(".", child); // fs.resolve(fs.getDefaultParent(), |
302 | | - // fs.normalize(child)); |
| 274 | + this.path = resolve(".", fs.normalize(child)); |
303 | 275 | } else { |
304 | | - this.path = resolve(parent, child);// fs.resolve(fs.normalize(parent), |
305 | | - // fs.normalize(child)); |
| 276 | + this.path = resolve(fs.normalize(parent), fs.normalize(child)); |
306 | 277 | } |
307 | 278 | } else { |
308 | | - this.path = resolve(".", child);// normalize(child); |
| 279 | + this.path = resolve(".", fs.normalize(child)); |
309 | 280 | } |
310 | 281 | this.prefixLength = this.path.lastIndexOf("/") + 1; // 1efixLength(this.path); |
311 | 282 | } |
@@ -355,76 +326,108 @@ public File(File parent, String child) { |
355 | 326 | // this.prefixLength = fs.prefixLength(this.path); |
356 | 327 | } |
357 | 328 |
|
358 | | - // /** |
359 | | - // * Creates a new <tt>File</tt> instance by converting the given |
360 | | - // * <tt>file:</tt> URI into an abstract pathname. |
361 | | - // * |
362 | | - // * <p> The exact form of a <tt>file:</tt> URI is system-dependent, hence |
363 | | - // * the transformation performed by this constructor is also |
364 | | - // * system-dependent. |
365 | | - // * |
366 | | - // * <p> For a given abstract pathname <i>f</i> it is guaranteed that |
367 | | - // * |
368 | | - // * <blockquote><tt> |
369 | | - // * new File(</tt><i> f</i><tt>.{@link #toURI() |
370 | | - // toURI}()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() |
371 | | - // getAbsoluteFile}()) |
372 | | - // * </tt></blockquote> |
373 | | - // * |
374 | | - // * so long as the original abstract pathname, the URI, and the new abstract |
375 | | - // * pathname are all created in (possibly different invocations of) the same |
376 | | - // * Java virtual machine. This relationship typically does not hold, |
377 | | - // * however, when a <tt>file:</tt> URI that is created in a virtual machine |
378 | | - // * on one operating system is converted into an abstract pathname in a |
379 | | - // * virtual machine on a different operating system. |
380 | | - // * |
381 | | - // * @param uri |
382 | | - // * An absolute, hierarchical URI with a scheme equal to |
383 | | - // * <tt>"file"</tt>, a non-empty path component, and undefined |
384 | | - // * authority, query, and fragment components |
385 | | - // * |
386 | | - // * @throws NullPointerException |
387 | | - // * If <tt>uri</tt> is <tt>null</tt> |
388 | | - // * |
389 | | - // * @throws IllegalArgumentException |
390 | | - // * If the preconditions on the parameter do not hold |
391 | | - // * |
392 | | - // * @see #toURI() |
393 | | - // * @see java.net.URI |
394 | | - // * @since 1.4 |
395 | | - // */ |
396 | | - // public File(URI uri) { |
397 | | - // |
398 | | - // // Check our many preconditions |
399 | | - // if (!uri.isAbsolute()) |
400 | | - // throw new IllegalArgumentException("URI is not absolute"); |
401 | | - // if (uri.isOpaque()) |
402 | | - // throw new IllegalArgumentException("URI is not hierarchical"); |
403 | | - // String scheme = uri.getScheme(); |
404 | | - // if ((scheme == null) || !scheme.equalsIgnoreCase("file")) |
405 | | - // throw new IllegalArgumentException("URI scheme is not \"file\""); |
406 | | - // if (uri.getAuthority() != null) |
407 | | - // throw new IllegalArgumentException("URI has an authority component"); |
408 | | - // if (uri.getFragment() != null) |
409 | | - // throw new IllegalArgumentException("URI has a fragment component"); |
410 | | - // if (uri.getQuery() != null) |
411 | | - // throw new IllegalArgumentException("URI has a query component"); |
412 | | - // String p = uri.getPath(); |
413 | | - // if (p.equals("")) |
414 | | - // throw new IllegalArgumentException("URI path component is empty"); |
415 | | - // |
416 | | - // // Okay, now initialize |
417 | | - // p = fs.fromURIPath(p); |
418 | | - // if (File.separatorChar != '/') |
419 | | - // p = p.replace('/', File.separatorChar); |
420 | | - // this.path = fs.normalize(p); |
421 | | - // this.prefixLength = fs.prefixLength(this.path); |
422 | | - // } |
423 | | - // |
| 329 | + /** |
| 330 | + * Creates a new <tt>File</tt> instance by converting the given <tt>file:</tt> |
| 331 | + * URI into an abstract pathname. |
| 332 | + * |
| 333 | + * <p> |
| 334 | + * The exact form of a <tt>file:</tt> URI is system-dependent, hence the |
| 335 | + * transformation performed by this constructor is also system-dependent. |
| 336 | + * |
| 337 | + * <p> |
| 338 | + * For a given abstract pathname <i>f</i> it is guaranteed that |
| 339 | + * |
| 340 | + * <blockquote><tt> |
| 341 | + * new File(</tt><i> f</i><tt>.{@link #toURI() |
| 342 | + toURI}()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() |
| 343 | + getAbsoluteFile}()) |
| 344 | + * </tt></blockquote> |
| 345 | + * |
| 346 | + * so long as the original abstract pathname, the URI, and the new abstract |
| 347 | + * pathname are all created in (possibly different invocations of) the same Java |
| 348 | + * virtual machine. This relationship typically does not hold, however, when a |
| 349 | + * <tt>file:</tt> URI that is created in a virtual machine on one operating |
| 350 | + * system is converted into an abstract pathname in a virtual machine on a |
| 351 | + * different operating system. |
| 352 | + * |
| 353 | + * @param uri An absolute, hierarchical URI with a scheme equal to |
| 354 | + * <tt>"file"</tt>, a non-empty path component, and undefined |
| 355 | + * authority, query, and fragment components |
| 356 | + * |
| 357 | + * @throws NullPointerException If <tt>uri</tt> is <tt>null</tt> |
| 358 | + * |
| 359 | + * @throws IllegalArgumentException If the preconditions on the parameter do not |
| 360 | + * hold |
| 361 | + * |
| 362 | + * @see #toURI() |
| 363 | + * @see java.net.URI |
| 364 | + * @since 1.4 |
| 365 | + */ |
| 366 | + public File(URI uri) { |
| 367 | + |
| 368 | + String err = null, scheme, p; |
| 369 | + // Check our many preconditions |
| 370 | + if (!uri.isAbsolute()) |
| 371 | + err = ("URI is not absolute"); |
| 372 | + else if (uri.isOpaque()) |
| 373 | + err = ("URI is not hierarchical"); |
| 374 | + else if (((scheme = uri.getScheme()) == null) || !scheme.equalsIgnoreCase("file")) |
| 375 | + err = ("URI scheme is not \"file\""); |
| 376 | + else if (uri.getAuthority() != null) |
| 377 | + err = ("URI has an authority component"); |
| 378 | + else if (uri.getFragment() != null) |
| 379 | + err = ("URI has a fragment component"); |
| 380 | + else if (uri.getQuery() != null) |
| 381 | + err = ("URI has a query component"); |
| 382 | + else if ((p = uri.getPath()).equals("")) |
| 383 | + err = ("URI path component is empty"); |
| 384 | + else { |
| 385 | + // Okay, now initialize |
| 386 | + p = fs.fromURIPath(p); |
| 387 | +// if (File.separatorChar != '/') |
| 388 | +// p = p.replace('/', File.separatorChar); |
| 389 | + this.path = //fs.normalize |
| 390 | + (p); |
| 391 | + this.prefixLength = fs.prefixLength(this.path); |
| 392 | + return; |
| 393 | + } |
| 394 | + throw new IllegalArgumentException(err); |
| 395 | + } |
| 396 | + |
424 | 397 |
|
425 | 398 | /* -- Path-component accessors -- */ |
426 | 399 |
|
427 | | - /** |
| 400 | + /** |
| 401 | + * Internal constructor for already-normalized pathname strings. |
| 402 | + */ |
| 403 | + private File(String pathname, int prefixLength) { |
| 404 | + this.path = pathname; |
| 405 | + this.prefixLength = prefixLength; |
| 406 | + } |
| 407 | + |
| 408 | + /** |
| 409 | + * Internal constructor for already-normalized pathname strings. |
| 410 | + * The parameter order is used to disambiguate this method from the |
| 411 | + * public(File, String) constructor. |
| 412 | + */ |
| 413 | + private File(String child, File parent) { |
| 414 | +// assert parent.path != null; |
| 415 | +// assert (!parent.path.equals("")); |
| 416 | + this.path = resolve(parent.path, child); |
| 417 | + this.prefixLength = parent.prefixLength; |
| 418 | + } |
| 419 | + |
| 420 | + private String resolve(String path, String child) { |
| 421 | + if (path == "." && child.startsWith("./")) |
| 422 | + return child; |
| 423 | + if (child.length() > 0 && !child.startsWith("/") && !path.endsWith("/")) |
| 424 | + path += "/"; |
| 425 | + path = path + child; |
| 426 | + this.秘isTempFile = path.startsWith(temporaryDirectory); |
| 427 | + return path; |
| 428 | + } |
| 429 | + |
| 430 | + /** |
428 | 431 | * Returns the name of the file or directory denoted by this abstract |
429 | 432 | * pathname. This is just the last name in the pathname's name |
430 | 433 | * sequence. If the pathname's name sequence is empty, then the empty |
@@ -891,13 +894,7 @@ public boolean isFile() { |
891 | 894 | * method denies read access to the file |
892 | 895 | */ |
893 | 896 | public long length() { |
894 | | -// SecurityManager security = System.getSecurityManager(); |
895 | | -// if (security != null) { |
896 | | -// security.checkRead(path); |
897 | | -// } |
898 | | -// return fs.getLength(this); |
899 | | - return (/** @j2sNative this.秘bytes ? this.秘bytes.length : */0); |
900 | | - |
| 897 | + return fs.getLength(this); |
901 | 898 | } |
902 | 899 |
|
903 | 900 |
|
@@ -1752,7 +1749,9 @@ private static File generateFile(String prefix, String suffix, File dir) |
1752 | 1749 | } else { |
1753 | 1750 | n = Math.abs(n); |
1754 | 1751 | } |
1755 | | - return new JSTempFile(dir, prefix + Long.toString(n) + suffix); |
| 1752 | + File f = new File(dir, prefix + Long.toString(n) + suffix); |
| 1753 | + f.秘isTempFile = true; |
| 1754 | + return f; |
1756 | 1755 | } |
1757 | 1756 | // |
1758 | 1757 | // private static boolean checkAndCreate(String filename, SecurityManager sm, |
|
0 commit comments