~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/nio/fs/NetFileSystemProvider.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2011 Jeroen Frijters
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
 
 
23
*/
 
24
 
 
25
package sun.nio.fs;
 
26
 
 
27
import ikvm.internal.NotYetImplementedError;
 
28
import static ikvm.internal.Util.WINDOWS;
 
29
import cli.System.IO.Directory;
 
30
import cli.System.IO.DirectoryInfo;
 
31
import cli.System.IO.DriveInfo;
 
32
import cli.System.IO.File;
 
33
import cli.System.IO.FileAttributes;
 
34
import cli.System.IO.FileInfo;
 
35
import cli.System.IO.FileMode;
 
36
import cli.System.IO.FileShare;
 
37
import cli.System.IO.FileStream;
 
38
import cli.System.IO.FileOptions;
 
39
import cli.System.Security.AccessControl.FileSystemRights;
 
40
import com.sun.nio.file.ExtendedOpenOption;
 
41
import java.io.FileDescriptor;
 
42
import java.io.IOException;
 
43
import java.net.URI;
 
44
import java.nio.channels.*;
 
45
import java.nio.file.*;
 
46
import java.nio.file.attribute.*;
 
47
import java.nio.file.spi.FileSystemProvider;
 
48
import java.util.concurrent.ExecutorService;
 
49
import java.util.Iterator;
 
50
import java.util.HashMap;
 
51
import java.util.Map;
 
52
import java.util.NoSuchElementException;
 
53
import java.util.Set;
 
54
import sun.nio.ch.WindowsAsynchronousFileChannelImpl;
 
55
import sun.nio.ch.FileChannelImpl;
 
56
import sun.nio.ch.ThreadPool;
 
57
 
 
58
final class NetFileSystemProvider extends AbstractFileSystemProvider
 
59
{
 
60
    private final NetFileSystem fs = new NetFileSystem(this);
 
61
    private final HashMap<String, FileStore> stores = new HashMap<String, FileStore>();
 
62
 
 
63
    final synchronized FileStore getFileStore(DriveInfo drive) throws IOException
 
64
    {
 
65
        String name = drive.get_Name().toLowerCase();
 
66
        FileStore fs = stores.get(name);
 
67
        if (fs == null)
 
68
        {
 
69
            fs = new NetFileStore(drive);
 
70
            stores.put(name, fs);
 
71
        }
 
72
        return fs;
 
73
    }
 
74
 
 
75
    public String getScheme()
 
76
    {
 
77
        return "file";
 
78
    }
 
79
 
 
80
    public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException
 
81
    {
 
82
        throw new FileSystemAlreadyExistsException();
 
83
    }
 
84
 
 
85
    public FileSystem getFileSystem(URI uri)
 
86
    {
 
87
        return fs;
 
88
    }
 
89
 
 
90
    public Path getPath(URI uri)
 
91
    {
 
92
        if (WINDOWS)
 
93
        {
 
94
            return WindowsUriSupport.fromUri(fs, uri);
 
95
        }
 
96
        else
 
97
        {
 
98
            return UnixUriUtils.fromUri(fs, uri);
 
99
        }
 
100
    }
 
101
 
 
102
    public AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set<? extends OpenOption> opts, ExecutorService executor, FileAttribute<?>... attrs) throws IOException
 
103
    {
 
104
        NetPath npath = NetPath.from(path);
 
105
        for (FileAttribute<?> attr : attrs)
 
106
        {
 
107
            // null check
 
108
            attr.getClass();
 
109
            throw new NotYetImplementedError();
 
110
        }
 
111
        int mode = FileMode.Open;
 
112
        int share = FileShare.ReadWrite | FileShare.Delete;
 
113
        int options = FileOptions.Asynchronous;
 
114
        boolean read = false;
 
115
        boolean write = false;
 
116
        boolean truncate = false;
 
117
        for (OpenOption opt : opts)
 
118
        {
 
119
            if (opt instanceof StandardOpenOption)
 
120
            {
 
121
                switch ((StandardOpenOption)opt)
 
122
                {
 
123
                    case CREATE:
 
124
                        mode = FileMode.Create;
 
125
                        break;
 
126
                    case CREATE_NEW:
 
127
                        mode = FileMode.CreateNew;
 
128
                        break;
 
129
                    case DELETE_ON_CLOSE:
 
130
                        options |= FileOptions.DeleteOnClose;
 
131
                        break;
 
132
                    case DSYNC:
 
133
                        options |= FileOptions.WriteThrough;
 
134
                        break;
 
135
                    case READ:
 
136
                        read = true;
 
137
                        break;
 
138
                    case SPARSE:
 
139
                        break;
 
140
                    case SYNC:
 
141
                        options |= FileOptions.WriteThrough;
 
142
                        break;
 
143
                    case TRUNCATE_EXISTING:
 
144
                        truncate = true;
 
145
                        break;
 
146
                    case WRITE:
 
147
                        write = true;
 
148
                        break;
 
149
                    default:
 
150
                        throw new UnsupportedOperationException();
 
151
                }
 
152
            }
 
153
            else if (opt instanceof ExtendedOpenOption)
 
154
            {
 
155
                switch ((ExtendedOpenOption)opt)
 
156
                {
 
157
                    case NOSHARE_READ:
 
158
                        share &= ~FileShare.Read;
 
159
                        break;
 
160
                    case NOSHARE_WRITE:
 
161
                        share &= ~FileShare.Write;
 
162
                        break;
 
163
                    case NOSHARE_DELETE:
 
164
                        share &= ~FileShare.Delete;
 
165
                        break;
 
166
                    default:
 
167
                        throw new UnsupportedOperationException();
 
168
                }
 
169
            }
 
170
            else
 
171
            {
 
172
                // null check
 
173
                opt.getClass();
 
174
                throw new UnsupportedOperationException();
 
175
            }
 
176
        }
 
177
 
 
178
        if (!read && !write)
 
179
        {
 
180
            read = true;
 
181
        }
 
182
 
 
183
        if (truncate)
 
184
        {
 
185
            if (mode == FileMode.Open)
 
186
            {
 
187
                mode = FileMode.Truncate;
 
188
            }
 
189
        }
 
190
 
 
191
        int rights = 0;
 
192
        if (read)
 
193
        {
 
194
            rights |= FileSystemRights.Read;
 
195
        }
 
196
        if (write)
 
197
        {
 
198
            rights |= FileSystemRights.Write;
 
199
        }
 
200
 
 
201
        ThreadPool pool;
 
202
        if (executor == null)
 
203
        {
 
204
            pool = null;
 
205
        }
 
206
        else
 
207
        {
 
208
            pool = ThreadPool.wrap(executor, 0);
 
209
        }
 
210
 
 
211
        return WindowsAsynchronousFileChannelImpl.open(open(npath.path, mode, rights, share, options), read, write, pool);
 
212
    }
 
