如何使用 JIIC 生成 ISO

How to generate an ISO with JIIC

我正在尝试生成一个 ISO 文件,以便在 JAVA 中将其刻录到 CD 上。经过搜索,我找到了可用的 JIIC(Java Iso Image Creator)on Source Forge or as a Maven dependency

我做了一个简单的 java class 来只生成一个 ISO,但我的程序没有正确终止,即它永远不会停止。

public class ISOtest {

    private static boolean enableJoliet    = true;
    private static boolean enableRockRidge = true;
    private static boolean enableElTorito  = true;

    private static void handleOption(String option) {
      if (option.equals("disable-joliet")) {
          enableJoliet = false;
      } else
      if (option.equals("disable-rockridge")) {
          enableRockRidge = false;
      } else
      if (option.equals("disable-eltorito")) {
          enableElTorito = false;
      }
    }

    public static void main(String[] args) throws Exception {

        System.out.println("Start");

        // Output file
        File outfile = new File(args.length>0 ? args[0] : "ISOTest3.iso");

        // Directory hierarchy, starting from the root
        ISO9660RootDirectory.MOVED_DIRECTORIES_STORE_NAME = "rr_moved";
        ISO9660RootDirectory root = new ISO9660RootDirectory();

        if (args.length > 1) {

            System.out.println("    If");

            // Record specified files and directories

            for (int i=1; i<args.length; i++) {
                if (args[i].startsWith("--")) {
                    handleOption(args[i].substring(2, args[i].length()));
                } else {
                    // Add file or directory contents recursively
                    File file = new File(args[i]);
                    if (file.exists()) {
                        if (file.isDirectory()) {
                            root.addContentsRecursively(file);
                        } else {
                            root.addFile(file);
                        }
                    }
                }
            }
        } else {
            // Record test cases
            // Additional test cases
            // (file without extension, tar.gz, deeply nested directory;
            // sort order tests, renaming tests: filename + extension,
            // directory with many files: sector end test)
            root.addRecursively(new File("test"));

            ISO9660File file1 = new ISO9660File("test/tux.gif", 1);
            root.addFile(file1);
            ISO9660File file10 = new ISO9660File("test/tux.gif", 10);
            root.addFile(file10);
            ISO9660File file12 = new ISO9660File("test/tux.gif", 12);
            root.addFile(file12);
        }


        // ISO9660 support
        System.out.println("ISO9660 support");
        ISO9660Config iso9660Config = new ISO9660Config();
        iso9660Config.allowASCII(false);
        iso9660Config.setInterchangeLevel(1);
        iso9660Config.restrictDirDepthTo8(true);
        iso9660Config.setPublisher("Jens Hatlak");
        iso9660Config.setVolumeID("ISO Test");
        iso9660Config.setDataPreparer("Jens Hatlak");

        iso9660Config.setCopyrightFile(new File("Copyright.txt"));
        iso9660Config.forceDotDelimiter(true);

        RockRidgeConfig rrConfig = null;
        if (enableRockRidge) {
            // Rock Ridge support
            rrConfig = new RockRidgeConfig();
            rrConfig.setMkisofsCompatibility(false);
            rrConfig.hideMovedDirectoriesStore(true);
            rrConfig.forcePortableFilenameCharacterSet(true);
        }

        JolietConfig jolietConfig = null;
        if (enableJoliet) {
            // Joliet support
            jolietConfig = new JolietConfig();
            jolietConfig.setPublisher("Test 1");
            jolietConfig.setVolumeID("Joliet Test");
            jolietConfig.setDataPreparer("Jens Hatlak");
            jolietConfig.setCopyrightFile(new File("Copyright.txt"));
            jolietConfig.forceDotDelimiter(true);
        }

        ElToritoConfig elToritoConfig = null;
        if(enableElTorito) {

            elToritoConfig = new ElToritoConfig(new File("tomsrtbt-2.0.103.ElTorito.288.img"),
                                                         ElToritoConfig.BOOT_MEDIA_TYPE_2_88MEG_DISKETTE,
                                                         ElToritoConfig.PLATFORM_ID_X86, "isoTest", 4,
                                                         ElToritoConfig.LOAD_SEGMENT_7C0);
        }

        // Create ISO
        System.out.println("Create ISO");
        ISOImageFileHandler streamHandler = new ISOImageFileHandler(outfile);
        System.out.println("streamHandler");
        CreateISO iso = new CreateISO(streamHandler, root);
        System.out.println("iso");
        iso.process(iso9660Config, rrConfig, jolietConfig, elToritoConfig);
        System.out.println("process");
        System.out.println("Done. File is: " + outfile);
    }
}

