Class S3SeekableByteChannel
- java.lang.Object
-
- software.amazon.nio.spi.s3.S3SeekableByteChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.SeekableByteChannel,java.nio.channels.WritableByteChannel
public class S3SeekableByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedS3SeekableByteChannel(S3Path s3Path)protectedS3SeekableByteChannel(S3Path s3Path, long startAt)Deprecated.startAt is only a valid parameter for the read mode and is therefore discouraged to be used during creation of the channelprotectedS3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client)protectedS3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, long startAt)Deprecated.startAt is only a valid parameter for the read mode and is therefore discouraged to be used during creation of the channelprotectedS3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, java.util.Set<? extends java.nio.file.OpenOption> options)protectedS3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, java.util.Set<? extends java.nio.file.OpenOption> options, long timeout, java.util.concurrent.TimeUnit timeUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this channel.protected java.nio.channels.ReadableByteChannelgetReadDelegate()Access the underlyingReadableByteChannelused for readingprotected java.nio.channels.WritableByteChannelgetWriteDelegate()Access the underlyingWritableByteChannelused for writingbooleanisOpen()Tells whether this channel is open.longposition()Returns this channel's position.java.nio.channels.SeekableByteChannelposition(long newPosition)Sets this channel's position.intread(java.nio.ByteBuffer dst)Reads a sequence of bytes from this channel into the given buffer.longsize()Returns the current size of entity to which this channel is connected.java.nio.channels.SeekableByteChanneltruncate(long size)Truncates the entity, to which this channel is connected, to the given size.intwrite(java.nio.ByteBuffer src)Writes a sequence of bytes to this channel from the given buffer.
-
-
-
Constructor Detail
-
S3SeekableByteChannel
protected S3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client) throws java.io.IOException
- Throws:
java.io.IOException
-
S3SeekableByteChannel
@Deprecated protected S3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, long startAt) throws java.io.IOException
Deprecated.startAt is only a valid parameter for the read mode and is therefore discouraged to be used during creation of the channel- Parameters:
s3Client- the s3 client to use to obtain bytes for the byte channels3Path- the path to the filestartAt- the position to start at- Throws:
java.io.IOException- if there is an error creating the channel
-
S3SeekableByteChannel
@Deprecated protected S3SeekableByteChannel(S3Path s3Path, long startAt) throws java.io.IOException
Deprecated.startAt is only a valid parameter for the read mode and is therefore discouraged to be used during creation of the channel- Parameters:
s3Path- the path to the filestartAt- the position to start at- Throws:
java.io.IOException- if there is an error creating the channel
-
S3SeekableByteChannel
protected S3SeekableByteChannel(S3Path s3Path) throws java.io.IOException
- Throws:
java.io.IOException
-
S3SeekableByteChannel
protected S3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, java.util.Set<? extends java.nio.file.OpenOption> options) throws java.io.IOException
- Throws:
java.io.IOException
-
S3SeekableByteChannel
protected S3SeekableByteChannel(S3Path s3Path, software.amazon.awssdk.services.s3.S3AsyncClient s3Client, java.util.Set<? extends java.nio.file.OpenOption> options, long timeout, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionReads a sequence of bytes from this channel into the given buffer.Bytes are read starting at this channel's current position, and then the position is updated with the number of bytes actually read. Otherwise, this method behaves exactly as specified in the
ReadableByteChannelinterface.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Specified by:
readin interfacejava.nio.channels.SeekableByteChannel- Parameters:
dst- the destination buffer- Returns:
- the number of bytes read or -1 if no more bytes can be read.
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOExceptionWrites a sequence of bytes to this channel from the given buffer.Bytes are written starting at this channel's current position, unless the channel is connected to an entity such as a file that is opened with the
APPENDoption, in which case the position is first advanced to the end. The entity to which the channel is connected will grow to accommodate the written bytes, and the position updates with the number of bytes actually written. Otherwise, this method behaves exactly as specified by theWritableByteChannelinterface.- Specified by:
writein interfacejava.nio.channels.SeekableByteChannel- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Parameters:
src- the src of the bytes to write to this channel- Throws:
java.io.IOException
-
position
public long position() throws java.io.IOExceptionReturns this channel's position.- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Returns:
- This channel's position, a non-negative integer counting the number of bytes from the beginning of the entity to the current position
- Throws:
java.io.IOException
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOExceptionSets this channel's position.Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.
Setting the channel's position is not recommended when connected to an entity, typically a file, that is opened with the
APPENDoption. When opened for append, the position is first advanced to the end before writing.- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Parameters:
newPosition- The new position, a non-negative integer counting the number of bytes from the beginning of the entity- Returns:
- This channel
- Throws:
java.nio.channels.ClosedChannelException- If this channel is closedjava.lang.IllegalArgumentException- If the new position is negativejava.io.IOException- If some other I/O error occurs
-
size
public long size() throws java.io.IOExceptionReturns the current size of entity to which this channel is connected.- Specified by:
sizein interfacejava.nio.channels.SeekableByteChannel- Returns:
- The current size, measured in bytes
- Throws:
java.io.IOException- If some other I/O error occurs
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size)
Truncates the entity, to which this channel is connected, to the given size.If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size.
An implementation of this interface may prohibit truncation when connected to an entity, typically a file, opened with the
APPENDoption.- Specified by:
truncatein interfacejava.nio.channels.SeekableByteChannel- Parameters:
size- The new size, a non-negative byte count- Returns:
- This channel
-
isOpen
public boolean isOpen()
Tells whether this channel is open.- Specified by:
isOpenin interfacejava.nio.channels.Channel- Returns:
trueif, and only if, this channels delegate is open
-
close
public void close() throws java.io.IOExceptionCloses this channel.After a channel is closed, any further attempt to invoke I/O operations upon it will cause a
ClosedChannelExceptionto be thrown.If this channel is already closed then invoking this method has no effect.
This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getReadDelegate
protected java.nio.channels.ReadableByteChannel getReadDelegate()
Access the underlyingReadableByteChannelused for reading- Returns:
- the channel. May be null if opened for writing only
-
getWriteDelegate
protected java.nio.channels.WritableByteChannel getWriteDelegate()
Access the underlyingWritableByteChannelused for writing- Returns:
- the channel. May be null if opened for reading only
-
-