# Class FileManager

java.lang.Object
org.jmol.viewer.FileManager

All Implemented Interfaces:
  `BytePoster`

public class FileManager extends Object implements BytePoster

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`CHECK_DIMS`
`static final int`
`FILE_DROPPED`
`static final int`
`IS_APPEND`
`static final String`
`JPEG_CONTINUE_STRING`
`static final int`
`NO_AUTOPLAY`
`static final int`
`NO_SCRIPT`
`static final int`
`PDB_CARTOONS`
`static final String`
`PMESH_BINARY_MAGIC_NUMBER`
`Map<String,Object>`
`pngjCache`
`static final int`
`SCRIPT_ONLY`
`static String`
`SIMULATION_PROTOCOL`
`Map<String,byte[]>`
`spardirCache`
`Viewer`
`vwr`

## Method Summary

Modifier and Type
Method
Description
`int`
`cacheFileByNameAdd(String fileName, boolean isAdd)`
`Object`
`cacheGet(String key, boolean bytesOnly)`
`Map<String,Integer>`
`cacheList()`
`static String`
`determineSurfaceFileType(BufferedReader bufferedReader)`
Try to determine a surface file type based on its header.
`static String`
`fixDOSName(String fileName)`
Switch \ for / only for DOS names such as C:\temp\t.xyz, not names like http://cactus.nci.nih.gov/chemical/structure/CC/C=C\CC
`Object`
`getBufferedInputStreamOrErrorMessageFromName(String name, String fullName, boolean showMsg, boolean checkOnly, byte[] outputBytes, boolean allowReader, boolean allowCached)`
`static BufferedReader`
`getBufferedReaderForResource(Viewer vwr, Class<?> resourceClass, String classPath, String resourceName)`
`Object`
`getBufferedReaderOrErrorMessageFromName(String name, String[] fullPathNameReturn, boolean isBinary, boolean doSpecialLoad)`
`String`
`getCanonicalName(String pathName)`
`String`
`getEmbeddedFileState(String fileName, boolean allowCached, String sptName)`
Get the specified SPT file of a Jmol zip collection or the embedded script for any other file that is embeddable.
`static String`
`getEmbeddedScript(String s)`
Extract a Jmol script embedded using JC.EMBEDDED_SCRIPT_TAG.
`Object`
`getFileAsBytes(String name, OC out)`
`Object`
`getFileAsMap(String name, String type, boolean asBytes)`
create a PNG or ZIP file and return it as a map or, optionally, as a byte[]
`boolean`
`getFileDataAsString(String[] data, int nBytesMax, boolean doSpecialLoad, boolean allowBinary, boolean checkProtected)`
`String[]`
`getFileInfo()`
`String`
`getFileName()`
`String`
`getFilePath(String name, boolean addUrlPrefix, boolean asShortName)`
`static void`
`getFileReferences(String script, Lst<String> fileList, Lst<String> fileListUTF)`
`String`
`getFileType()`
`String`
`getFullPathName(boolean orPrevious)`
`Object`
`getImage(Object nameOrBytes, String echoName, boolean forceSync)`
`JmolDataReader`
`getJmolDataReader()`
`JmolUtil`
`getJzu()`
`static GenericFileInterface`
`getLocalDirectory(Viewer vwr, boolean forDialog)`
`static String`
`getLocalPathForWritingFile(Viewer vwr, String file, boolean forDialog)`
`static String`
`getManifestScriptPath(String manifest)`
check a JmolManifest for a reference to a script file (.spt)
`String`
`getPathForAllFiles()`
`Object`
`getUnzippedReaderOrStreamFromName(String name, Object bytesOrStream, boolean allowZipStream, boolean forceInputStream, boolean isTypeCheckOnly, boolean doSpecialLoad, Map<String,Object> htParams)`
`String[]`
`getZipDirectory(String fileName, boolean addManifest, boolean allowCached)`
`static boolean`
`isEmbeddable(String type)`
Check to see if it is possible that this file has been embedded by Jmol using JC.EMBEDDED_SCRIPT_TAG.
`static boolean`
`isJmolType(String type)`
Check to see if this is a Jmol WRITE file type that might be or have attached a ZIP collection .
`static boolean`
`isScriptType(String fname)`
`boolean`
`isZipStream(Object br)`
`boolean`
`loadImage(Object nameOrBytes, String echoName, boolean forceSync)`
Load an image
`void`
`openFileAsync(String fname, int flags, String type)`
From file dropping.
`String`
`postByteArray(String fileName, byte[] bytes)`
/ BytePoster interface
`void`
`recachePngjBytes(String fileName, byte[] bytes)`
`void`
`setFileInfo(String[] fileInfo)`
Set fullPathName, fileName, and nameAsGiven
`void`
`setFileType(String fileType)`
`static void`
`setLocalPath(Viewer vwr, String path, boolean forDialog)`
called by getImageFileNameFromDialog called by getOpenFileNameFromDialog called by getSaveFileNameFromDialog called by classifyName for any full file load called from the CD command currentLocalPath is set in all cases and is used specifically for dialogs as a first try defaultDirectoryLocal is set only when not from a dialog and is used only in getLocalPathForWritingFile or from an open/save dialog.
`static String`
`setScriptFileReferences(String script, String localPath, String remotePath, String scriptPath)`
`SpartanUtil`
`spartanUtil()`
An isolated class to retrieve Spartan file data from compound documents, zip files, and directories
`static String`
`stripPath(String name)`
`static String`
`stripTypePrefix(String fileName)`
Stip PDB::file://...

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### SIMULATION_PROTOCOL