213
 
 
214
    public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> opts, FileAttribute<?>... attrs) throws IOException
 
215
    {
 
216
        return newFileChannel(path, opts, attrs);
 
217
    }
 
218
 
 
219
    public FileChannel newFileChannel(Path path, Set<? extends OpenOption> opts, FileAttribute<?>... attrs) throws IOException
 
220
    {
 
221
        NetPath npath = NetPath.from(path);
 
222
        for (FileAttribute<?> attr : attrs)
 
223
        {
 
224
            // null check
 
225
            attr.getClass();
 
226
            throw new NotYetImplementedError();
 
227
        }
 
228
        int mode = FileMode.Open;
 
229
        int share = FileShare.ReadWrite | FileShare.Delete;
 
230
        int options = FileOptions.None;
 
231
        boolean read = false;
 
232
        boolean write = false;
 
233
        boolean append = false;
 
234
        boolean truncate = false;
 
235
        for (OpenOption opt : opts)
 
236
        {
 
237
            if (opt instanceof StandardOpenOption)
 
238
            {
 
239
                switch ((StandardOpenOption)opt)
 
240
                {
 
241
                    case APPEND:
 
242
                        append = true;
 
243
                        write = true;
 
244
                        mode = FileMode.Append;
 
245
                        break;
 
246
                    case CREATE:
 
247
                        mode = FileMode.Create;
 
248
                        break;
 
249
                    case CREATE_NEW:
 
250
                        mode = FileMode.CreateNew;
 
251
                        break;
 
252
                    case DELETE_ON_CLOSE:
 
253
                        options |= FileOptions.DeleteOnClose;
 
254
                        break;
 
255
                    case DSYNC:
 
256
                        options |= FileOptions.WriteThrough;
 
257
                        break;
 
258
                    case READ:
 
259
                        read = true;
 
260
                        break;
 
261
                    case SPARSE:
 
262
                        break;
 
263
                    case SYNC:
 
264
                        options |= FileOptions.WriteThrough;
 
265
                        break;
 
266
                    case TRUNCATE_EXISTING:
 
267
                        truncate = true;
 
268
                        break;
 
269
                    case WRITE:
 
270
                        write = true;
 
271
                        break;
 
272
                    default:
 
273
                        throw new UnsupportedOperationException();
 
274
                }
 
275
            }
 
276
            else if (opt instanceof ExtendedOpenOption)
 
277
            {
 
278
                switch ((ExtendedOpenOption)opt)
 
279
                {
 
280
                    case NOSHARE_READ:
 
281
                        share &= ~FileShare.Read;
 
282
                        break;
 
283
                    case NOSHARE_WRITE:
 
284
                        share &= ~FileShare.Write;
 
285
                        break;
 
286
                    case NOSHARE_DELETE:
 
287
                        share &= ~FileShare.Delete;
 
288
                        break;
 
289
                    default:
 
290
                        throw new UnsupportedOperationException();
 
291
                }
 
292
            }
 
293
            else
 
294
            {
 
295
                // null check
 
296
                opt.getClass();
 
297
                throw new UnsupportedOperationException();
 
298
            }
 
299
        }
 
300
 
 
301
        if (!read && !write)
 
302
        {
 
303
            read = true;
 
304
        }
 
305
 
 
306
        if (read && append)
 
307
        {
 
308
            throw new IllegalArgumentException("READ + APPEND not allowed");
 
309
        }
 
310
        
 
311
        if (truncate)
 
312
        {
 
313
            if (append)
 
314
            {
 
315
                throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
 
316
            }
 
317
            if (mode == FileMode.Open)
 
318
            {
 
319
                mode = FileMode.Truncate;
 
320
            }
 
321
        }
 
322
        
 
323
        int rights = 0;
 
324
        if (append)
 
325
        {
 
326
            // for atomic append to work, we can't set FileSystemRights.Write
 
327
            rights |= FileSystemRights.AppendData;
 
328
        }
 
329
        else
 
330
        {
 
331
            if (read)
 
332
            {
 
333
                rights |= FileSystemRights.Read;
 
334
            }
 
335
            if (write)
 
336
            {
 
337
                rights |= FileSystemRights.Write;
 
338
            }
 
339
        }
 
340
 
 
341
        return FileChannelImpl.open(open(npath.path, mode, rights, share, options), read, write, append, null);
 
342
    }
 
343
 
 
344
    private static FileDescriptor open(String path, int mode, int rights, int share, int options) throws IOException
 
345
    {
 
346
        SecurityManager sm = System.getSecurityManager();
 
347
        if (sm != null)
 
348
        {
 
349
            if ((rights & FileSystemRights.Read) != 0)
 
350
            {
 
351
                sm.checkRead(path);
 
352
            }
 
353
            if ((rights & (FileSystemRights.Write | FileSystemRights.AppendData)) != 0)
 
354
            {
 
355
                sm.checkWrite(path);
 
356
            }
 
357
            if ((options & FileOptions.DeleteOnClose) != 0)
 
358
            {
 
359
                sm.checkDelete(path);
 
360
            }
 
361
        }
 
362
 
 
363
        try
 
364
        {
 
365
            if (false) throw new cli.System.ArgumentException();
 
366
            if (false) throw new cli.System.IO.FileNotFoundException();
 
367
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
368
            if (false) throw new cli.System.PlatformNotSupportedException();
 
369
            if (false) throw new cli.System.IO.IOException();
 
370
            if (false) throw new cli.System.Security.SecurityException();
 
371
            if (false) throw new cli.System.UnauthorizedAccessException();
 
372
            return FileDescriptor.fromStream(new FileStream(path, FileMode.wrap(mode), FileSystemRights.wrap(rights), FileShare.wrap(share), 8, FileOptions.wrap(options)));
 
373
        }
 
374
        catch (cli.System.ArgumentException x)
 
375
        {
 
376
            throw new FileSystemException(path, null, x.getMessage());
 
377
        }
 
378
        catch (cli.System.IO.FileNotFoundException _)
 
379
        {
 
380
            throw new NoSuchFileException(path);
 
381
        }
 
382
        catch (cli.System.IO.DirectoryNotFoundException _)
 
383
        {
 
384
            throw new NoSuchFileException(path);
 
385
        }
 
386
        catch (cli.System.PlatformNotSupportedException x)
 
387
        {
 
388
            throw new UnsupportedOperationException(x.getMessage());
 
389
        }
 
390
        catch (cli.System.IO.IOException x)
 
391
        {
 
392
            if (mode == FileMode.CreateNew && File.Exists(path))
 
393
            {
 
394
                throw new FileAlreadyExistsException(path);
 
395
            }
 
396
            throw new FileSystemException(path, null, x.getMessage());
 
397
        }
 
398
        catch (cli.System.Security.SecurityException _)
 
399
        {
 
400
            throw new AccessDeniedException(path);
 
401
        }
 
402
        catch (cli.System.UnauthorizedAccessException _)
 
403
        {
 
404
            throw new AccessDeniedException(path);
 
405
        }
 
406
    }
 
