public class DbfsExt extends DbfsAPI
This class provides utility methods for the DBFS API that are not part of the official API surface. These methods are subject to change without notice.
Constructor and Description |
---|
DbfsExt(ApiClient apiClient) |
DbfsExt(DbfsService mock) |
Modifier and Type | Method and Description |
---|---|
OutputStream |
getOutputStream(String path)
Returns an OutputStream that writes to the given file in DBFS.
|
InputStream |
open(String path)
Construct a new
java.io.BufferedReader for the given file. |
byte[] |
readAllBytes(Path path)
Returns the contents of the given file as a byte array.
|
List<String> |
readAllLines(Path path,
Charset cs)
Returns the contents of the given file as a list of strings, where each string corresponds to a
line in the file.
|
Iterable<FileInfo> |
recursiveList(String path)
Recursively lists files in DBFS, starting from the provided directory.
|
Path |
write(Path path,
byte[] bytes)
Writes the given bytes to the given file in DBFS.
|
public DbfsExt(ApiClient apiClient)
public DbfsExt(DbfsService mock)
public InputStream open(String path)
java.io.BufferedReader
for the given file.
The returned implementation of InputStream
internally buffers calls to the DBFS API
to reduce the number of requests made. The buffer has a maximum size of 1 MB, corresponding to
the maximum number of bytes that can be read in a single call to the DBFS API. The buffer is
refilled when read()
is called after the buffer has been exhausted.
path
- the path to the file to readpublic byte[] readAllBytes(Path path) throws IOException
This method is analogous to Files.readAllBytes(path)
in Java 8, but it reads the
file from DBFS instead of the local filesystem.
path
- the path to the file to readIOException
- if an I/O error occurspublic List<String> readAllLines(Path path, Charset cs) throws IOException
This method is analogous to Files.readAllLines(path, cs)
in Java 8, but it reads the
file from DBFS instead of the local filesystem.
path
- the path to the file to readcs
- the charset to use when decoding the fileIOException
- if an I/O error occurspublic OutputStream getOutputStream(String path)
This method first creates the given file in DBFS if it does not exist. If the file exists, this method overwrites the existing file. Then, this method constructs an OutputStream that writes to the file in DBFS. The returned OutputStream buffers writes to the file to reduce the number of requests made to the DBFS API. The buffer has a maximum size of 1 MB, corresponding to the maximum number of bytes that can be written in a single call to the DBFS AddBlock API, and is flushed when full.
path
- the path to the file to readpublic Path write(Path path, byte[] bytes) throws IOException
This methods is analogous to Files.write(path, bytes)
in Java 8, but it writes the
file to DBFS instead of the local filesystem.
path
- the path to the file to writebytes
- the bytes to writeIOException
- if an I/O error occurspublic Iterable<FileInfo> recursiveList(String path)
path
- the path to the directory to listCopyright © 2023. All rights reserved.