public static String SIMULATION_PROTOCOL

### vwr

public Viewer vwr

### PMESH_BINARY_MAGIC_NUMBER

public static final String PMESH_BINARY_MAGIC_NUMBER

See Also:
  - Constant Field Values

### JPEG_CONTINUE_STRING

public static final String JPEG_CONTINUE_STRING

See Also:
  - Constant Field Values

### pngjCache

public Map<String,Object> pngjCache

### spardirCache

public Map<String,byte[]> spardirCache

### CHECK_DIMS

public static final int CHECK_DIMS

See Also:
  - Constant Field Values

### SCRIPT_ONLY

public static final int SCRIPT_ONLY

See Also:
  - Constant Field Values

### FILE_DROPPED

public static final int FILE_DROPPED

See Also:
  - Constant Field Values

### NO_AUTOPLAY

public static final int NO_AUTOPLAY

See Also:
  - Constant Field Values

### IS_APPEND

public static final int IS_APPEND

See Also:
  - Constant Field Values

### NO_SCRIPT

public static final int NO_SCRIPT

See Also:
  - Constant Field Values

### PDB_CARTOONS

public static final int PDB_CARTOONS

See Also:
  - Constant Field Values

## Method Details

### spartanUtil

public SpartanUtil spartanUtil()
An isolated class to retrieve Spartan file data from compound documents, zip files, and directories

Returns:
  a SpartanUtil

### getJzu

public JmolUtil getJzu()

### getPathForAllFiles

public String getPathForAllFiles()

### setFileInfo

public void setFileInfo(String[] fileInfo)
Set fullPathName, fileName, and nameAsGiven

Parameters:
  `fileInfo` - if null, replace fullPathName and nameAsGiven with last version of such

### getFileInfo

public String[] getFileInfo()

### getFullPathName

public String getFullPathName(boolean orPrevious)

### getFileType

public String getFileType()

### setFileType

public void setFileType(String fileType)

### getFileName

public String getFileName()

### getBufferedInputStreamOrErrorMessageFromName

public Object getBufferedInputStreamOrErrorMessageFromName(String name, String fullName, boolean showMsg, boolean checkOnly, byte[] outputBytes, boolean allowReader, boolean allowCached)

### getBufferedReaderForResource

public static BufferedReader getBufferedReaderForResource(Viewer vwr, Class<?> resourceClass, String classPath, String resourceName) throws IOException

Throws:
  `IOException`

### getBufferedReaderOrErrorMessageFromName

public Object getBufferedReaderOrErrorMessageFromName(String name, String[] fullPathNameReturn, boolean isBinary, boolean doSpecialLoad)

### getUnzippedReaderOrStreamFromName

public Object getUnzippedReaderOrStreamFromName(String name, Object bytesOrStream, boolean allowZipStream, boolean forceInputStream, boolean isTypeCheckOnly, boolean doSpecialLoad, Map<String,Object> htParams)

Parameters:
  `name` -
  `bytesOrStream` - cached bytes or a BufferedInputStream
  `allowZipStream` - if the file is a zip file, allow a return that is a ZipInputStream
  `forceInputStream` - always return a raw BufferedInputStream, not a BufferedReader, and do not process PNGJ files
  `isTypeCheckOnly` - when possibly reading a spartan file for content (doSpecialLoad == true), just return the compound document's file list
  `doSpecialLoad` - check for a Spartan file
  `htParams` -
Returns:
  String if error or String[] if a type check or BufferedReader or BufferedInputStream

### getZipDirectory

public String[] getZipDirectory(String fileName, boolean addManifest, boolean allowCached)

Parameters:
  `fileName` -
  `addManifest` -
  `allowCached` -
Returns:
  [] if not a zip file;

### getFileAsBytes

public Object getFileAsBytes(String name, OC out)

Parameters:
  `name` -
  `out` -
Returns:
  a byte[] or error string

### getFileAsMap

public Object getFileAsMap(String name, String type, boolean asBytes)
create a PNG or ZIP file and return it as a map or, optionally, as a byte[]

Parameters:
  `name` -
  `type` -
  `asBytes` - true to return byte[] instead of a map
Returns:
  Map or byte[]

### getFileDataAsString

public boolean getFileDataAsString(String[] data, int nBytesMax, boolean doSpecialLoad, boolean allowBinary, boolean checkProtected)

Parameters:
  `data` - [0] initially path name, but returned as full path name; [1]file contents (directory listing for a ZIP/JAR file) or error string
  `nBytesMax` - or -1
  `doSpecialLoad` -
  `allowBinary` -
  `checkProtected` - TODO
