Changing the location of temporary files in .Net

Ibex creates temporary files during the PDF creation process. This is done to reduce the amount of memory used when processing massive FO files.

By default the temporary files are created using calls to System.IO.Path.GetTempFileName(), which will place the file in the system temp file location.

It is possible to specify where Ibex should create temporary files. This is done by creating an object which implements the ibex4.ITemporaryFileManager interface. This interface only contains the method getFileName().

Having created an instance of your object, you then pass it to the setTemporaryFileManager() method on the FODocument object use to create the PDF file. Any subsequest requests for a temporary file name are delegated to your object, giving you full control of where the temp file is placed.

Creating a temporary file manager object

An example of an object which implements the ITemporaryFileManager interface shown here:

using System;
using System.IO;

using ibex4.logging;
using ibex4;

internal class TempNameCreator : ibex4.ITemporaryFileManager {

    public string getFileName() {

            string name = null ; 
            try  {
                name = System.IO.Path.GetTempFileName();

                Logger.getLogger().info( "using temp file " + name );
            }
            catch( Exception ex) {
                Logger.getLogger().info( "exception " + ex.Message );
                throw ; 
            }
            return name ; 
    }
}
      

The call to getFileName() should return the full name and path of the temporary file. This must be a location to which the process has write access. Every call to getFileName() must return a unique file name.

Using the temporary file manager object

To use the object create an instance of it and pass it to the setTemporaryFileManager() method of the FODocument object. An example of this is shown here:

using System.IO;
using System;
using ibex4.logging;
using ibex4;

public class runibex {

  public static void Main( string[] args ) {
    
    if(args.Length < 1 ) {
        Logger.getLogger().info( "runibex fo-file pdf-file");
        return;
    }

    Logger.getLogger().setLevel( Level.INFO );

    FODocument doc = new FODocument();

    doc.setTemporaryFileManager( new TempNameCreator() );

    Logger.getLogger().info( doc.Settings.Version + " running" );
    
    Stream xmlStream = null;
    Stream pdfStream = null;
    try {
        xmlStream = new FileStream( args[0], FileMode.Open, FileAccess.Read );
        pdfStream = new FileStream( args[1], FileMode.Create, FileAccess.Write );
        
        Logger.getLogger().info ( args[0] + ")->" + args[1] );
        
        doc.generate( xmlStream, null, pdfStream );
        
        Logger.getLogger().info( "count of pages created = " + doc.getPageCount() );
    }
    catch( Exception ex ) {
        Logger.getLogger().info("caught runtime exception:" + ex.Message );
    }
   }
}
      

Copyright (c) 2002-2016 Visual Programming Limited