public class IOChannelUtils extends Object
| Constructor and Description |
|---|
IOChannelUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
constructName(String prefix,
String shardTemplate,
String suffix,
int shardNum,
int numShards)
Constructs a fully qualified name from components.
|
static WritableByteChannel |
create(String filename,
String mimeType)
Creates a write channel for the given filename.
|
static WritableByteChannel |
create(String prefix,
String shardTemplate,
String suffix,
int numShards,
String mimeType)
Creates a write channel for the given file components.
|
static IOChannelFactory |
getFactory(String spec)
Returns the IOChannelFactory associated with an input specification.
|
static long |
getSizeBytes(String spec)
Returns the size in bytes for the given specification.
|
static void |
registerStandardIOFactories(PipelineOptions options)
Registers standard factories globally.
|
static String |
resolve(String path,
String other)
Resolve the given
other against the path. |
static void |
setIOFactory(String scheme,
IOChannelFactory factory)
Associates a scheme with an
IOChannelFactory. |
public static void setIOFactory(String scheme, IOChannelFactory factory)
IOChannelFactory.
The given factory is used to construct read and write channels when a URI is provided with the given scheme.
For example, when reading from "gs://bucket/path", the scheme "gs" is used to lookup the appropriate factory.
public static void registerStandardIOFactories(PipelineOptions options)
PipelineOptions
to provide, e.g., credentials for GCS.public static WritableByteChannel create(String filename, String mimeType) throws IOException
IOExceptionpublic static WritableByteChannel create(String prefix, String shardTemplate, String suffix, int numShards, String mimeType) throws IOException
If numShards is specified, then a ShardingWritableByteChannel is returned.
Shard numbers are 0 based, meaning they start with 0 and end at the number of shards - 1.
IOExceptionpublic static long getSizeBytes(String spec) throws IOException
The specification is not expanded; it is used verbatim.
FileNotFoundException will be thrown if the resource does not exist.
IOExceptionpublic static String constructName(String prefix, String shardTemplate, String suffix, int shardNum, int numShards)
The name is built from a prefix, shard template (with shard numbers applied), and a suffix. All components are required, but may be empty strings.
Within a shard template, repeating sequences of the letters "S" or "N" are replaced with the shard number, or number of shards respectively. The numbers are formatted with leading zeros to match the length of the repeated sequence of letters.
For example, if prefix = "output", shardTemplate = "-SSS-of-NNN", and suffix = ".txt", with shardNum = 1 and numShards = 100, the following is produced: "output-001-of-100.txt".
public static IOChannelFactory getFactory(String spec) throws IOException
IOExceptionpublic static String resolve(String path, String other) throws IOException
other against the path.
If the other parameter is an absolute path then this method trivially returns other.
If other is an empty path then this method trivially returns the given path.
Otherwise this method considers the given path to be a directory and resolves the
other path against this path. In the simplest case, the other path does not
have a root component, in which case this method joins the other path to the given
path and returns a resulting path that ends with the other path.
Where the other path has a root component then resolution is highly implementation
dependent and therefore unspecified.
IOException