Package com.github.robtimus.filesystems
Class FileSystemProviderSupport
- java.lang.Object
-
- com.github.robtimus.filesystems.FileSystemProviderSupport
-
public final class FileSystemProviderSupport extends Object
A utility class that can assist in implementingFileSystemProvider
s.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SeekableByteChannel
createSeekableByteChannel(InputStream in, long size)
Creates aSeekableByteChannel
wrapped around anInputStream
.static SeekableByteChannel
createSeekableByteChannel(InputStream in, long size, long initialPosition)
Creates aSeekableByteChannel
wrapped around anInputStream
.static SeekableByteChannel
createSeekableByteChannel(OutputStream out)
Creates aSeekableByteChannel
wrapped around anOutputStream
.static SeekableByteChannel
createSeekableByteChannel(OutputStream out, long initialPosition)
Creates aSeekableByteChannel
wrapped around anOutputStream
.static boolean
getBooleanValue(Map<String,?> env, String property)
Retrieves a required boolean property from a map.static boolean
getBooleanValue(Map<String,?> env, String property, boolean defaultValue)
Retrieves an optional boolean property from a map.static byte
getByteValue(Map<String,?> env, String property)
Retrieves a required byte property from a map.static byte
getByteValue(Map<String,?> env, String property, byte defaultValue)
Retrieves an optional byte property from a map.static double
getDoubleValue(Map<String,?> env, String property)
Retrieves a required double property from a map.static double
getDoubleValue(Map<String,?> env, String property, double defaultValue)
Retrieves an optional double property from a map.static float
getFloatValue(Map<String,?> env, String property)
Retrieves a required float property from a map.static float
getFloatValue(Map<String,?> env, String property, float defaultValue)
Retrieves an optional float property from a map.static int
getIntValue(Map<String,?> env, String property)
Retrieves a required int property from a map.static int
getIntValue(Map<String,?> env, String property, int defaultValue)
Retrieves an optional int property from a map.static long
getLongValue(Map<String,?> env, String property)
Retrieves a required long property from a map.static long
getLongValue(Map<String,?> env, String property, long defaultValue)
Retrieves an optional long property from a map.static short
getShortValue(Map<String,?> env, String property)
Retrieves a required short property from a map.static short
getShortValue(Map<String,?> env, String property, short defaultValue)
Retrieves an optional short property from a map.static <T> T
getValue(Map<String,?> env, String property, Class<T> cls)
Retrieves a required property from a map.static <T> T
getValue(Map<String,?> env, String property, Class<T> cls, T defaultValue)
Retrieves an optional property from a map.
-
-
-
Method Detail
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(InputStream in, long size)
Creates aSeekableByteChannel
wrapped around anInputStream
. ThisSeekableByteChannel
, with an initial position of0
does not support seeking a specific position, truncating or writing.- Parameters:
in
- TheInputStream
to wrap.size
- The size of the source of theInputStream
.- Returns:
- The created
SeekableByteChannel
. - Throws:
NullPointerException
- If the givenInputStream
isnull
.IllegalArgumentException
- If the given size of initial position is negative.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(InputStream in, long size, long initialPosition)
Creates aSeekableByteChannel
wrapped around anInputStream
. ThisSeekableByteChannel
does not support seeking a specific position, truncating or writing.- Parameters:
in
- TheInputStream
to wrap.size
- The size of the source of theInputStream
.initialPosition
- The initial position of the returnedSeekableByteChannel
.- Returns:
- The created
SeekableByteChannel
. - Throws:
NullPointerException
- If the givenInputStream
isnull
.IllegalArgumentException
- If the given size of initial position is negative.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(OutputStream out)
Creates aSeekableByteChannel
wrapped around anOutputStream
. ThisSeekableByteChannel
, with an initial position of0
, does not support seeking a specific position, truncating or reading.- Parameters:
out
- TheOutputStream
to wrap.- Returns:
- The created
SeekableByteChannel
. - Throws:
NullPointerException
- If the givenOutputStream
isnull
.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(OutputStream out, long initialPosition)
Creates aSeekableByteChannel
wrapped around anOutputStream
. ThisSeekableByteChannel
does not support seeking a specific position, truncating or reading.- Parameters:
out
- TheOutputStream
to wrap.initialPosition
- The initial position of the returnedSeekableByteChannel
.- Returns:
- The created
SeekableByteChannel
. - Throws:
NullPointerException
- If the givenOutputStream
isnull
.IllegalArgumentException
- If the given initial position is negative.
-
getBooleanValue
public static boolean getBooleanValue(Map<String,?> env, String property)
Retrieves a required boolean property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeBoolean
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getBooleanValue
public static boolean getBooleanValue(Map<String,?> env, String property, boolean defaultValue)
Retrieves an optional boolean property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeBoolean
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getByteValue
public static byte getByteValue(Map<String,?> env, String property)
Retrieves a required byte property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeByte
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getByteValue
public static byte getByteValue(Map<String,?> env, String property, byte defaultValue)
Retrieves an optional byte property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeByte
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getShortValue
public static short getShortValue(Map<String,?> env, String property)
Retrieves a required short property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeShort
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getShortValue
public static short getShortValue(Map<String,?> env, String property, short defaultValue)
Retrieves an optional short property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeShort
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getIntValue
public static int getIntValue(Map<String,?> env, String property)
Retrieves a required int property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeInteger
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getIntValue
public static int getIntValue(Map<String,?> env, String property, int defaultValue)
Retrieves an optional int property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeInteger
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getLongValue
public static long getLongValue(Map<String,?> env, String property)
Retrieves a required long property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeLong
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getLongValue
public static long getLongValue(Map<String,?> env, String property, long defaultValue)
Retrieves an optional long property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeLong
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getFloatValue
public static float getFloatValue(Map<String,?> env, String property)
Retrieves a required float property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeFloat
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getFloatValue
public static float getFloatValue(Map<String,?> env, String property, float defaultValue)
Retrieves an optional float property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeFloat
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getDoubleValue
public static double getDoubleValue(Map<String,?> env, String property)
Retrieves a required double property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeDouble
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getDoubleValue
public static double getDoubleValue(Map<String,?> env, String property, double defaultValue)
Retrieves an optional double property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
. It supports values of typeDouble
andString
.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
getValue
public static <T> T getValue(Map<String,?> env, String property, Class<T> cls)
Retrieves a required property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
.- Type Parameters:
T
- The property type.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.cls
- The class the property should be an instance of.- Returns:
- The value for the given property.
- Throws:
IllegalArgumentException
- If the property is not present in the given map, or if its value has an incompatible type.
-
getValue
public static <T> T getValue(Map<String,?> env, String property, Class<T> cls, T defaultValue)
Retrieves an optional property from a map. This method can be used to retrieve properties in implementations ofFileSystemProvider.newFileSystem(URI, Map)
andFileSystemProvider.newFileSystem(Path, Map)
.- Type Parameters:
T
- The property type.- Parameters:
env
- The map to retrieve the property from.property
- The name of the property.cls
- The class the property should be an instance of.defaultValue
- The value that should be used if the property is not in the given map.- Returns:
- The value for the given property, or the given default value if the property is not in the given map.
- Throws:
IllegalArgumentException
- If the property's value has an incompatible type.
-
-