407
 
 
408
    public DirectoryStream<Path> newDirectoryStream(Path dir, final DirectoryStream.Filter<? super Path> filter) throws IOException
 
409
    {
 
410
        final String ndir = NetPath.from(dir).path;
 
411
        // null check
 
412
        filter.getClass();
 
413
 
 
414
        SecurityManager sm = System.getSecurityManager();
 
415
        if (sm != null)
 
416
        {
 
417
            sm.checkRead(ndir);
 
418
        }
 
419
 
 
420
        try
 
421
        {
 
422
            if (false) throw new cli.System.ArgumentException();
 
423
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
424
            if (false) throw new cli.System.IO.IOException();
 
425
            if (false) throw new cli.System.Security.SecurityException();
 
426
            if (false) throw new cli.System.UnauthorizedAccessException();
 
427
            final String[] files = Directory.GetFileSystemEntries(ndir);
 
428
            return new DirectoryStream<Path>() {
 
429
                private boolean closed;
 
430
                public Iterator<Path> iterator() {
 
431
                    if (closed) {
 
432
                        throw new IllegalStateException();
 
433
                    }
 
434
                    closed = true;
 
435
                    return new Iterator<Path>() {
 
436
                        private int pos;
 
437
                        private Path filtered;
 
438
                        public boolean hasNext() {
 
439
                            if (filtered == null) {
 
440
                                while (pos != files.length) {
 
441
                                    Path p = new NetPath(fs, cli.System.IO.Path.Combine(ndir, files[pos++]));
 
442
                                    try {
 
443
                                        if (filter.accept(p)) {
 
444
                                            filtered = p;
 
445
                                            break;
 
446
                                        }
 
447
                                    } catch (IOException x) {
 
448
                                        throw new DirectoryIteratorException(x);
 
449
                                    }
 
450
                                }
 
451
                            }
 
452
                            return filtered != null;
 
453
                        }
 
454
                        public Path next() {
 
455
                            if (!hasNext()) {
 
456
                                throw new NoSuchElementException();
 
457
                            }
 
458
                            Path p = filtered;
 
459
                            filtered = null;
 
460
                            return p;
 
461
                        }
 
462
                        public void remove() {
 
463
                            throw new UnsupportedOperationException();
 
464
                        }
 
465
                    };
 
466
                }
 
467
                public void close() {
 
468
                    closed = true;
 
469
                }
 
470
            };
 
471
        }
 
472
        catch (cli.System.ArgumentException
 
473
             | cli.System.IO.IOException
 
474
             | cli.System.Security.SecurityException
 
475
             | cli.System.UnauthorizedAccessException x)
 
476
        {
 
477
            if (File.Exists(ndir))
 
478
            {
 
479
                throw new NotDirectoryException(ndir);
 
480
            }
 
481
            throw new IOException(x.getMessage());
 
482
        }
 
483
    }
 
484
 
 
485
    public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
 
486
    {
 
487
        NetPath ndir = NetPath.from(dir);
 
488
        for (FileAttribute<?> attr : attrs)
 
489
        {
 
490
            // null check
 
491
            attr.getClass();
 
492
            throw new NotYetImplementedError();
 
493
        }
 
494
        SecurityManager sm = System.getSecurityManager();
 
495
        if (sm != null)
 
496
        {
 
497
            sm.checkWrite(ndir.path);
 
498
        }
 
499
        try
 
500
        {
 
501
            if (false) throw new cli.System.ArgumentException();
 
502
            if (false) throw new cli.System.IO.IOException();
 
503
            if (false) throw new cli.System.Security.SecurityException();
 
504
            if (false) throw new cli.System.UnauthorizedAccessException();
 
505
            Directory.CreateDirectory(ndir.path);
 
506
        }
 
507
        catch (cli.System.ArgumentException
 
508
             | cli.System.IO.IOException
 
509
             | cli.System.Security.SecurityException
 
510
             | cli.System.UnauthorizedAccessException x)
 
511
        {
 
512
            if (File.Exists(ndir.path))
 
513
            {
 
514
                throw new FileAlreadyExistsException(ndir.path);
 
515
            }
 
516
            throw new IOException(x.getMessage());
 
517
        }
 
518
    }
 
519
 
 
520
    public void copy(Path source, Path target, CopyOption... options) throws IOException
 
