Package com.snowflake.snowpark_java

## Class FileOperation

- java.lang.Object
- - com.snowflake.snowpark_java.FileOperation

-     public class FileOperation
      extends java.lang.Object

  Provides methods for working on files in a stage.

  To access an object of this class, use `Session.file`.

  Since:
    1.2.0

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `java.io.InputStream` | `downloadStream​(java.lang.String stageLocation, boolean decompress)` | Download file from the given stage and return an input stream
    `GetResult[]` | `get​(java.lang.String stageLocation, java.lang.String targetDirectory)` | Downloads the specified files from a path in a stage (specified by `stageLocation`) to the local directory specified by `targetLocation`.
    `GetResult[]` | `get​(java.lang.String stageLocation, java.lang.String targetDirectory, java.util.Map<java.lang.String,​java.lang.String> options)` | Downloads the specified files from a path in a stage (specified by `stageLocation`) to the local directory specified by `targetLocation`.
    `PutResult[]` | `put​(java.lang.String localFileName, java.lang.String stageLocation)` | Uploads the local files specified by `localFileName` to the stage location specified in `stageLocation`.
    `PutResult[]` | `put​(java.lang.String localFileName, java.lang.String stageLocation, java.util.Map<java.lang.String,​java.lang.String> options)` | Uploads the local files specified by `localFileName` to the stage location specified in `stageLocation`.
    `void` | `uploadStream​(java.lang.String stageLocation, java.io.InputStream inputStream, boolean compress)` | Method to compress data from a stream and upload it at a stage location.

    - ### Methods inherited from class java.lang.Object

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

- - ### Method Detail

    - #### put

          public PutResult[] put​(java.lang.String localFileName,
                                 java.lang.String stageLocation,
                                 java.util.Map<java.lang.String,​java.lang.String> options)

      Uploads the local files specified by `localFileName` to the stage location specified in `stageLocation`.

      This method returns the results as an Array of `PutResult` objects (one for each file). Each object represents the results of uploading a file.

      For example:

           Map<String, String> options = new HashMap<>();
           options.put("AUTO_COMPRESS", "FALSE");
           session.file().put("file://file_path", "@stage_name", options);

      Parameters:
        `localFileName` - The path to the local file(s) to upload. Specify the path in the following format: `file://'path_to_file'/'filename'`. (The `file://` prefix is optional.) To match multiple files in the path, you can specify the wildcard characters `*` and `?`.
        `stageLocation` - The stage (and prefix) where you want to upload the file(s). The `@` prefix is optional.
        `options` - A Map containing the names and values of optional parameters for the PUT command.
      Returns:
        An Array of `PutResult` objects (one object for each file uploaded).
      Since:
        1.2.0

    - #### put

          public PutResult[] put​(java.lang.String localFileName,
                                 java.lang.String stageLocation)

      Uploads the local files specified by `localFileName` to the stage location specified in `stageLocation`.

      This method returns the results as an Array of `PutResult` objects (one for each file). Each object represents the results of uploading a file.

      For example:

           session.file().put("file://file_path", "@stage_name");

      Parameters:
        `localFileName` - The path to the local file(s) to upload. Specify the path in the following format: `file://'path_to_file'/'filename'`. (The `file://` prefix is optional.) To match multiple files in the path, you can specify the wildcard characters `*` and `?`.
        `stageLocation` - The stage (and prefix) where you want to upload the file(s). The `@` prefix is optional.
      Returns:
        An Array of `PutResult` objects (one object for each file uploaded).
      Since:
        1.2.0

    - #### get

          public GetResult[] get​(java.lang.String stageLocation,
                                 java.lang.String targetDirectory,
                                 java.util.Map<java.lang.String,​java.lang.String> options)

      Downloads the specified files from a path in a stage (specified by `stageLocation`) to the local directory specified by `targetLocation`.

      This method returns the results as an Array of `GetResult` objects (one for each file). Each object represents the results of downloading a file.

      For example:

           Map<String, String> options = new HashMap<>();
           options.put("PATTERN", "'.*.csv'");
           session.file().get("@stage_name/", "file:///tmp/", options);

      Parameters:
        `stageLocation` - The location (a directory or filename on a stage) from which you want to download the files. The `@` prefix is optional.
        `targetDirectory` - The path to the local directory where the file(s) should be downloaded. Specify the path in the following format: `file://'path_to_file'/'filename'`. If `targetDirectory` does not already exist, the method creates the directory.
        `options` - A Map containing the names and values of optional parameters for the GET command.
      Returns:
        An Array of PutResult objects (one object for each file downloaded).
      Since:
        1.2.0

    - #### get

          public GetResult[] get​(java.lang.String stageLocation,
                                 java.lang.String targetDirectory)

      Downloads the specified files from a path in a stage (specified by `stageLocation`) to the local directory specified by `targetLocation`.

      This method returns the results as an Array of `GetResult` objects (one for each file). Each object represents the results of downloading a file.

      For example:

           getSession().file().get("@stage_name/", "file:///tmp/");

      Parameters:
        `stageLocation` - The location (a directory or filename on a stage) from which you want to download the files. The `@` prefix is optional.
        `targetDirectory` - The path to the local directory where the file(s) should be downloaded. Specify the path in the following format: `file://'path_to_file'/'filename'`. If `targetDirectory` does not already exist, the method creates the directory.
      Returns:
        An Array of PutResult objects (one object for each file downloaded).
      Since:
        1.2.0

    - #### uploadStream

          public void uploadStream​(java.lang.String stageLocation,
                                   java.io.InputStream inputStream,
                                   boolean compress)

      Method to compress data from a stream and upload it at a stage location. The data will be uploaded as one file. No splitting is done in this method.

      caller is responsible for releasing the inputStream after the method is called.

      Parameters:
        `stageLocation` - Full stage path to the file
        `inputStream` - Input stream from which the data will be uploaded
        `compress` - Compress data or not before uploading stream
      Since:
        1.4.0

    - #### downloadStream

          public java.io.InputStream downloadStream​(java.lang.String stageLocation,
                                                    boolean decompress)

      Download file from the given stage and return an input stream
      Parameters:
        `stageLocation` - Full stage path to the file
        `decompress` - True if file compressed
      Returns:
        An InputStream object
      Since:
        1.4.0