|
| 1 | +package org.cryptomator.integrations.mount; |
| 2 | + |
| 3 | +import org.jetbrains.annotations.Contract; |
| 4 | +import org.jetbrains.annotations.Range; |
| 5 | + |
| 6 | +import java.nio.file.Path; |
| 7 | + |
| 8 | +/** |
| 9 | + * Builder to mount a filesystem. |
| 10 | + * <p> |
| 11 | + * The setter may attempt to validate the input, but {@link #mount()} may still fail due to missing or invalid (combination of) options. |
| 12 | + * This holds especially for {@link MountBuilder#setMountFlags(String)}; |
| 13 | + */ |
| 14 | +public interface MountBuilder { |
| 15 | + |
| 16 | + /** |
| 17 | + * Sets the file system name. |
| 18 | + * |
| 19 | + * @param fileSystemName file system name |
| 20 | + * @return <code>this</code> |
| 21 | + * @throws UnsupportedOperationException If {@link MountCapability#FILE_SYSTEM_NAME} is not supported |
| 22 | + */ |
| 23 | + @Contract("_ -> this") |
| 24 | + default MountBuilder setFileSystemName(String fileSystemName) { |
| 25 | + throw new UnsupportedOperationException(); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Use the given host name as the loopback address. |
| 30 | + * |
| 31 | + * @param hostName string conforming with the uri host part |
| 32 | + * @return <code>this</code> |
| 33 | + * @throws UnsupportedOperationException If {@link MountCapability#LOOPBACK_HOST_NAME} is not supported |
| 34 | + */ |
| 35 | + @Contract("_ -> this") |
| 36 | + default MountBuilder setLoopbackHostName(String hostName) { |
| 37 | + throw new UnsupportedOperationException(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Use the given TCP port of the loopback address. |
| 42 | + * |
| 43 | + * @param port Fixed TCP port or 0 to use a system-assigned port |
| 44 | + * @return <code>this</code> |
| 45 | + * @throws UnsupportedOperationException If {@link MountCapability#LOOPBACK_PORT} is not supported |
| 46 | + */ |
| 47 | + @Contract("_ -> this") |
| 48 | + default MountBuilder setLoopbackPort(@Range(from = 0, to = Short.MAX_VALUE) int port) { |
| 49 | + throw new UnsupportedOperationException(); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Sets the mount point. |
| 54 | + * <p> |
| 55 | + * Unless the mount service provider supports {@link MountCapability#MOUNT_TO_SYSTEM_CHOSEN_PATH}, setting a mount point is required. |
| 56 | + * |
| 57 | + * @param mountPoint Where to mount the volume |
| 58 | + * @return <code>this</code> |
| 59 | + */ |
| 60 | + @Contract("_ -> this") |
| 61 | + default MountBuilder setMountpoint(Path mountPoint) { |
| 62 | + throw new UnsupportedOperationException(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Sets mount flags. |
| 67 | + * |
| 68 | + * @param mountFlags Mount flags |
| 69 | + * @return <code>this</code> |
| 70 | + * @throws UnsupportedOperationException If {@link MountCapability#MOUNT_FLAGS} is not supported |
| 71 | + * @see MountService#getDefaultMountFlags() |
| 72 | + */ |
| 73 | + @Contract("_ -> this") |
| 74 | + default MountBuilder setMountFlags(String mountFlags) { |
| 75 | + throw new UnsupportedOperationException(); |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + /** |
| 80 | + * Instructs the mount to be read-only. |
| 81 | + * |
| 82 | + * @param mountReadOnly Whether to mount read-only. |
| 83 | + * @return <code>this</code> |
| 84 | + * @throws UnsupportedOperationException If {@link MountCapability#READ_ONLY} is not supported |
| 85 | + */ |
| 86 | + @Contract("_ -> this") |
| 87 | + default MountBuilder setReadOnly(boolean mountReadOnly) { |
| 88 | + throw new UnsupportedOperationException(); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Sets a unique volume id. |
| 93 | + * <p> |
| 94 | + * The volume id is used as a path component, thus must conform with the os-dependent path component restrictions. |
| 95 | + * |
| 96 | + * @param volumeId String conforming with the os-dependent path component restrictions |
| 97 | + * @return <code>this</code> |
| 98 | + * @throws UnsupportedOperationException If {@link MountCapability#VOLUME_ID} is not supported |
| 99 | + */ |
| 100 | + @Contract("_ -> this") |
| 101 | + default MountBuilder setVolumeId(String volumeId) { |
| 102 | + throw new UnsupportedOperationException(); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Sets a volume name. |
| 107 | + * <p> |
| 108 | + * The volume name is intended to be human-readable. The input string might be altered to replace non-conforming characters and thus is not suited to identify the volume. |
| 109 | + * |
| 110 | + * @param volumeName String conforming with the os-dependent naming restrictions |
| 111 | + * @return <code>this</code> |
| 112 | + * @throws UnsupportedOperationException If {@link MountCapability#VOLUME_NAME} is not supported |
| 113 | + */ |
| 114 | + @Contract("_ -> this") |
| 115 | + default MountBuilder setVolumeName(String volumeName) { |
| 116 | + throw new UnsupportedOperationException(); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Mounts the file system. |
| 121 | + * |
| 122 | + * @return A mount handle |
| 123 | + * @throws MountFailedException If mounting failed |
| 124 | + */ |
| 125 | + @Contract(" -> new") |
| 126 | + Mount mount() throws MountFailedException; |
| 127 | + |
| 128 | +} |
0 commit comments