521
    {
 
522
        NetPath nsource = NetPath.from(source);
 
523
        NetPath ntarget = NetPath.from(target);
 
524
        boolean overwrite = false;
 
525
        boolean copyAttribs = false;
 
526
        for (CopyOption opt : options)
 
527
        {
 
528
            if (opt == StandardCopyOption.REPLACE_EXISTING)
 
529
            {
 
530
                overwrite = true;
 
531
            }
 
532
            else if (opt == StandardCopyOption.COPY_ATTRIBUTES)
 
533
            {
 
534
                copyAttribs = true;
 
535
            }
 
536
            else
 
537
            {
 
538
                // null check
 
539
                opt.getClass();
 
540
                throw new UnsupportedOperationException("Unsupported copy option");
 
541
            }
 
542
        }
 
543
        SecurityManager sm = System.getSecurityManager();
 
544
        if (sm != null)
 
545
        {
 
546
            sm.checkRead(nsource.path);
 
547
            sm.checkWrite(ntarget.path);
 
548
        }
 
549
        try
 
550
        {
 
551
            if (false) throw new cli.System.ArgumentException();
 
552
            if (false) throw new cli.System.IO.FileNotFoundException();
 
553
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
554
            if (false) throw new cli.System.IO.IOException();
 
555
            if (false) throw new cli.System.Security.SecurityException();
 
556
            if (false) throw new cli.System.UnauthorizedAccessException();
 
557
            if (File.Exists(ntarget.path))
 
558
            {
 
559
                if (!overwrite)
 
560
                {
 
561
                    throw new FileAlreadyExistsException(ntarget.path);
 
562
                }
 
563
                File.Delete(ntarget.path);
 
564
            }
 
565
            if (Directory.Exists(ntarget.path))
 
566
            {
 
567
                if (!overwrite)
 
568
                {
 
569
                    throw new FileAlreadyExistsException(ntarget.path);
 
570
                }
 
571
                try
 
572
                {
 
573
                    if (false) throw new cli.System.IO.IOException();
 
574
                    Directory.Delete(ntarget.path);
 
575
                }
 
576
                catch (cli.System.IO.IOException _)
 
577
                {
 
578
                    // HACK we assume that the IOException is caused by the directory not being empty
 
579
                    throw new DirectoryNotEmptyException(ntarget.path);
 
580
                }
 
581
            }
 
582
            if (Directory.Exists(nsource.path))
 
583
            {
 
584
                Directory.CreateDirectory(ntarget.path);
 
585
            }
 
586
            else
 
587
            {
 
588
                File.Copy(nsource.path, ntarget.path, overwrite);
 
589
            }
 
590
            if (copyAttribs)
 
591
            {
 
592
                if (Directory.Exists(ntarget.path))
 
593
                {
 
594
                    File.SetAttributes(ntarget.path, File.GetAttributes(nsource.path));
 
595
                    Directory.SetCreationTimeUtc(ntarget.path, File.GetCreationTimeUtc(nsource.path));
 
596
                    Directory.SetLastAccessTimeUtc(ntarget.path, File.GetLastAccessTimeUtc(nsource.path));
 
597
                    Directory.SetLastWriteTimeUtc(ntarget.path, File.GetLastWriteTimeUtc(nsource.path));
 
598
                }
 
599
                else
 
600
                {
 
601
                    File.SetAttributes(ntarget.path, File.GetAttributes(nsource.path));
 
602
                    File.SetCreationTimeUtc(ntarget.path, File.GetCreationTimeUtc(nsource.path));
 
603
                    File.SetLastAccessTimeUtc(ntarget.path, File.GetLastAccessTimeUtc(nsource.path));
 
604
                    File.SetLastWriteTimeUtc(ntarget.path, File.GetLastWriteTimeUtc(nsource.path));
 
605
                }
 
606
            }
 
607
        }
 
608
        catch (cli.System.IO.FileNotFoundException x)
 
609
        {
 
610
            throw new NoSuchFileException(x.get_FileName());
 
611
        }
 
612
        catch (cli.System.IO.DirectoryNotFoundException x)
 
613
        {
 
614
            throw new NoSuchFileException(nsource.path, ntarget.path, x.getMessage());
 
615
        }
 
616
        catch (cli.System.IO.IOException | cli.System.ArgumentException x)
 
617
        {
 
618
            throw new FileSystemException(nsource.path, ntarget.path, x.getMessage());
 
619
        }
 
620
        catch (cli.System.Security.SecurityException | cli.System.UnauthorizedAccessException x)
 
621
        {
 
622
            throw new AccessDeniedException(nsource.path, ntarget.path, x.getMessage());
 
623
        }
 
624
    }
 
625
 
 
626
    public void move(Path source, Path target, CopyOption... options) throws IOException
 
627
    {
 
628
        NetPath nsource = NetPath.from(source);
 
629
        NetPath ntarget = NetPath.from(target);
 
630
        boolean overwrite = false;
 
631
        for (CopyOption opt : options)
 
632
        {
 
633
            if (opt == StandardCopyOption.REPLACE_EXISTING)
 
634
            {
 
635
                overwrite = true;
 
636
            }
 
637
            else if (opt == StandardCopyOption.ATOMIC_MOVE)
 
638
            {
 
639
                throw new AtomicMoveNotSupportedException(nsource.path, ntarget.path, "Unsupported copy option");
 
640
            }
 
641
            else
 
642
            {
 
643
                // null check
 
644
                opt.getClass();
 
645
                throw new UnsupportedOperationException("Unsupported copy option");
 
646
            }
 
647
        }
 
648
        SecurityManager sm = System.getSecurityManager();
 
649
        if (sm != null)
 
650
        {
 
651
            sm.checkRead(nsource.path);
 
652
            sm.checkWrite(ntarget.path);
 
653
        }
 
654
        try
 
655
        {
 
656
            if (false) throw new cli.System.ArgumentException();
 
657
            if (false) throw new cli.System.IO.FileNotFoundException();
 
658
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
659
            if (false) throw new cli.System.IO.IOException();
 
660
            if (false) throw new cli.System.Security.SecurityException();
 
661
            if (false) throw new cli.System.UnauthorizedAccessException();
 
662
            if (File.Exists(ntarget.path))
 
663
            {
 
664
                if (!overwrite)
 
665
                {
 
666
                    throw new FileAlreadyExistsException(ntarget.path);
 
667
                }
 
668
                File.Delete(ntarget.path);
 
669
            }
 
670
            if (Directory.Exists(ntarget.path))
 
671
            {
 
672
                if (!overwrite)
 
673
                {
 
674
                    throw new FileAlreadyExistsException(ntarget.path);
 
675
                }
 
676
                try
 
677
                {
 
678
                    if (false) throw new cli.System.IO.IOException();
 
679
                    Directory.Delete(ntarget.path);
 
680
                }
 
681
                catch (cli.System.IO.IOException _)
 
682
                {
 
683
                    // HACK we assume that the IOException is caused by the directory not being empty
 
684
                    throw new DirectoryNotEmptyException(ntarget.path);
 
685
                }
 
686
            }
 
687
            if (Directory.Exists(nsource.path))
 
688
            {
 
689
                Directory.Move(nsource.path, ntarget.path);
 
690
            }
 
691
            else
 
692
            {
 
693
                File.Move(nsource.path, ntarget.path);
 
694
            }
 
695
        }
 
696
        catch (cli.System.IO.FileNotFoundException x)
 
697
        {
 
698
            throw new NoSuchFileException(x.get_FileName());
 
699
        }
 
700
        catch (cli.System.IO.DirectoryNotFoundException x)
 
701
        {
 
702
            throw new NoSuchFileException(nsource.path, ntarget.path, x.getMessage());
 
703
        }
 
704
        catch (cli.System.IO.IOException | cli.System.ArgumentException x)
 
705
        {
 
706
            throw new FileSystemException(nsource.path, ntarget.path, x.getMessage());
 
707
        }
 
708
        catch (cli.System.Security.SecurityException | cli.System.UnauthorizedAccessException x)
 
709
        {
 
710
            throw new AccessDeniedException(nsource.path, ntarget.path, x.getMessage());
 
711
        }
 
712
    }
 
