Class HttpSeekableByteChannel
java.lang.Object
org.broadinstitute.http.nio.HttpSeekableByteChannel
- All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, ReadableByteChannel, SeekableByteChannel, WritableByteChannel
Implementation for a
SeekableByteChannel for URL open as a connection.
The current implementation is thread-safe using the synchronized keyword in every
method.
- Author:
- Daniel Gomez-Sanchez (magicDGS)
-
Constructor Summary
ConstructorsConstructorDescriptioncreate a new seekable channel with default setttings at beggining of the fileHttpSeekableByteChannel(URI uri, long position) Create a new seekable channel with default setttins and seek to the given positionHttpSeekableByteChannel(URI uri, HttpFileSystemProviderSettings settings, long position) Create a new seekable channel which reads from the requested URI -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanisOpen()longposition()position(long newPosition) intread(ByteBuffer dst) static intPerforms the equivalent of a channel.read(buf) operation but in the case of an exception the state of the input buffer is not adversely impacted.longsize()truncate(long size) intwrite(ByteBuffer src)
-
Constructor Details
-
HttpSeekableByteChannel
create a new seekable channel with default setttings at beggining of the file- Parameters:
uri- the URI to connect to, this should not include range parameters already- Throws:
IOException- if no connection can be established
-
HttpSeekableByteChannel
Create a new seekable channel with default setttins and seek to the given position- Parameters:
uri- the URI to connect to, this should not include range parameters alreadyposition- an initial byte offset to open the file at- Throws:
IOException- if no connection can be established
-
HttpSeekableByteChannel
public HttpSeekableByteChannel(URI uri, HttpFileSystemProviderSettings settings, long position) throws IOException Create a new seekable channel which reads from the requested URI- Parameters:
uri- the URI to connect to, this should not include range parameters alreadysettings- settings to configure the connection and retry handlingposition- an initial byte offset to open the file at- Throws:
IOException- if no connection can be established
-
-
Method Details
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekableByteChannel- Throws:
IOException
-
readWithoutPerturbingTheBufferIfAnErrorOccurs
public static int readWithoutPerturbingTheBufferIfAnErrorOccurs(ByteBuffer dst, ReadableByteChannel channel) throws IOException Performs the equivalent of a channel.read(buf) operation but in the case of an exception the state of the input buffer is not adversely impacted.- Parameters:
dst- a ByteBuffer to read intochannel- the channel to reaad from- Returns:
- the number of bytes read from the channel
- Throws:
IOException- if the read operation throws
-
write
- Specified by:
writein interfaceSeekableByteChannel- Specified by:
writein interfaceWritableByteChannel
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException
-
position
- Specified by:
positionin interfaceSeekableByteChannel- Throws:
IOException
-
size
- Specified by:
sizein interfaceSeekableByteChannel- Throws:
IOException
-
truncate
- Specified by:
truncatein interfaceSeekableByteChannel
-
isOpen
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-