Aspose.TeX's input interface | Java

Please, refer to Aspose.TeX for Java API reference for formal definitions of I/O implementation.

The concept of the input directory

Since I/O primitives of the TeX language can only deal with file names, Aspose.TeX for Java defines a directory as a mapping between names and bulks of data. The bulks of data are supposed to be files, streams, arrays, or whatever else.The API allows us to specify the input and output working directories separately. It provides the general IInputWorkingDirectory interface, which the user can implement for their own purposes. It also provides its own implementations, which will be discussed below. The interface defines the getFile() method, which returns the data stream and determines the full name of the file, while taking some, hypothetically different, name as the first argument, which, in fact, is the mapping key.

Getting file input from the disk file system

Here’s how we would do it:

1// Create conversion options instance.
2...
3// Specify a file system working directory for the input.
4options.setInputWorkingDirectory(new InputFileSystemDirectory(Utils.getInputDirectory()));

This use case is quite simple, so we won’t dwell on it for a long time.

Getting file input from a ZIP archive

We can also put the input files in a ZIP archive and consider it an input directory. In this case, we should proceed as follows:

 1// Open the stream for the ZIP archive that will serve as the input working directory.
 2final Stream inZipStream = File.Open(Path.Combine(RunExamples.InputDirectory, "zip-in.zip"), FileMode.Open))
 3{
 4    // Create conversion options instance.
 5    ...
 6    // Specify a ZIP archive working directory for the input. You can also specify a path inside the archive.
 7    options.setInputWorkingDirectory(new InputZipDirectory(inZipStream, "in"));
 8} finally {
 9    if (inZipStream != null)
10        inZipStream.close();
11}

First, we create the stream containing the ZIP file. Then, after creating the conversion options, we set the InputWorkingDirectory option to be an instance of the InputZipDirectory class. The second argument of the constructor is the base path inside the archive. If we want the entire archive to be an input directory, we should pass the empty string.

The concept of the input terminal

Now let’s remember that there is also the terminal input. As for this one, Aspose.TeX for Java defines the general IInputTerminal interface as having two methods. One of them returns a BufferedReader instance. Another method returns an InputStream as the underlying stream. Provided implementations of the interface are discussed below.

Getting terminal input from the console

To do this, we need to set the TerminalIn option to be an instance of the InputConsoleTerminal class.

1// Create conversion options instance.
2...
3// Specify the console as the input terminal.
4options.setTerminalIn(new InputConsoleTerminal()); // Default value. Arbitrary assignment.

But, to tell you the truth, this is the default value of the option, so there’s no real need to specify it. Due to this fact, and as long as there are no other implementations, this section serves only demonstration purposes.

Theoretically, if we have an interactive TeX file (or script) with predictable behavior, we may want to implement a version of the input terminal that would contain a complementary script for responding to the TeX engine’s requests. Try your hand when you have time!

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.