713
 
 
714
    public boolean isSameFile(Path path, Path path2) throws IOException
 
715
    {
 
716
        if (path.equals(path2))
 
717
        {
 
718
            return true;
 
719
        }
 
720
        if (!(path instanceof NetPath && path2 instanceof NetPath))
 
721
        {
 
722
            // null check
 
723
            path2.getClass();
 
724
            return false;
 
725
        }
 
726
        return path.toRealPath().equals(path2.toRealPath());
 
727
    }
 
728
 
 
729
    public boolean isHidden(Path path) throws IOException
 
730
    {
 
731
        String npath = NetPath.from(path).path;
 
732
        SecurityManager sm = System.getSecurityManager();
 
733
        if (sm != null)
 
734
        {
 
735
            sm.checkRead(npath);
 
736
        }
 
737
        try
 
738
        {
 
739
            if (false) throw new cli.System.ArgumentException();
 
740
            if (false) throw new cli.System.IO.FileNotFoundException();
 
741
            if (false) throw new cli.System.IO.IOException();
 
742
            return (File.GetAttributes(npath).Value & (cli.System.IO.FileAttributes.Hidden | cli.System.IO.FileAttributes.Directory)) == cli.System.IO.FileAttributes.Hidden;
 
743
        }
 
744
        catch (cli.System.IO.FileNotFoundException x)
 
745
        {
 
746
            throw new NoSuchFileException(npath);
 
747
        }
 
748
        catch (cli.System.IO.IOException | cli.System.ArgumentException x)
 
749
        {
 
750
            throw new IOException(x.getMessage());
 
751
        }
 
752
    }
 
753
 
 
754
    private static class NetFileStore extends FileStore
 
755
    {
 
756
        private final DriveInfo info;
 
757
        private final String name;
 
758
        private final String type;
 
759
 
 
760
        NetFileStore(DriveInfo info) throws IOException
 
761
        {
 
762
            this.info = info;
 
763
            try
 
764
            {
 
765
                if (false) throw new cli.System.IO.IOException();
 
766
                name = info.get_VolumeLabel();
 
767
                type = info.get_DriveFormat();
 
768
            }
 
769
            catch (cli.System.IO.IOException x)
 
770
            {
 
771
                throw new IOException(x.getMessage());
 
772
            }
 
773
        }
 
774
 
 
775
        public Object getAttribute(String attribute) throws IOException
 
776
        {
 
777
            switch (attribute)
 
778
            {
 
779
                case "totalSpace":
 
780
                    return getTotalSpace();
 
781
                case "unallocatedSpace":
 
782
                    return getUnallocatedSpace();
 
783
                case "usableSpace":
 
784
                    return getUsableSpace();
 
785
                default:
 
786
                    throw new UnsupportedOperationException();
 
787
            }
 
788
        }
 
789
 
 
790
        public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type)
 
791
        {
 
792
            return null;
 
793
        }
 
794
 
 
795
        public long getTotalSpace() throws IOException
 
796
        {
 
797
            try
 
798
            {
 
799
                if (false) throw new cli.System.IO.IOException();
 
800
                return info.get_TotalSize();
 
801
            }
 
802
            catch (cli.System.IO.IOException x)
 
803
            {
 
804
                throw new IOException(x.getMessage());
 
805
            }
 
806
        }
 
807
 
 
808
        public long getUnallocatedSpace() throws IOException
 
809
        {
 
810
            try
 
811
            {
 
812
                if (false) throw new cli.System.IO.IOException();
 
813
                return info.get_TotalFreeSpace();
 
814
            }
 
815
            catch (cli.System.IO.IOException x)
 
816
            {
 
817
                throw new IOException(x.getMessage());
 
818
            }
 
819
        }
 
820
 
 
821
        public long getUsableSpace() throws IOException
 
822
        {
 
823
            try
 
824
            {
 
825
                if (false) throw new cli.System.IO.IOException();
 
826
                return info.get_AvailableFreeSpace();
 
827
            }
 
828
            catch (cli.System.IO.IOException x)
 
829
            {
 
830
                throw new IOException(x.getMessage());
 
831
            }
 
832
        }
 
833
 
 
834
        public boolean isReadOnly()
 
835
        {
 
836
            return false;
 
837
        }
 
838
 
 
839
        public String name()
 
840
        {
 
841
            return name;
 
842
        }
 
843
 
 
844
        public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type)
 
845
        {
 
846
            // null check
 
847
            type.getClass();
 
848
            return type == BasicFileAttributeView.class || type == DosFileAttributeView.class;
 
849
        }
 
850
 
 
851
        public boolean supportsFileAttributeView(String name)
 
852
        {
 
853
            return name.equals("basic") || name.equals("dos");
 
854
        }
 
855
 
 
856
        public String type()
 
857
        {
 
858
            return type;
 
859
        }        
 
860
 
 
861
        public String toString()
 
862
        {
 
863
            return name + " (" + info.get_Name().charAt(0) + ":)";
 
864
        }
 
865
    }
 
866
 
 
867
    public FileStore getFileStore(Path path) throws IOException
 
868
    {
 
869
        NetPath npath = NetPath.from(path.toAbsolutePath());
 
870
        SecurityManager sm = System.getSecurityManager();
 
871
        if (sm != null)
 
872
        {
 
873
            sm.checkRead(npath.path);
 
874
        }
 
875
        return getFileStore(new DriveInfo(npath.path));
 
876
    }
 
877
 
 
878
    public void checkAccess(Path path, AccessMode... modes) throws IOException
 
