public class FileOperation extends Object
To access an object of this class, use Session.file.
| Modifier and Type | Method and Description |
|---|---|
InputStream |
downloadStream(String stageLocation,
boolean decompress)
Download file from the given stage and return an input stream
|
GetResult[] |
get(String stageLocation,
String targetDirectory)
Downloads the specified files from a path in a stage (specified by
stageLocation) to
the local directory specified by targetLocation. |
GetResult[] |
get(String stageLocation,
String targetDirectory,
Map<String,String> options)
Downloads the specified files from a path in a stage (specified by
stageLocation) to
the local directory specified by targetLocation. |
PutResult[] |
put(String localFileName,
String stageLocation)
Uploads the local files specified by
localFileName to the stage location specified in
stageLocation. |
PutResult[] |
put(String localFileName,
String stageLocation,
Map<String,String> options)
Uploads the local files specified by
localFileName to the stage location specified in
stageLocation. |
void |
uploadStream(String stageLocation,
InputStream inputStream,
boolean compress)
Method to compress data from a stream and upload it at a stage location.
|
public PutResult[] put(String localFileName, String stageLocation, Map<String,String> options)
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);
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.PutResult objects (one object for each file uploaded).public PutResult[] put(String localFileName, String stageLocation)
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");
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.PutResult objects (one object for each file uploaded).public GetResult[] get(String stageLocation, String targetDirectory, Map<String,String> options)
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);
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.public GetResult[] get(String stageLocation, String targetDirectory)
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/");
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.public void uploadStream(String stageLocation, InputStream inputStream, boolean compress)
caller is responsible for releasing the inputStream after the method is called.
stageLocation - Full stage path to the fileinputStream - Input stream from which the data will be uploadedcompress - Compress data or not before uploading streampublic InputStream downloadStream(String stageLocation, boolean decompress)
stageLocation - Full stage path to the filedecompress - True if file compressed© 2022 Snowflake Inc. All Rights Reserved