在我的控制台中,我从几个 System.out.println

中得到以下结果

Start ISO9660 support Create ISO streamHandler iso

程序无法从 "CreateISO" class 实现方法 "process"。 我的 ISO 已创建,但无法作为存档打开,并且其大小为 0 个八位字节。

我有什么错?

堆栈跟踪

调试面板中的堆栈跟踪。

ISO9660Handler(StandardHandler).<init>StreamHandler,ISO9660Directory,StandardCon‌​fig) line:35
ISO9660Handler.<init>(StreamHandler, ISO9660RootDirectory, ISO9660Config, RockRidgeConfig) line: 48
CreateISO.process(ISO9660Config, RockRidgeConfig, JolietConfig, ElToritoConfig) line: 57
ISOtest.main(String[]) line: 150

经过多次测试,我已经禁用了配置参数: - 岩岭 - 埃尔托里托

我使用 Joliet,配置如下。

我的代码现在更简单并且可以正常工作,我的 iso 已经创建,我可以用 7-zip 打开它。

代码:

public class ISOtest {

    public static void main(String[] args) throws Exception {

        System.out.println("Start");

        // Output file
        File outfile = new File(args.length>0 ? args[0] : "ISOTest6.iso");

        // Directory hierarchy, starting from the root
        ISO9660RootDirectory.MOVED_DIRECTORIES_STORE_NAME = "rr_moved";
        ISO9660RootDirectory root = new ISO9660RootDirectory();

        // Files with different versions
        // (to appear in descending order, pointing to same LSN)
        ISO9660File file1 = new ISO9660File("test/tux.gif");
        root.addFile(file1);
        ISO9660File file2 = new ISO9660File("test/150114 Outils.xlsx");
        root.addFile(file2);
        ISO9660File file3 = new ISO9660File("test/DMD.xlsx");
        root.addFile(file3);

        // ISO9660 support
        System.out.println("ISO9660 support");
        ISO9660Config iso9660Config = new ISO9660Config();
        iso9660Config.allowASCII(false);
        iso9660Config.setInterchangeLevel(1);
        iso9660Config.restrictDirDepthTo8(true);
        iso9660Config.setPublisher("Name Nickname");
        iso9660Config.setVolumeID("ISO Test Jiic");
        iso9660Config.setDataPreparer("Name Nickname");

        //iso9660Config.setCopyrightFile(new File("Copyright.txt"));
        iso9660Config.forceDotDelimiter(true);

        RockRidgeConfig rrConfig = null;
        ElToritoConfig elToritoConfig = null;

        JolietConfig jolietConfig = null;

        // Joliet support
        System.out.println("Joliet support");
        jolietConfig = new JolietConfig();
        jolietConfig.setPublisher("Test 2");
        jolietConfig.setVolumeID("Joliet Test");
        jolietConfig.setDataPreparer("Jens Hatlak");
        //jolietConfig.setCopyrightFile(new File("Copyright.txt"));
        jolietConfig.forceDotDelimiter(true);


        System.out.println("Create ISO");
        ISOImageFileHandler streamHandler = new ISOImageFileHandler(outfile);
        System.out.println("streamHandler");
        CreateISO iso = new CreateISO(streamHandler, root);
        System.out.println("iso");
        iso.process(iso9660Config, rrConfig, jolietConfig, elToritoConfig);
        System.out.println("process");
        System.out.println("Done. File is: " + outfile);
    }
}