javaiso9660

How to generate an ISO with JIIC


I'm trying to generate an ISO file, for burning it on CDs, in JAVA. After a search I have found JIIC (Java Iso Image Creator) which is available on Source Forge or as a Maven dependency.

I have made a simple java class to only generate an ISO but my program does not terminate correctly i.e. it never stops.

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);
    }
}

In my console, I have the following result from the several System.out.println

Start ISO9660 support Create ISO streamHandler iso

The program can't achieve the method "process" from the "CreateISO" class. My ISO is create but it can't be open as an archive and its size is 0 octet.

What is my fault ?

Stacktrace

The stacktrace in the debug panel.

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

Solution

  • After several tests, I have disabled the configuration parameters : - RockRidge - ElTorito

    And I use Joliet, with the following configuration.

    My code is much simpler and working properly now, my iso is create and I can open it with 7-zip for example.

    The code :

    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);
        }
    }