如何使用 JIIC 生成 ISO
Posted
技术标签:
【中文标题】如何使用 JIIC 生成 ISO【英文标题】:How to generate an ISO with JIIC 【发布时间】:2015-04-20 14:26:18 【问题描述】:我正在尝试生成一个 ISO 文件,以便用 JAVA 将其刻录到 CD 上。经过搜索,我找到了 JIIC(Java Iso Image Creator),可以使用 on Source Forge 或 as a Maven dependency。
我制作了一个简单的 java 类,只生成一个 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”类中的“process”方法。 我的 ISO 已创建,但无法作为存档打开,其大小为 0 个八位字节。
我的错是什么?
堆栈跟踪
调试面板中的堆栈跟踪。
ISO9660Handler(StandardHandler).<init>StreamHandler,ISO9660Directory,StandardConfig) line:35
ISO9660Handler.<init>(StreamHandler, ISO9660RootDirectory, ISO9660Config, RockRidgeConfig) line: 48
CreateISO.process(ISO9660Config, RockRidgeConfig, JolietConfig, ElToritoConfig) line: 57
ISOtest.main(String[]) line: 150
【问题讨论】:
你有堆栈跟踪来显示任何错误吗? 【参考方案1】:经过几次测试,我禁用了配置参数: - 岩岭 - 埃尔托里托
我使用 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);
【讨论】:
该程序正确地创建了一个 ISO,但在程序仍在运行之前,这个 ISO 不可用。也许我没有正确关闭流或其他东西,但我找不到哪个。以上是关于如何使用 JIIC 生成 ISO的主要内容,如果未能解决你的问题,请参考以下文章
如何使用正确的字符编码在 jQueryMobile 1.3.1 中通过 AJAX 加载 ISO-8859-1 内容?
如何在 Swift 中解析/创建格式为小数秒 UTC 时区(ISO 8601、RFC 3339)的日期时间戳?