Class FileAPI

java.lang.Object
com.jedox.etl.core.scriptapi.ScriptAPI
com.jedox.etl.components.scriptapi.BaseAPI
com.jedox.etl.components.scriptapi.FileAPI
All Implemented Interfaces:
com.jedox.etl.core.scriptapi.IPropertiesAware, com.jedox.etl.core.scriptapi.IScriptAPI

public class FileAPI extends BaseAPI
Use with binding FILE to work with files and folders in file-based connections of Integrator projects.

Supported location types for file-based locations by operation:

Supported location types 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
1 File size not supported (FileInfo.getSize() returns 0)
2 Not possible to implement
3 For 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 supported
4 Only source connections referencing files, location type of target zip archive must be FileSystem
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    delete(String connName)
    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
    mkdirs(String connName)
    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 an InputStream.
    boolean
    rename(String connName, String newConnName)
    Renames the file or directory referenced by one file-based connection in its location to the name of a second file-based connection.
    unzip(String zipConnName, String targetConnName)
    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.
    unzip(String zipConnName, String targetConnName, String zipPwVar)
    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
    Writes binary data from an InputStream to a file referenced by a file-based connection.
    void
    zip(String zipTargetConnName, String... sourceConnNames)
    Deprecated.
    void
    zip(String zipTargetConnName, List<String> sourceConnNames)
    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
    zip(String zipTargetConnName, List<String> sourceConnNames, String zipPwVar)
    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.core.scriptapi.ScriptAPI

    getDefaultImports, getExtensionPoint, getParameters, setAPIDescriptor

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileAPI

      public FileAPI()
  • Method Details

    • getFilename

      public String getFilename(String connName) throws com.jedox.etl.core.component.ETLRuntimeException
      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

      public boolean delete(String connName) throws com.jedox.etl.core.component.ETLRuntimeException
      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 with zip(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 rename
      newConnName - 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

      public boolean mkdirs(String connName) throws com.jedox.etl.core.component.ETLRuntimeException
      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 an InputStream.
      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 an InputStream 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 project
      is - 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 archive
      targetConnName - name of a file-based connection referencing the target directory
      Returns:
      List containing the names of all unzipped files and directories as Strings
      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 archive
      targetConnName - name of a file-based connection referencing the target directory
      zipPwVar - 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 as Strings
      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 with zip(String, List, String).

      Parameters:
      zipTargetConnName - name of a file-based connection referencing the target zip archive
      zipPwVar - 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 type FileSystem 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 with zip(String, List).

      Parameters:
      zipTargetConnName - name of a file-based connection referencing the target zip archive
      sourceConnNames - names of file-based connections referencing files and directories to add to the zip archive (currently only directory locations of type FileSystem 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.
      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 archive
      sourceConnNames - names of file-based connections referencing files and directories to add to the zip archive (currently only directory locations of type FileSystem 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