Search in sources :

Example 11 with FileExistsException

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");
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Aggregations

FileExistsException (uk.me.parabola.imgfmt.FileExistsException)11 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)5 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)5 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)4 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)4 ExitException (uk.me.parabola.imgfmt.ExitException)3 Map (uk.me.parabola.imgfmt.app.map.Map)3 Sort (uk.me.parabola.imgfmt.app.srt.Sort)3 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)2 FileLink (uk.me.parabola.imgfmt.sys.FileLink)2 MapBuilder (uk.me.parabola.mkgmap.build.MapBuilder)2 Closeable (java.io.Closeable)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 Area (uk.me.parabola.imgfmt.app.Area)1 MDRFile (uk.me.parabola.imgfmt.app.mdr.MDRFile)1