Class FileAPI
- All Implemented Interfaces:
com.jedox.etl.core.scriptapi.IPropertiesAware
,com.jedox.etl.core.scriptapi.IScriptAPI
FILE
to work with files and folders in file-based connections of Integrator projects.
Supported location types for file-based locations by operation:
Operation/Location types FileSystem
JedoxFiles
FTP
SFTP
WebDav
AzureBlob
OneDrive
WebHDFS
HTTP
getFilename(String)
✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ getFileInfo(String)
✓ ✓ ✓1 ✓ delete(String)
✓ ✓ ✓ ✓ ✓ n/a2 rename(String, String)
✓ ✓3 ✓ ✓ ✓ n/a2 mkdirs(String)
✓ ✓ n/a2 readBinary(String)
✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ writeBinary(String, InputStream)
✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ n/a2 unzip(String, String)
unzip(String, String, String)
✓ n/a2 zip(String, List)
zip(String, List, String)
✓ ✓4 ✓4 ✓4 n/a2
FileInfo.getSize()
returns 0
)JedoxFiles
rename(String, String)
can only rename a file or directory, moving a file or directory (source (connName
) and destination (newConnName
) have different parent directories) or changing the file extension is not supportedFileSystem
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Deletes the file or directory referenced by a file-based connection in its location.getFileInfo
(String connName) Retrieves information of the file or directory referenced by a file-based connection.getFilename
(String connName) Returns the filename as specified in the connection definition.boolean
Creates the directory referenced by a file-based connection, including any necessary but nonexistent parent directories.readBinary
(String connName) Reads the binary data contained in a file referenced by a file-based connection via anInputStream
.boolean
Renames the file or directory referenced by one file-based connection in its location to the name of a second file-based connection.Unzips all files and directories from a zip archive referenced by the first file-based connection to a target directory referenced by a second file-based connection.Unzips all files and directories from a zip archive referenced by the first file-based connection to a target directory referenced by a second file-based connection.void
writeBinary
(String connName, InputStream is) Writes binary data from anInputStream
to a file referenced by a file-based connection.void
Deprecated.void
Creates a zip archive, referenced by the first file-based connection, from a list of file and directories referenced by subsequent file-based connections.void
Creates a zip archive, referenced by the first file-based connection, from a list of file and directories referenced by subsequent file-based connections.Methods inherited from class com.jedox.etl.components.scriptapi.BaseAPI
clearProperties, getComponentName, getConfigSetting, getConfigSetting, getGlobalConnections, getLocalFilesDir, getProjectName, getProperty, setProperty
Methods inherited from class com.jedox.etl.core.scriptapi.ScriptAPI
getDefaultImports, getExtensionPoint, getParameters, setAPIDescriptor
-
Constructor Details
-
FileAPI
public FileAPI()
-
-
Method Details
-
getFilename
Returns the filename as specified in the connection definition.- Parameters:
connName
- name of a file-based connection in the Integrator project- Returns:
- name of the file or directory
- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided or the connection is not file-based
-
getFileInfo
public FileInfo getFileInfo(String connName) throws com.jedox.etl.core.component.ETLRuntimeException Retrieves information of the file or directory referenced by a file-based connection.- Parameters:
connName
- name of a file-based connection in the Integrator project- Returns:
FileInfo
handle to query the information- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based or if access to the file or directory is not permitted
-
delete
Deletes the file or directory referenced by a file-based connection in its location. The connection in the Integrator project remains unchanged. For instance a connection might reference an existing zip archive. You can delete the referenced file and then create a new file withzip(String, String...)
using the same connection. A referenced directory must be empty in order to be deleted.- Parameters:
connName
- name of a file-based connection in the Integrator project- Returns:
true
if the file or directory is successfully deleted,false
otherwise- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based or if access to the file or directory is not permitted
-
rename
public boolean rename(String connName, String newConnName) throws com.jedox.etl.core.component.ETLRuntimeException Renames the file or directory referenced by one file-based connection in its location to the name of a second file-based connection. Both connections in the Integrator project remains unchanged.getFilename(String)
for both connections will return the old and the new name of the file or directory and the renamed file or directory is not referenced by the first connection. The renamed file or directory is referenced by the second connection.- Parameters:
connName
- name of a file-based connection referencing the file or directory to renamenewConnName
- name of a file-based connection referencing the file or directory with its new name- Returns:
true
if renaming the file or directory succeeded,false
otherwise- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based or if access to the file or directory is not permitted
-
mkdirs
Creates the directory referenced by a file-based connection, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.- Parameters:
connName
- name of a file-based connection referencing a directory- Returns:
true
if the directory was created, along with all necessary parent directories,false
otherwise- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based or if access to the directory is not permitted
-
readBinary
public InputStream readBinary(String connName) throws com.jedox.etl.core.component.ETLRuntimeException Reads the binary data contained in a file referenced by a file-based connection via anInputStream
.- Parameters:
connName
- name of a file-based connection in the Integrator project- Returns:
InputStream
to read the content of the referenced file- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based, if the file doesn't exist or if an error occurred while reading its content
-
writeBinary
public void writeBinary(String connName, InputStream is) throws com.jedox.etl.core.component.ETLRuntimeException Writes binary data from anInputStream
to a file referenced by a file-based connection. If the file exists, its content is replaced. If the file doesn't exist, it is created.- Parameters:
connName
- name of a file-based connection in the Integrator projectis
-InputStream
to provide the content to write to the referenced file- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connection is not file-based or if an error occurred while writing the content to the (new) file
-
unzip
public List<String> unzip(String zipConnName, String targetConnName) throws com.jedox.etl.core.component.ETLRuntimeException Unzips all files and directories from a zip archive referenced by the first file-based connection to a target directory referenced by a second file-based connection.- Parameters:
zipConnName
- name of a file-based connection referencing the zip archivetargetConnName
- name of a file-based connection referencing the target directory- Returns:
List
containing the names of all unzipped files and directories asString
s- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connections are not file-based, the first connection doesn't reference a file, the zip archive doesn't exist, the second connection doesn't reference a directory, the target directory doesn't exist or if an error occurred while unzipping the zip archive
-
unzip
public List<String> unzip(String zipConnName, String targetConnName, String zipPwVar) throws com.jedox.etl.core.component.ETLRuntimeException Unzips all files and directories from a zip archive referenced by the first file-based connection to a target directory referenced by a second file-based connection.- Parameters:
zipConnName
- name of a file-based connection referencing the zip archivetargetConnName
- name of a file-based connection referencing the target directoryzipPwVar
- name of a variable (marked as a password) which contains the password for the zip file.- Returns:
List
containing the names of all unzipped files and directories asString
s- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connections are not file-based, the first connection doesn't reference a file, the zip archive doesn't exist, the second connection doesn't reference a directory, the target directory doesn't exist or if an error occurred while unzipping the zip archive
-
zip
public void zip(String zipTargetConnName, List<String> sourceConnNames, String zipPwVar) throws com.jedox.etl.core.component.ETLRuntimeException Creates a zip archive, referenced by the first file-based connection, from a list of file and directories referenced by subsequent file-based connections. If a file-based connection references a directory, all files and directories below this directory are added to the zip archive.If the zip archive already exists, the files and directories are added to the existing archive. If a file referenced by a file-based connection or contained in a directory referenced by a directory connection already exists in the archive, it gets replaced. Use
delete(String)
to delete an existing zip archive if necessary before creating a new one withzip(String, List, String)
.- Parameters:
zipTargetConnName
- name of a file-based connection referencing the target zip archivezipPwVar
- name of a variable (marked as a password) which contains the password for the zip to be created.sourceConnNames
- names of file-based connections referencing files and directories to add to the zip archive (currently only directory locations of typeFileSystem
are supported)- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connections are not file-based, the first connection doesn't reference a file, the zip archive doesn't exist, any of the subsequent connections doesn't exist or if an error occured creating the target zip archive
-
zip
public void zip(String zipTargetConnName, List<String> sourceConnNames) throws com.jedox.etl.core.component.ETLRuntimeException Creates a zip archive, referenced by the first file-based connection, from a list of file and directories referenced by subsequent file-based connections. If a file-based connection references a directory, all files and directories below this directory are added to the zip archive.If the zip archive already exists, the files and directories are added to the existing archive. If a file referenced by a file-based connection or contained in a directory referenced by a directory connection already exists in the archive, it gets replaced. Use
delete(String)
to delete an existing zip archive if necessary before creating a new one withzip(String, List)
.- Parameters:
zipTargetConnName
- name of a file-based connection referencing the target zip archivesourceConnNames
- names of file-based connections referencing files and directories to add to the zip archive (currently only directory locations of typeFileSystem
are supported)- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connections are not file-based, the first connection doesn't reference a file, the zip archive doesn't exist, any of the subsequent connections doesn't exist or if an error occurred creating the target zip archive
-
zip
@Deprecated(since="23.2") public void zip(String zipTargetConnName, String... sourceConnNames) throws com.jedox.etl.core.component.ETLRuntimeException Deprecated.Usezip(String, List)
orzip(String, List, String)
instead.Creates a zip archive, referenced by the first file-based connection, from a list of file and directories referenced by subsequent file-based connections. If a file-based connection references a directory, all files and directories below this directory are added to the zip archive.- Parameters:
zipTargetConnName
- name of a file-based connection referencing the target zip archivesourceConnNames
- names of file-based connections referencing files and directories to add to the zip archive (currently only directory locations of typeFileSystem
are supported)- Throws:
com.jedox.etl.core.component.ETLRuntimeException
- if no connection name is provided, the connections are not file-based, the first connection doesn't reference a file, the zip archive doesn't exist, any of the subsequent connections doesn't exist or if an error occurred creating the target zip archive
-
zip(String, List)
orzip(String, List, String)
instead.