879
    {
 
880
        String npath = NetPath.from(path).path;
 
881
        SecurityManager sm = System.getSecurityManager();
 
882
        if (sm != null)
 
883
        {
 
884
            if (modes.length == 0)
 
885
            {
 
886
                sm.checkRead(npath);
 
887
            }
 
888
            for (AccessMode m : modes)
 
889
            {
 
890
                switch (m)
 
891
                {
 
892
                    case READ:
 
893
                        sm.checkRead(npath);
 
894
                        break;
 
895
                    case WRITE:
 
896
                        sm.checkWrite(npath);
 
897
                        break;
 
898
                    case EXECUTE:
 
899
                        sm.checkExec(npath);
 
900
                        break;
 
901
                    default:
 
902
                        throw new UnsupportedOperationException();
 
903
                }
 
904
            }
 
905
        }
 
906
        try
 
907
        {
 
908
            if (false) throw new cli.System.ArgumentException();
 
909
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
910
            if (false) throw new cli.System.IO.FileNotFoundException();
 
911
            if (false) throw new cli.System.IO.IOException();
 
912
            if (false) throw new cli.System.NotSupportedException();
 
913
            if (false) throw new cli.System.Security.SecurityException();
 
914
            if (false) throw new cli.System.UnauthorizedAccessException();
 
915
            // note that File.GetAttributes() works for directories as well
 
916
            int attr = File.GetAttributes(npath).Value;
 
917
            for (AccessMode m : modes)
 
918
            {
 
919
                switch (m)
 
920
                {
 
921
                    case READ:
 
922
                    case EXECUTE:
 
923
                        break;
 
924
                    case WRITE:
 
925
                        if ((attr & (cli.System.IO.FileAttributes.ReadOnly | cli.System.IO.FileAttributes.Directory)) == cli.System.IO.FileAttributes.ReadOnly)
 
926
                        {
 
927
                            throw new AccessDeniedException(npath, null, "file has read-only attribute set");
 
928
                        }
 
929
                        if (getFileStore(path).isReadOnly())
 
930
                        {
 
931
                            throw new AccessDeniedException(npath, null, "volume is read-only");
 
932
                        }
 
933
                        break;
 
934
                    default:
 
935
                        throw new UnsupportedOperationException();
 
936
                }
 
937
            }
 
938
        }
 
939
        catch (cli.System.IO.FileNotFoundException | cli.System.IO.DirectoryNotFoundException _)
 
940
        {
 
941
            throw new NoSuchFileException(npath);
 
942
        }
 
943
        catch (cli.System.Security.SecurityException | cli.System.UnauthorizedAccessException x)
 
944
        {
 
945
            throw new AccessDeniedException(npath, null, x.getMessage());
 
946
        }
 
947
        catch (cli.System.ArgumentException | cli.System.IO.IOException | cli.System.NotSupportedException x)
 
948
        {
 
949
            throw new IOException(x.getMessage());
 
950
        }
 
951
    }
 
952
 
 
953
    private static class BasicFileAttributesViewImpl extends AbstractBasicFileAttributeView
 
954
    {
 
955
        protected final String path;
 
956
 
 
957
        BasicFileAttributesViewImpl(String path)
 
958
        {
 
959
            this.path = path;
 
960
        }
 
961
 
 
962
        public BasicFileAttributes readAttributes() throws IOException
 
963
        {
 
964
            return DosFileAttributesViewImpl.readAttributesImpl(path);
 
965
        }
 
966
 
 
967
        public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException
 
968
        {
 
969
            SecurityManager sm = System.getSecurityManager();
 
970
            if (sm != null)
 
971
            {
 
972
                sm.checkWrite(path);
 
973
            }
 
974
            try
 
975
            {
 
976
                if (false) throw new cli.System.ArgumentException();
 
977
                if (false) throw new cli.System.IO.IOException();
 
978
                if (false) throw new cli.System.NotSupportedException();
 
979
                if (false) throw new cli.System.Security.SecurityException();
 
980
                if (false) throw new cli.System.UnauthorizedAccessException();
 
981
                if (File.Exists(path))
 
982
                {
 
983
                    if (lastModifiedTime != null)
 
984
                    {
 
985
                        File.SetLastWriteTimeUtc(path, toDateTime(lastModifiedTime));
 
986
                    }
 
987
                    if (lastAccessTime != null)
 
988
                    {
 
989
                        File.SetLastAccessTimeUtc(path, toDateTime(lastAccessTime));
 
990
                    }
 
991
                    if (createTime != null)
 
992
                    {
 
993
                        File.SetCreationTimeUtc(path, toDateTime(createTime));
 
994
                    }
 
995
                }
 
996
                else if (Directory.Exists(path))
 
997
                {
 
998
                    if (lastModifiedTime != null)
 
999
                    {
 
1000
                        Directory.SetLastWriteTimeUtc(path, toDateTime(lastModifiedTime));
 
1001
                    }
 
1002
                    if (lastAccessTime != null)
 
1003
                    {
 
1004
                        Directory.SetLastAccessTimeUtc(path, toDateTime(lastAccessTime));
 
1005
                    }
 
1006
                    if (createTime != null)
 
1007
                    {
 
1008
                        Directory.SetCreationTimeUtc(path, toDateTime(createTime));
 
1009
                    }
 
1010
                }
 
1011
                else
 
1012
                {
 
1013
                    throw new NoSuchFileException(path);
 
1014
                }
 
1015
            }
 
1016
            catch (cli.System.ArgumentException
 
1017
                 | cli.System.IO.IOException
 
1018
                 | cli.System.NotSupportedException
 
1019
                 | cli.System.Security.SecurityException
 
1020
                 | cli.System.UnauthorizedAccessException x)
 
1021
            {
 
1022
                throw new IOException(x.getMessage());
 
1023
            }
 
1024
        }
 
1025
    }
 
1026
 
 
1027
    private static class DosFileAttributesViewImpl extends BasicFileAttributesViewImpl implements DosFileAttributeView
 
1028
    {
 
1029
        private static final String READONLY_NAME = "readonly";
 
1030
        private static final String ARCHIVE_NAME = "archive";
 
1031
        private static final String SYSTEM_NAME = "system";
 
1032
        private static final String HIDDEN_NAME = "hidden";
 
1033
        private static final String ATTRIBUTES_NAME = "attributes";
 
1034
        private static final Set<String> dosAttributeNames = Util.newSet(basicAttributeNames, READONLY_NAME, ARCHIVE_NAME, SYSTEM_NAME,  HIDDEN_NAME, ATTRIBUTES_NAME);
 
1035
 
 
1036
        DosFileAttributesViewImpl(String path)
 
1037
        {
 
1038
            super(path);
 
1039
        }
 
1040
 
 
1041
        public String name()
 
1042
        {
 
1043
            return "dos";
 
1044
        }
 
1045
 
 
1046
        public DosFileAttributes readAttributes() throws IOException
 
1047
        {
 
1048
            return readAttributesImpl(path);
 
1049
        }
 
1050
 
 
1051
        private static class DosFileAttributesImpl implements DosFileAttributes
 
1052
        {
 
1053
            private final FileInfo info;
 
1054
 
 
1055
            DosFileAttributesImpl(FileInfo info)
 
1056
            {
 
1057
                this.info = info;
 
1058
            }
 
1059
 
 
1060
            int attributes()
 
1061
            {
 
1062
                return info.get_Attributes().Value;
 
1063
            }
 
1064
 
 
1065
            public FileTime creationTime()
 
1066
            {
 
1067
                return toFileTime(info.get_CreationTimeUtc());
 
1068
            }
 
1069
 
 
1070
            public Object fileKey()
 
1071
            {
 
1072
                return null;
 
1073
            }
 
1074
 
 
1075
            public boolean isDirectory()
 
1076
            {
 
1077
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.Directory) != 0;
 
1078
            }
 
1079
 
 
1080
            public boolean isOther()
 
1081
            {
 
1082
                return false;
 
1083
            }
 
1084
 
 
1085
            public boolean isRegularFile()
 
1086
            {
 
1087
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.Directory) == 0;
 
1088
            }
 
