I'm just getting started with Clojure and would like to call a Java method that takes as arguments an input file to read and an output file to which to write. Both appear to be of type java.io.File. The method I would like to call is "parse" in this class:
http://htmltolatex.sourceforge.net/javadoc/cz/kebrt/html2latex/Parser.html
However, because I will be calling the method repeatedly, I would prefer to use in-memory objects rather than files on disk.
I have successfully loaded an instance of the Parser class with:
(def my_parser (cz.kebrt.html2latex.Parser.))
I believe that I have successfully created an in-memory file-like object from which to read using this command:
(def input-object (java.io.StringBufferInputStream. "this is a test"))
However, what kind of file like object should I pass to capture the output? (For the sake of completeness, I should mention that this output file is first used to construct an instance of ParserHandler, which is then passed to the parser created above. http://htmltolatex.sourceforge.net/javadoc/cz/kebrt/html2latex/ParserHandler.html)
Thank you for any advice.
I'm pretty sure this (badly-designed) API is for an old version of the software which doesn't allow what you want to do. (i.e. you can't create a File whose contents is in-memory. That's not what the class is for.)
The latest version appears to have a constructor to which you can pass either a java.io.File or a String. The latter should be what you're after.
edit: I think it might be nice to clear up some stuff for you, since you seem to be coming from a Python background (given your repeated use of the term "file-like"). java.io.File is a misleading name. Its actually more like a path. For example, if you want to check if a file exists, you'd do (.exists (java.io.File. "my/path")). A File can also be a directory. It's dumb I know, but hey, it's java. (If you want to know more, look here). What this Parser class should really be providing is the ability to pass a java.io.Reader, which is like an abstract view over a sequence of characters. Internally they convert both the String option and the File option to a Reader, so its really bad design that they don't just accept a reader and cut out the middle man.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With