Search in sources :

Example 6 with FileExistsException

use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.

the class Directory method create.

/**
 * Create a new file in the directory.
 *
 * @param name The file name.  Must be 8+3 characters.
 * @param blockManager To allocate blocks for the created file entry.
 * @return The new directory entity.
 * @throws FileExistsException If the entry already
 * exists.
 */
Dirent create(String name, BlockManager blockManager) throws FileExistsException {
    // Check to see if it is already there.
    if (entries.get(name) != null)
        throw new FileExistsException("File " + name + " already exists");
    Dirent ent;
    if (Objects.equals(name, ImgFS.DIRECTORY_FILE_NAME)) {
        ent = new HeaderDirent(name, blockManager);
    } else {
        ent = new Dirent(name, blockManager);
    }
    addEntry(ent);
    return ent;
}
Also used : FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 7 with FileExistsException

use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.

the class MapMaker method makeMap.

/**
 * Make a map from the given map data source.
 *
 * @param args User supplied arguments.
 * @param src The data source to load.
 * @param mapNameExt
 * @return The output filename for the map.
 */
private String makeMap(CommandArgs args, LoadableMapDataSource src, String mapNamePrefix) {
    if (src.getBounds().isEmpty())
        return null;
    FileSystemParam params = new FileSystemParam();
    params.setBlockSize(args.getBlockSize());
    params.setMapDescription(args.getDescription());
    log.info("Started making", args.getMapname(), "(" + args.getDescription() + ")");
    try {
        Map map = Map.createMap(mapNamePrefix + args.getMapname(), args.getOutputDir(), params, args.getMapname(), sort);
        setOptions(map, args);
        MapBuilder builder = new MapBuilder();
        builder.config(args.getProperties());
        if (!OverviewBuilder.OVERVIEW_PREFIX.equals(mapNamePrefix)) {
            if (args.getProperties().containsKey("route") || args.getProperties().containsKey("net"))
                builder.setDoRoads(true);
        }
        builder.makeMap(map, src);
        // Collect information on map complete.
        String outName = map.getFilename();
        log.info("finished making map", outName, "closing");
        map.close();
        return outName;
    } catch (FileExistsException e) {
        throw new MapFailedException("File exists already", e);
    } catch (FileNotWritableException e) {
        throw new MapFailedException("Could not create or write to file", e);
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) MapBuilder(uk.me.parabola.mkgmap.build.MapBuilder) Map(uk.me.parabola.imgfmt.app.map.Map) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 8 with FileExistsException

use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.

the class FileCopier method addImg.

private void addImg(FileSystem outfs, FileInfo info) {
    FileCopier fc = new FileCopier(info.getFilename());
    List<SubFileInfo> subFiles = info.subFiles();
    for (SubFileInfo sf : subFiles) {
        try {
            ImgChannel chan = outfs.create(sf.getName());
            Closeable sync = fc.add(sf.getName(), chan);
            ((FileLink) chan).link(sf, sync);
        } catch (FileExistsException e) {
            log.warn("Could not copy " + sf.getName(), e);
        }
    }
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) Closeable(java.io.Closeable) FileLink(uk.me.parabola.imgfmt.sys.FileLink) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 9 with FileExistsException

use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.

the class MdrBuilder method init.

/**
 * Create the mdr file and initialise.
 * It has a name that is based on the overview-mapname option, as does
 * the associated MDX file.
 *
 * @param args The command line arguments.
 */
public void init(CommandArgs args) {
    String name = args.get("overview-mapname", "osmmap");
    String outputDir = args.getOutputDir();
    outputName = Utils.joinPath(outputDir, name + "_mdr.img");
    ImgChannel mdrChan;
    try {
        // Create the .img file system/archive
        FileSystemParam params = new FileSystemParam();
        tmpName = File.createTempFile("mdr", null, new File(outputDir));
        tmpName.deleteOnExit();
        imgfs = ImgFS.createFs(tmpName.getPath(), params);
        // Create the MDR file within the .img
        mdrChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".MDR");
    } catch (IOException e) {
        throw new ExitException("Could not create global index file");
    }
    // Create the sort description
    Sort sort = SrtTextReader.sortForCodepage(args.getCodePage());
    // Set the options that we are using for the mdr.
    MdrConfig config = new MdrConfig();
    config.setHeaderLen(568);
    config.setWritable(true);
    config.setForDevice(false);
    config.setOutputDir(outputDir);
    config.setSort(sort);
    config.setIndexOptions(args);
    // Wrap the MDR channel with the MDRFile object
    mdrFile = new MDRFile(mdrChan, config);
    try {
        ImgChannel srtChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".SRT");
        SRTFile srtFile = new SRTFile(srtChan);
        srtFile.setSort(sort);
        srtFile.write();
    // Do not close srtFile here
    } catch (FileExistsException e) {
        throw new ExitException("Could not create SRT file within index file");
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MdrConfig(uk.me.parabola.imgfmt.app.mdr.MdrConfig) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) IOException(java.io.IOException) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) File(java.io.File) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 10 with FileExistsException

use of uk.me.parabola.imgfmt.FileExistsException in project mkgmap by openstreetmap.

the class ImgFS method createInitFS.

/**
 * Set up and ImgFS that has just been created.
 *
 * @param chan The real underlying file to write to.
 * @param params The file system parameters.
 * @throws FileNotWritableException If the file cannot be written for any
 * reason.
 */
private void createInitFS(FileChannel chan, FileSystemParam params) throws FileNotWritableException {
    readOnly = false;
    this.fsparam = params;
    // The block manager allocates blocks for files.
    headerBlockManager = new BlockManager(params.getBlockSize(), 0);
    headerBlockManager.setMaxBlock(params.getReservedDirectoryBlocks());
    // it already existing, so it is created by hand.
    try {
        directory = new Directory(headerBlockManager);
        Dirent ent = directory.create(DIRECTORY_FILE_NAME, headerBlockManager);
        ent.setSpecial(true);
        ent.setInitialized(true);
        FileNode f = new FileNode(chan, ent, "w");
        directory.setFile(f);
        header = new ImgHeader(f);
        header.createHeader(params);
    } catch (FileExistsException e) {
        throw new FileNotWritableException("Could not create img file directory", e);
    }
    fileBlockManager = new BlockManager(params.getBlockSize(), params.getReservedDirectoryBlocks());
    assert header != null;
}
Also used : FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) 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