1089
 
 
1090
            public boolean isSymbolicLink()
 
1091
            {
 
1092
                return false;
 
1093
            }
 
1094
 
 
1095
            public FileTime lastAccessTime()
 
1096
            {
 
1097
                return toFileTime(info.get_LastAccessTimeUtc());
 
1098
            }
 
1099
 
 
1100
            public FileTime lastModifiedTime()
 
1101
            {
 
1102
                return toFileTime(info.get_LastWriteTimeUtc());
 
1103
            }
 
1104
 
 
1105
            public long size()
 
1106
            {
 
1107
                return info.get_Length();
 
1108
            }
 
1109
 
 
1110
            public boolean isArchive()
 
1111
            {
 
1112
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.Archive) != 0;
 
1113
            }
 
1114
 
 
1115
            public boolean isHidden()
 
1116
            {
 
1117
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.Hidden) != 0;
 
1118
            }
 
1119
 
 
1120
            public boolean isReadOnly()
 
1121
            {
 
1122
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.ReadOnly) != 0;
 
1123
            }
 
1124
 
 
1125
            public boolean isSystem()
 
1126
            {
 
1127
                return (info.get_Attributes().Value & cli.System.IO.FileAttributes.System) != 0;
 
1128
            }
 
1129
        }
 
1130
 
 
1131
        static DosFileAttributesImpl readAttributesImpl(String path) throws IOException
 
1132
        {
 
1133
            SecurityManager sm = System.getSecurityManager();
 
1134
            if (sm != null)
 
1135
            {
 
1136
                sm.checkRead(path);
 
1137
            }
 
1138
            try
 
1139
            {
 
1140
                if (false) throw new cli.System.ArgumentException();
 
1141
                if (false) throw new cli.System.IO.FileNotFoundException();
 
1142
                if (false) throw new cli.System.IO.IOException();
 
1143
                return new DosFileAttributesImpl(new FileInfo(path));
 
1144
            }
 
1145
            catch (cli.System.IO.FileNotFoundException _)
 
1146
            {
 
1147
                throw new NoSuchFileException(path);
 
1148
            }
 
1149
            catch (cli.System.IO.IOException | cli.System.ArgumentException x)
 
1150
            {
 
1151
                throw new IOException(x.getMessage());
 
1152
            }
 
1153
        }
 
1154
 
 
1155
        public void setArchive(boolean value) throws IOException
 
1156
        {
 
1157
            setAttribute(cli.System.IO.FileAttributes.Archive, value);
 
1158
        }
 
1159
 
 
1160
        public void setHidden(boolean value) throws IOException
 
1161
        {
 
1162
            setAttribute(cli.System.IO.FileAttributes.Hidden, value);
 
1163
        }
 
1164
 
 
1165
        public void setReadOnly(boolean value) throws IOException
 
1166
        {
 
1167
            setAttribute(cli.System.IO.FileAttributes.ReadOnly, value);
 
1168
        }
 
1169
 
 
1170
        public void setSystem(boolean value) throws IOException
 
1171
        {
 
1172
            setAttribute(cli.System.IO.FileAttributes.System, value);
 
1173
        }
 
1174
 
 
1175
        private void setAttribute(int attr, boolean value) throws IOException
 
1176
        {
 
1177
            SecurityManager sm = System.getSecurityManager();
 
1178
            if (sm != null)
 
1179
            {
 
1180
                sm.checkWrite(path);
 
1181
            }
 
1182
            try
 
1183
            {
 
1184
                if (false) throw new cli.System.ArgumentException();
 
1185
                if (false) throw new cli.System.IO.IOException();
 
1186
                FileInfo info = new FileInfo(path);
 
1187
                if (value)
 
1188
                {
 
1189
                    info.set_Attributes(cli.System.IO.FileAttributes.wrap(info.get_Attributes().Value | attr));
 
1190
                }
 
1191
                else
 
1192
                {
 
1193
                    info.set_Attributes(cli.System.IO.FileAttributes.wrap(info.get_Attributes().Value & ~attr));
 
1194
                }
 
1195
            }
 
1196
            catch (cli.System.ArgumentException
 
1197
                 | cli.System.IO.IOException x)
 
1198
            {
 
1199
                throw new IOException(x.getMessage());
 
1200
            }
 
1201
        }
 
1202
 
 
1203
        public Map<String,Object> readAttributes(String[] attributes) throws IOException
 
1204
        {
 
1205
            AttributesBuilder builder = AttributesBuilder.create(dosAttributeNames, attributes);
 
1206
            DosFileAttributesImpl attrs = readAttributesImpl(path);
 
1207
            addRequestedBasicAttributes(attrs, builder);
 
1208
            if (builder.match(READONLY_NAME))
 
1209
            {
 
1210
                builder.add(READONLY_NAME, attrs.isReadOnly());
 
1211
            }
 
1212
            if (builder.match(ARCHIVE_NAME))
 
1213
            {
 
1214
                builder.add(ARCHIVE_NAME, attrs.isArchive());
 
1215
            }
 
1216
            if (builder.match(SYSTEM_NAME))
 
1217
            {
 
1218
                builder.add(SYSTEM_NAME, attrs.isSystem());
 
1219
            }
 
1220
            if (builder.match(HIDDEN_NAME))
 
1221
            {
 
1222
                builder.add(HIDDEN_NAME, attrs.isHidden());
 
1223
            }
 
1224
            if (builder.match(ATTRIBUTES_NAME))
 
1225
            {
 
1226
                builder.add(ATTRIBUTES_NAME, attrs.attributes());
 
1227
            }
 
1228
            return builder.unmodifiableMap();
 
1229
        }
 
1230
 
 
1231
        public void setAttribute(String attribute, Object value) throws IOException
 