Returns:
  true if successful; false on error

### loadImage

public boolean loadImage(Object nameOrBytes, String echoName, boolean forceSync)
Load an image

Parameters:
  `nameOrBytes` -
  `echoName` -
  `forceSync` - TODO
Returns:
  true if asynchronous

### getImage

public Object getImage(Object nameOrBytes, String echoName, boolean forceSync)

### getFilePath

public String getFilePath(String name, boolean addUrlPrefix, boolean asShortName)

### getLocalDirectory

public static GenericFileInterface getLocalDirectory(Viewer vwr, boolean forDialog)

### setLocalPath

public static void setLocalPath(Viewer vwr, String path, boolean forDialog)
called by getImageFileNameFromDialog called by getOpenFileNameFromDialog called by getSaveFileNameFromDialog called by classifyName for any full file load called from the CD command currentLocalPath is set in all cases and is used specifically for dialogs as a first try defaultDirectoryLocal is set only when not from a dialog and is used only in getLocalPathForWritingFile or from an open/save dialog. In this way, saving a file from a dialog doesn't change the "CD" directory. Neither of these is saved in the state, but

Parameters:
  `vwr` -
  `path` -
  `forDialog` -

### getLocalPathForWritingFile

public static String getLocalPathForWritingFile(Viewer vwr, String file, boolean forDialog)

### fixDOSName

public static String fixDOSName(String fileName)
Switch \ for / only for DOS names such as C:\temp\t.xyz, not names like http://cactus.nci.nih.gov/chemical/structure/CC/C=C\CC

Parameters:
  `fileName` -
Returns:
  fixed name

### stripPath

public static String stripPath(String name)

### isScriptType

public static boolean isScriptType(String fname)

### determineSurfaceFileType

public static String determineSurfaceFileType(BufferedReader bufferedReader)
Try to determine a surface file type based on its header. Also identifies Menu files.

Parameters:
  `bufferedReader` -
Returns:
  file type

### getManifestScriptPath

public static String getManifestScriptPath(String manifest)
check a JmolManifest for a reference to a script file (.spt)

Parameters:
  `manifest` -
Returns:
  null, "", or a directory entry in the ZIP file

### getFileReferences

public static void getFileReferences(String script, Lst<String> fileList, Lst<String> fileListUTF)

### setScriptFileReferences

public static String setScriptFileReferences(String script, String localPath, String remotePath, String scriptPath)

### cacheGet

public Object cacheGet(String key, boolean bytesOnly)

### cacheFileByNameAdd

public int cacheFileByNameAdd(String fileName, boolean isAdd)

### cacheList

public Map<String,Integer> cacheList()

### getCanonicalName

public String getCanonicalName(String pathName)

### recachePngjBytes

public void recachePngjBytes(String fileName, byte[] bytes)

### postByteArray

public String postByteArray(String fileName, byte[] bytes)
/ BytePoster interface

Specified by:
  `postByteArray` in interface `BytePoster`
Parameters:
  `fileName` -
  `bytes` -
Returns:
  null or a Java exception message if there is an error; otherwise "OK" and a message

### isJmolType

public static boolean isJmolType(String type)
Check to see if this is a Jmol WRITE file type that might be or have attached a ZIP collection .

Parameters:
  `type` - the
Returns:
  true if PNG, PNGJ, JMOL, ZIP, or ZIPALL

### isEmbeddable

public static boolean isEmbeddable(String type)
Check to see if it is possible that this file has been embedded by Jmol using JC.EMBEDDED_SCRIPT_TAG. This includes all Jmol types, JPEG images, and export types POV, POVRAY, and IDTF

Parameters:
  `type` - raw extension or file name
Returns:
  true if this file might contain an embedded script

### getEmbeddedFileState

public String getEmbeddedFileState(String fileName, boolean allowCached, String sptName)
Get the specified SPT file of a Jmol zip collection or the embedded script for any other file that is embeddable.

Parameters:
  `fileName` -
  `allowCached` -
  `sptName` - state.spt, movie.spt, or null
Returns:
  embedded state.spt, movie.spt, or a script embedded using JC.EMBEDDED_SCRIPT_TAG, or "" if not found.

### stripTypePrefix

public static String stripTypePrefix(String fileName)
Stip PDB::file://... from a file name

Parameters:
  `fileName` -
Returns:
  stripped name

### getEmbeddedScript

public static String getEmbeddedScript(String s)
Extract a Jmol script embedded using JC.EMBEDDED_SCRIPT_TAG.

Parameters:
  `s` -
Returns:
  the embedded script or null

### isZipStream

public boolean isZipStream(Object br)

### openFileAsync

public void openFileAsync(String fname, int flags, String type)
From file dropping.

Parameters:
  `fname` -
  `flags` - 1=pdbCartoons, 2=no scripting, 4=append, 8=no autoplay, 16=file dropped, 32=script only (dropped into console) 64=check dims for resize
  `type` -

### getJmolDataReader

public JmolDataReader getJmolDataReader()