Blame src/libbluray/bdj/java/org/videolan/BDJUtil.java

Packit 5e46da
/*
Packit 5e46da
 * This file is part of libbluray
Packit 5e46da
 * Copyright (C) 2010  William Hahne
Packit 5e46da
 *
Packit 5e46da
 * This library is free software; you can redistribute it and/or
Packit 5e46da
 * modify it under the terms of the GNU Lesser General Public
Packit 5e46da
 * License as published by the Free Software Foundation; either
Packit 5e46da
 * version 2.1 of the License, or (at your option) any later version.
Packit 5e46da
 *
Packit 5e46da
 * This library is distributed in the hope that it will be useful,
Packit 5e46da
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5e46da
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 5e46da
 * Lesser General Public License for more details.
Packit 5e46da
 *
Packit 5e46da
 * You should have received a copy of the GNU Lesser General Public
Packit 5e46da
 * License along with this library. If not, see
Packit 5e46da
 * <http://www.gnu.org/licenses/>.
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
package org.videolan;
Packit 5e46da
Packit 5e46da
import java.text.DecimalFormat;
Packit 5e46da
Packit 5e46da
public class BDJUtil {
Packit 5e46da
    /**
Packit 5e46da
     * Make a five digit zero padded string based on an integer
Packit 5e46da
     * Ex. integer 1 -> string "00001"
Packit 5e46da
     *
Packit 5e46da
     * @param id
Packit 5e46da
     * @return
Packit 5e46da
     */
Packit 5e46da
    public static String makeFiveDigitStr(int id) {
Packit 5e46da
        if (id < 0 || id > 99999) {
Packit 5e46da
            System.err.println("Invalid ID: " + id);
Packit 5e46da
            throw new IllegalArgumentException("Invalid ID " + id);
Packit 5e46da
        }
Packit 5e46da
        String s = "" + id;
Packit 5e46da
        while (s.length() < 5) {
Packit 5e46da
            s = "0" + s;
Packit 5e46da
        }
Packit 5e46da
        return s;
Packit 5e46da
        /*
Packit 5e46da
        DecimalFormat fmt = new DecimalFormat();
Packit 5e46da
        fmt.setMaximumIntegerDigits(5);
Packit 5e46da
        fmt.setMinimumIntegerDigits(5);
Packit 5e46da
        fmt.setGroupingUsed(false);
Packit 5e46da
Packit 5e46da
        return fmt.format(id);
Packit 5e46da
        */
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    /**
Packit 5e46da
     * Make a path based on the disc root to an absolute path based on the filesystem of the computer
Packit 5e46da
     * Ex. /BDMV/JAR/00000.jar -> /bluray/disc/mount/point/BDMV/JAR/00000.jar
Packit 5e46da
     * @param path
Packit 5e46da
     * @return
Packit 5e46da
     */
Packit 5e46da
    public static String discRootToFilesystem(String path) {
Packit 5e46da
        String vfsRoot = System.getProperty("bluray.vfs.root");
Packit 5e46da
        if (vfsRoot == null) {
Packit 5e46da
            System.err.println("discRootToFilesystem(): disc root not set !");
Packit 5e46da
            return path;
Packit 5e46da
        }
Packit 5e46da
        return vfsRoot + path;
Packit 5e46da
    }
Packit 5e46da
}