1919import org .apache .logging .log4j .Logger ;
2020import org .jetbrains .annotations .NotNull ;
2121import org .labkey .api .exp .api .DataType ;
22+ import org .labkey .api .settings .OptionalFeatureService ;
23+ import org .labkey .api .util .FileUtil ;
24+ import org .labkey .targetedms .TargetedMSModule ;
2225import org .labkey .targetedms .parser .proto .ChromatogramGroupDataOuterClass ;
2326import org .labkey .targetedms .parser .skyd .CacheFormat ;
2427import org .labkey .targetedms .parser .skyd .CacheFormatVersion ;
4447
4548/**
4649 * Parses the .skyd binary file format, for chromatogram data.
47- *
4850 * Based on ChromatogramCache.cs and ChromHeaderInfo.cs from Skyline
49- *
50- * User: jeckels
51- * Date: Apr 13, 2012
5251 */
5352public class SkylineBinaryParser
5453{
5554 private final File _file ;
55+ private final boolean _deleteFileOnClose ;
5656 private final Logger _log ;
5757 private FileChannel _channel ;
5858 private RandomAccessFile _randomAccessFile ;
@@ -71,10 +71,24 @@ public class SkylineBinaryParser
7171
7272 private CachedFile [] _cacheFiles ;
7373
74- public SkylineBinaryParser (File file , Logger log )
74+ public SkylineBinaryParser (File file , Logger log ) throws IOException
7575 {
76- _file = file ;
7776 _log = log ;
77+
78+ if (OptionalFeatureService .get ().isFeatureEnabled (TargetedMSModule .USE_TEMP_DIR_FOR_SKYD_IMPORT ))
79+ {
80+ _deleteFileOnClose = true ;
81+ _file = FileUtil .createTempFile (file .getName (), ".skyd" );
82+ _file .deleteOnExit ();
83+ _log .info ("Copying SKYD to temp directory for import purposes" );
84+ FileUtil .copyFile (file , _file );
85+ _log .info ("Copying complete" );
86+ }
87+ else
88+ {
89+ _file = file ;
90+ _deleteFileOnClose = false ;
91+ }
7892 }
7993
8094 public ChromGroupHeaderInfo [] getChromatograms ()
@@ -97,6 +111,18 @@ public void close()
97111 // using a FileChannel there is a known Java issue on Windows that prevents the mapped file from being deleted,
98112 // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4715154 and http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4469299
99113 System .gc ();
114+
115+ if (_deleteFileOnClose && _file != null )
116+ {
117+ if (!_file .delete ())
118+ {
119+ _log .warn ("Failed to delete temp copy of SKYD file: " + _file .getAbsolutePath ());
120+ }
121+ else
122+ {
123+ _log .info ("Deleted temp copy of SKYD file" );
124+ }
125+ }
100126 }
101127
102128 public void parse () throws IOException
0 commit comments