-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstreamingReader.cfc
38 lines (34 loc) · 1.73 KB
/
streamingReader.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
component extends="base"{
boolean function isStreamingReaderFormat( required workbook ){
return arguments.workbook.getClass().getCanonicalName() == "com.github.pjfanning.xlsx.impl.StreamingWorkbook";
}
query function readFileIntoQuery( required string path, required struct builderOptions, required struct sheetToQueryArgs ){
lock name="#arguments.path#" timeout=5 {
try{
var file = CreateObject( "java", "java.io.FileInputStream" ).init( arguments.path );
arguments.sheetToQueryArgs.workbook = getBuilder( arguments.builderOptions ).open( file );
return getSheetHelper().sheetToQuery( argumentCollection=arguments.sheetToQueryArgs );
}
catch( com.github.pjfanning.xlsx.exceptions.ReadException exception ){
getExceptionHelper().throwInvalidFileForReadLargeFileException();
}
finally{
getFileHelper().closeLocalFileOrStream( local, "file" );
getFileHelper().closeLocalFileOrStream( local, "workbook" );
}
}
}
// NB: called from tests
any function getBuilder( required struct options ){
var passwordProtected = ( arguments.options.KeyExists( "password") && arguments.options.password.Trim().Len() );
var builder = library().createJavaObject( "com.github.pjfanning.xlsx.StreamingReader" ).builder()
.setFullFormatRichText( JavaCast( "boolean", true ) ); //some sheet methods e.g. getLastRowNum() may error if not set to true!
if( passwordProtected )
builder.password( JavaCast( "string", arguments.options.password ) );
if( arguments.options.KeyExists( "bufferSize" ) )
builder.bufferSize( JavaCast( "int", arguments.options.bufferSize ) );
if( arguments.options.KeyExists( "rowCacheSize" ) )
builder.rowCacheSize( JavaCast( "int", arguments.options.rowCacheSize ) );
return builder;
}
}