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 implementingFileSystemProviders.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SeekableByteChannelcreateSeekableByteChannel(InputStream in, long size)Creates aSeekableByteChannelwrapped around anInputStream.static SeekableByteChannelcreateSeekableByteChannel(InputStream in, long size, long initialPosition)Creates aSeekableByteChannelwrapped around anInputStream.static SeekableByteChannelcreateSeekableByteChannel(OutputStream out)Creates aSeekableByteChannelwrapped around anOutputStream.static SeekableByteChannelcreateSeekableByteChannel(OutputStream out, long initialPosition)Creates aSeekableByteChannelwrapped around anOutputStream.static booleangetBooleanValue(Map<String,?> env, String property)Retrieves a required boolean property from a map.static booleangetBooleanValue(Map<String,?> env, String property, boolean defaultValue)Retrieves an optional boolean property from a map.static bytegetByteValue(Map<String,?> env, String property)Retrieves a required byte property from a map.static bytegetByteValue(Map<String,?> env, String property, byte defaultValue)Retrieves an optional byte property from a map.static doublegetDoubleValue(Map<String,?> env, String property)Retrieves a required double property from a map.static doublegetDoubleValue(Map<String,?> env, String property, double defaultValue)Retrieves an optional double property from a map.static floatgetFloatValue(Map<String,?> env, String property)Retrieves a required float property from a map.static floatgetFloatValue(Map<String,?> env, String property, float defaultValue)Retrieves an optional float property from a map.static intgetIntValue(Map<String,?> env, String property)Retrieves a required int property from a map.static intgetIntValue(Map<String,?> env, String property, int defaultValue)Retrieves an optional int property from a map.static longgetLongValue(Map<String,?> env, String property)Retrieves a required long property from a map.static longgetLongValue(Map<String,?> env, String property, long defaultValue)Retrieves an optional long property from a map.static shortgetShortValue(Map<String,?> env, String property)Retrieves a required short property from a map.static shortgetShortValue(Map<String,?> env, String property, short defaultValue)Retrieves an optional short property from a map.static <T> TgetValue(Map<String,?> env, String property, Class<T> cls)Retrieves a required property from a map.static <T> TgetValue(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 aSeekableByteChannelwrapped around anInputStream. ThisSeekableByteChannel, with an initial position of0does not support seeking a specific position, truncating or writing.- Parameters:
in- TheInputStreamto wrap.size- The size of the source of theInputStream.- Returns:
- The created
SeekableByteChannel. - Throws:
NullPointerException- If the givenInputStreamisnull.IllegalArgumentException- If the given size of initial position is negative.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(InputStream in, long size, long initialPosition)
Creates aSeekableByteChannelwrapped around anInputStream. ThisSeekableByteChanneldoes not support seeking a specific position, truncating or writing.- Parameters:
in- TheInputStreamto wrap.size- The size of the source of theInputStream.initialPosition- The initial position of the returnedSeekableByteChannel.- Returns:
- The created
SeekableByteChannel. - Throws:
NullPointerException- If the givenInputStreamisnull.IllegalArgumentException- If the given size of initial position is negative.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(OutputStream out)
Creates aSeekableByteChannelwrapped around anOutputStream. ThisSeekableByteChannel, with an initial position of0, does not support seeking a specific position, truncating or reading.- Parameters:
out- TheOutputStreamto wrap.- Returns:
- The created
SeekableByteChannel. - Throws:
NullPointerException- If the givenOutputStreamisnull.
-
createSeekableByteChannel
public static SeekableByteChannel createSeekableByteChannel(OutputStream out, long initialPosition)
Creates aSeekableByteChannelwrapped around anOutputStream. ThisSeekableByteChanneldoes not support seeking a specific position, truncating or reading.- Parameters:
out- TheOutputStreamto wrap.initialPosition- The initial position of the returnedSeekableByteChannel.- Returns:
- The created
SeekableByteChannel. - Throws:
NullPointerException- If the givenOutputStreamisnull.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 typeBooleanandString.- 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 typeBooleanandString.- 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 typeByteandString.- 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 typeByteandString.- 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 typeShortandString.- 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 typeShortandString.- 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 typeIntegerandString.- 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 typeIntegerandString.- 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 typeLongandString.- 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 typeLongandString.- 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 typeFloatandString.- 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 typeFloatandString.- 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 typeDoubleandString.- 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 typeDoubleandString.- 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.
-
-