I've tracked this down to being caused by enabling full validation. If
you change it to limited or off, configuring blob attributes should work
as expected. Unfortunately, there isn't really a great alternative. You
could change the java.io.tmpdir property to change the directory, but
you can't change the prefix/suffix, and changing that could potentially
affect other things.
I've added some additional low level details on the cause here:
https://issues.apache.org/jira/browse/DAFFODIL-2837
Fortunately, the fix should be pretty small and straightforward.
On 2023-08-03 11:51 AM, Lara Blatchford wrote:
Good morning –
I’m trying to set a custom directory for blob files corresponding to
xs:anyUri elements to be written to. Despite setting a custom
directory, prefix and suffix via
XMLTextInfosetOutputter.setBlobAttributes(), the files are still written
to /tmp and do not use the prefix and suffix I specified. Additionally,
when I call xMLTextInfosetOutputter.getBlobPaths() after parsing, the
list of files is empty despite files having been written. Example code
shown below. Am I doing something incorrectly? I could not find an
example. I’m using the Java API.
Thanks,
Lara
public void parse ( String schema, String inFile, String outFile, String
uriDirectory ) throws Exception
{
Compiler compiler = Daffodil.compiler( );
ProcessorFactory pf = compiler.compileFile( new File( schema ) );
if ( pf.isError( ) )
{
System.err.println( "Failed to load schema: " + schema + ", " +
asString( pf.getDiagnostics( ) ) );
}
else
{
DataProcessor processor = pf.onPath( “/” );
try
{
processor = processor.withValidationMode( ValidationMode.Full );
}
catch ( InvalidUsageException ex )
{
throw new Exception( “Invalid validation mode: “ +
ex.getMessage( ), ex );
}
try ( FileInputStream fis = new FileInputStream( new File (
inFile ) );
FileOutputStream fos = new FileOutputStream( new File(
outFile ) ) )
{
InputSourceDataInputStream dis = new
InputSourceDataInputStream( fis );
XMLTextInfosetOutputter xto = new XMLTextInfosetOutputter( fos,
false );
// write blobs from anyURI elements to uriDirectory with
extension dab (daffodil blob )
Path uriPath = Paths.get( uriDirectory );
if ( !Files.exists( uriPath ) )
{
throw new IOException( uriDirectory + “ directory does not
exist” );
}
String prefix = “dfdltoxml”;
String suffix = “dab”;
xto.setBlobAttributes( uriPath, prefix, suffix );
ParseResult result = processor.parse( dis, xto );
if ( result.isError( ) )
{
throw new Exception( “Parse error” );
}
// get list of blbos written to uri directory
List<Path> blobPaths = JavaConverters.seqAsJavaList(
xto.getBlobPaths( ) );
System.out.println( “Blob files written:” );
for ( Path p : blobPaths )
{
System.out.println( p.toString( ) );
}
}
}
}