use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.
the class ImgFS method open.
/**
* Open a file. The returned file object can be used to read and write the
* underlying file.
*
* @param name The file name to open.
* @param mode Either "r" for read access, "w" for write access or "rw"
* for both read and write.
* @return A file descriptor.
* @throws FileNotFoundException When the file does not exist.
*/
public ImgChannel open(String name, String mode) throws FileNotFoundException {
if (name == null || mode == null)
throw new IllegalArgumentException("null argument");
if (mode.indexOf('r') >= 0) {
Dirent ent = internalLookup(name);
FileNode fn = new FileNode(file, ent, "r");
if (xorByte != 0)
fn.setXorByte(xorByte);
return fn;
} else if (mode.indexOf('w') >= 0) {
Dirent ent;
try {
ent = internalLookup(name);
} catch (FileNotFoundException e) {
try {
ent = directory.create(name, fileBlockManager);
} catch (FileExistsException e1) {
// This shouldn't happen as we have just checked.
throw new FileNotFoundException("Attempt to duplicate a file name");
}
}
FileNode node = new FileNode(file, ent, "w");
openNodes.add(node);
return node;
} else {
throw new IllegalArgumentException("Invalid mode given");
}
}
Aggregations