41 |
import gnu.classpath.Configuration; |
import gnu.classpath.Configuration; |
42 |
import gnu.java.nio.FileLockImpl; |
import gnu.java.nio.FileLockImpl; |
43 |
|
|
44 |
|
import java.io.File; |
45 |
import java.io.FileNotFoundException; |
import java.io.FileNotFoundException; |
46 |
import java.io.IOException; |
import java.io.IOException; |
47 |
import java.nio.ByteBuffer; |
import java.nio.ByteBuffer; |
102 |
} |
} |
103 |
|
|
104 |
/* Open a file. MODE is a combination of the above mode flags. */ |
/* Open a file. MODE is a combination of the above mode flags. */ |
105 |
public FileChannelImpl (String path, int mode) throws FileNotFoundException |
public FileChannelImpl (File file, int mode) throws FileNotFoundException |
106 |
{ |
{ |
107 |
|
final String path = file.getPath(); |
108 |
fd = open (path, mode); |
fd = open (path, mode); |
109 |
this.mode = mode; |
this.mode = mode; |
110 |
|
|
111 |
|
// First open the file and then check if it is a a directory |
112 |
|
// to avoid race condition. |
113 |
|
if (file.isDirectory()) |
114 |
|
{ |
115 |
|
try |
116 |
|
{ |
117 |
|
close(); |
118 |
|
} |
119 |
|
catch (IOException e) |
120 |
|
{ |
121 |
|
/* ignore it */ |
122 |
|
} |
123 |
|
|
124 |
|
throw new FileNotFoundException(path + " is a directory"); |
125 |
|
} |
126 |
} |
} |
127 |
|
|
128 |
/* Used by init() (native code) */ |
/* Used by init() (native code) */ |