public class HttpKeyValueAccess extends Object implements KeyValueAccess
KeyValueAccess implementation using HTTP. As a result, calling lockForWriting, createDirectories, or delete will throw an N5Exception.
The behavior of list, listDirectories, and isDirectory will depend on the server configuration. See the documentation of those methods for details.
Methods that take a "normalPath" as an argument expect absolute URIs.
| Modifier and Type | Field and Description |
|---|---|
static String |
ACCEPT_RANGE |
static String |
BYTES |
static String |
GET |
static String |
HEAD |
static String |
RANGE |
| Constructor and Description |
|---|
HttpKeyValueAccess()
Opens an
HttpKeyValueAccess |
| Modifier and Type | Method and Description |
|---|---|
void |
createDirectories(String normalPath)
Create a directory and all parent paths along the way.
|
VolatileReadData |
createReadData(String normalPath)
Create a
VolatileReadData through which data at the normal key
can be read. |
void |
delete(String normalPath)
Delete a path.
|
boolean |
exists(String normalPath)
Test whether the
normalPath exists. |
boolean |
isDirectory(String normalPath)
Test whether the path is a directory.
|
boolean |
isFile(String normalPath)
Test whether the path is a file.
|
String[] |
list(String normalPath)
List all children of a path.
|
String[] |
listDirectories(String normalPath)
List all 'directory'-like children of a path.
|
LockedChannel |
lockForReading(String normalPath)
Create a lock on a path for reading.
|
LockedChannel |
lockForWriting(String normalPath)
Create an exclusive lock on a path for writing.
|
String |
normalize(String path)
Normalize a path to canonical form.
|
void |
setConnectionTimeout(int connectionTimeoutMilliseconds) |
void |
setListDirectoryParser(ListResponseParser parser) |
void |
setListParser(ListResponseParser parser) |
void |
setReadTimeout(int readTimeoutMilliseconds) |
long |
size(String normalPath)
Returns the size in bytes of the object at the given normalPath if it exists.
|
URI |
uri(String normalPath)
Get the absolute (including scheme)
URI of the given path |
void |
write(String normalPath,
ReadData data)
Write
data to the given normalPath. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomponents, compose, compose, parent, relativizepublic static final String HEAD
public static final String GET
public static final String RANGE
public static final String ACCEPT_RANGE
public static final String BYTES
public HttpKeyValueAccess()
HttpKeyValueAccessN5Exception.N5IOException - if the access could not be createdpublic void setReadTimeout(int readTimeoutMilliseconds)
public void setConnectionTimeout(int connectionTimeoutMilliseconds)
public void setListParser(ListResponseParser parser)
public void setListDirectoryParser(ListResponseParser parser)
public String normalize(String path)
KeyValueAccessnormalize in interface KeyValueAccesspath - the pathpublic URI uri(String normalPath) throws URISyntaxException
KeyValueAccessURI of the given pathuri in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.URISyntaxException - if the given path is not a proper URIpublic boolean exists(String normalPath)
normalPath exists.
Removes leading slash from normalPath, and then checks whether
either path or path + "/" is a key.
exists in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are
made to normalize it.true if path exists, false otherwisepublic long size(String normalPath)
KeyValueAccesssize in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.public boolean isDirectory(String normalPath)
Appends trailing "/" to normalPath if there is none, removes
leading "/", and then checks whether resulting path is a key.
isDirectory in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are
made to normalize it.true if path (with trailing "/") exists as a key,
false otherwisepublic boolean isFile(String normalPath)
Checks whether normalPath has no trailing "/", then removes
leading "/" and checks whether the resulting path is a key.
isFile in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are
made to normalize it.true if path exists as a key and has no trailing
slash, false otherwisepublic VolatileReadData createReadData(String normalPath)
KeyValueAccessVolatileReadData through which data at the normal key
can be read.
Implementations should read lazily if possible. Consumers may call ReadData.materialize() to force a read operation if needed.
If supported by this KeyValueAccess implementation, partial reads are
possible by slicing the returned ReadData.
The resulting VolatileReadData is potentially lazy. If the requested
key does not exist, it will throw N5NoSuchKeyException. Whether
the exception is thrown when KeyValueAccess.createReadData(String)] is called,
or when trying to materialize the VolatileReadData is implementation dependent.
createReadData in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are made to normalize itpublic LockedChannel lockForReading(String normalPath) throws N5Exception.N5IOException
KeyValueAccess
try (final lock = store.lockForReading()) {
...
}
lockForReading in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.N5Exception.N5IOException - if a locked channel could not be createdpublic LockedChannel lockForWriting(String normalPath) throws N5Exception.N5IOException
KeyValueAccess
try (final lock = store.lockForWriting()) {
...
}
lockForWriting in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.N5Exception.N5IOException - if a locked channel could not be createdpublic void write(String normalPath, ReadData data) throws N5Exception.N5IOException
KeyValueAccessdata to the given normalPath.
Existing data at normalPath will be overridden.
write in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are made to normalize itdata - the data to writeN5Exception.N5IOException - if an error occurspublic String[] listDirectories(String normalPath) throws N5Exception.N5IOException
Will throw an N5IOException both if a connection to the server can not be established, or the server does not allow listing.
listDirectories in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.N5Exception.N5IOException - if an error occurs during listingpublic String[] list(String normalPath) throws N5Exception.N5IOException
Will throw an N5IOException both if a connection to the server can not be established, or the server does not allow listing.
list in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further efforts are
made to normalize it.N5Exception.N5IOException - if an error occurs during listingpublic void createDirectories(String normalPath)
KeyValueAccesscreateDirectories in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.public void delete(String normalPath)
KeyValueAccessdelete in interface KeyValueAccessnormalPath - is expected to be in normalized form, no further
efforts are made to normalize it.Copyright © 2017–2026 Saalfeld Lab. All rights reserved.