In short, I have a package that can load a proprietary device file-format. The underlying reading code is written in Java, packed into .jar
, and in a Mathematica package, I can use some simple JLink
wrapper functions to access the functionality.
Now, I would like to attach my code to Mathematica's Import
, which is usually also trivial by employing ImportExport`RegisterImport
. However, to make the importer always available, the RegisterImport
code is should be placed in
$UserBaseDirectory/SystemFiles/Formats/MyFormat/Import.m
For simplicity, assume the following fake package structure
MyFormat/
├── Java
│ └── reader.jar
├── Kernel
│ └── init.m
├── Import.m
├── PacletInfo.m
└── ReadingFunctions.m
In ReadingFunctions.m
, I'm accessing the Java methods from the jar
and provide high-level Mathematica functions for the binary file format. In Import.m
I can use these functions and register a custom importer.
My questions are simple:
- How can I set-up the
PacletInfo.m
so that theImport.m
goes into theFormats
directory and automatically loads the rest of the package when I try to import files? - Or should I use
Loading -> "Startup"
in thePacletInfo.m
to make it available on a kernel start? But then, some unnecessary is always evaluated (e.g. loading of thejar
) that I only need if I indeed use the importer in a session.
Are there other/better ways I haven't considered? I could start testing around, but my hope is that someone can give some hints.
Bonus: Do we have a better alternative to this here for adding a file-extension so that it is automatically recognized by Import
?
FileFormat
. Has anyone investigated if overloadingFileFormat
will affect howImport
decides about the format? $\endgroup$