1232
        {
 
1233
            switch (attribute)
 
1234
            {
 
1235
                case READONLY_NAME:
 
1236
                    setReadOnly((Boolean)value);
 
1237
                    break;
 
1238
                case ARCHIVE_NAME:
 
1239
                    setArchive((Boolean)value);
 
1240
                    break;
 
1241
                case SYSTEM_NAME:
 
1242
                    setSystem((Boolean)value);
 
1243
                    break;
 
1244
                case HIDDEN_NAME:
 
1245
                    setHidden((Boolean)value);
 
1246
                    break;
 
1247
                default:
 
1248
                    super.setAttribute(attribute, value);
 
1249
                    break;
 
1250
            }
 
1251
        }
 
1252
    }
 
1253
 
 
1254
    private static void validateLinkOption(LinkOption... options)
 
1255
    {
 
1256
        for (LinkOption option : options)
 
1257
        {
 
1258
            if (option == LinkOption.NOFOLLOW_LINKS)
 
1259
            {
 
1260
                // ignored
 
1261
            }
 
1262
            else
 
1263
            {
 
1264
                // null check
 
1265
                option.getClass();
 
1266
                throw new UnsupportedOperationException();
 
1267
            }
 
1268
        }
 
1269
    }
 
1270
 
 
1271
    public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
 
1272
    {
 
1273
        String npath = NetPath.from(path).path;
 
1274
        validateLinkOption(options);
 
1275
        if (type == BasicFileAttributeView.class)
 
1276
        {
 
1277
            return (V)new BasicFileAttributesViewImpl(npath);
 
1278
        }
 
1279
        else if (type == DosFileAttributeView.class)
 
1280
        {
 
1281
            return (V)new DosFileAttributesViewImpl(npath);
 
1282
        }
 
1283
        else
 
1284
        {
 
1285
            // null check
 
1286
            type.getClass();
 
1287
            return null;
 
1288
        }
 
1289
    }
 
1290
 
 
1291
    public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
 
1292
    {
 
1293
        String npath = NetPath.from(path).path;
 
1294
        // null check
 
1295
        type.getClass();
 
1296
        validateLinkOption(options);
 
1297
        if (type != BasicFileAttributes.class && type != DosFileAttributes.class)
 
1298
        {
 
1299
            throw new UnsupportedOperationException();
 
1300
        }
 
1301
        SecurityManager sm = System.getSecurityManager();
 
1302
        if (sm != null)
 
1303
        {
 
1304
            sm.checkRead(npath);
 
1305
        }
 
1306
        return (A)DosFileAttributesViewImpl.readAttributesImpl(npath);
 
1307
    }
 
1308
 
 
1309
    DynamicFileAttributeView getFileAttributeView(Path file, String name, LinkOption... options)
 
1310
    {
 
1311
        validateLinkOption(options);
 
1312
        if (name.equals("basic"))
 
1313
        {
 
1314
            return new BasicFileAttributesViewImpl(NetPath.from(file).path);
 
1315
        }
 
1316
        else if (name.equals("dos"))
 
1317
        {
 
1318
            return new DosFileAttributesViewImpl(NetPath.from(file).path);
 
1319
        }
 
1320
        else
 
1321
        {
 
1322
            return null;
 
1323
        }
 
1324
    }
 
1325
 
 
1326
    boolean implDelete(Path file, boolean failIfNotExists) throws IOException
 
1327
    {
 
1328
        String path = NetPath.from(file).path;
 
1329
        SecurityManager sm = System.getSecurityManager();
 
1330
        if (sm != null)
 
1331
        {
 
1332
            sm.checkDelete(path);
 
1333
        }
 
1334
        try
 
1335
        {
 
1336
            if (false) throw new cli.System.ArgumentException();
 
1337
            if (false) throw new cli.System.IO.FileNotFoundException();
 
1338
            if (false) throw new cli.System.IO.DirectoryNotFoundException();
 
1339
            if (false) throw new cli.System.IO.IOException();
 
1340
            if (false) throw new cli.System.Security.SecurityException();
 
1341
            if (false) throw new cli.System.UnauthorizedAccessException();
 
1342
            int attr = cli.System.IO.File.GetAttributes(path).Value;
 
1343
            if ((attr & cli.System.IO.FileAttributes.Directory) != 0)
 
1344
            {
 
1345
                try
 
1346
                {
 
1347
                    if (false) throw new cli.System.IO.IOException();
 
1348
                    cli.System.IO.Directory.Delete(path);
 
1349
                }
 
1350
                catch (cli.System.IO.IOException _)
 
1351
                {
 
1352
                    // HACK we assume that the IOException is caused by the directory not being empty
 
1353
                    throw new DirectoryNotEmptyException(path);
 
1354
                }
 
1355
                return true;
 
1356
            }
 
1357
            else
 
1358
            {
 
1359
                cli.System.IO.File.Delete(path);
 
1360
                return true;
 
1361
            }
 
1362
        }
 
1363
        catch (cli.System.ArgumentException x)
 
1364
        {
 
1365
            throw new FileSystemException(path, null, x.getMessage());
 
1366
        }
 
1367
        catch (cli.System.IO.FileNotFoundException _)
 
1368
        {
 
1369
            if (failIfNotExists)
 
1370
            {
 
1371
                throw new NoSuchFileException(path);
 
1372
            }
 
1373
            else
 
1374
            {
 
1375
                return false;
 
1376
            }
 
1377
        }
 
1378
        catch (cli.System.IO.DirectoryNotFoundException _)
 
1379
        {
 
1380
            if (failIfNotExists)
 
1381
            {
 
1382
                throw new NoSuchFileException(path);
 
1383
            }
 
1384
            else
 
1385
            {
 
1386
                return false;
 
1387
            }
 
1388
        }
 
1389
        catch (cli.System.IO.IOException x)
 
1390
        {
 
1391
            throw new FileSystemException(path, null, x.getMessage());
 
1392
        }
 
1393
        catch (cli.System.Security.SecurityException _)
 
1394
        {
 
1395
            throw new AccessDeniedException(path);
 
1396
        }
 
1397
        catch (cli.System.UnauthorizedAccessException _)
 
1398
        {
 
1399
            throw new AccessDeniedException(path);
 
1400
        }
 
1401
    }
 
1402
 
 
1403
    static FileTime toFileTime(cli.System.DateTime dateTime)
 
1404
    {
 
1405
        return FileTime.from((dateTime.get_Ticks() - 621355968000000000L) / 10, java.util.concurrent.TimeUnit.MICROSECONDS);
 
1406
    }
 
1407
 
 
1408
    static cli.System.DateTime toDateTime(FileTime fileTime)
 
1409
    {
 
1410
        return new cli.System.DateTime(fileTime.to(java.util.concurrent.TimeUnit.MICROSECONDS) * 10 + 621355968000000000L);
 
1411
    }
 
1412
}