Package ch.pontius.nio.smb
Class SeekableSMBByteChannel
- java.lang.Object
-
- ch.pontius.nio.smb.SeekableSMBByteChannel
-
- 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 final class SeekableSMBByteChannel extends java.lang.Object implements java.nio.channels.SeekableByteChannel
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the currentSeekableSMBByteChannel.booleanisOpen()Determines whether the currentSeekableSMBByteChannelis still opened.longposition()Returns the position of the pointer into theSmbRandomAccessFilethat is handled by the current instance ofSeekableSMBByteChanneljava.nio.channels.SeekableByteChannelposition(long newPosition)Tries to reposition the pointer into theSmbRandomAccessFilethat is handled by the current instance ofSeekableSMBByteChannelintread(java.nio.ByteBuffer dst)Reads the content from theSmbRandomAccessFilehandled by the current instance ofSeekableSMBByteChannelto the providedByteBuffer.longsize()Returns the size of the file handled by the current instance ofSeekableSMBByteChannel.java.nio.channels.SeekableByteChanneltruncate(long size)Truncates theSmbRandomAccessFileby setting its length to the provided value.intwrite(java.nio.ByteBuffer src)Writes the content of the providedByteBufferinto theSmbRandomAccessFilehandled by the current instance ofSeekableSMBByteChannel.
-
-
-
Method Detail
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionReads the content from theSmbRandomAccessFilehandled by the current instance ofSeekableSMBByteChannelto the providedByteBuffer. TheByteBufferis written from its current position to its end.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Specified by:
readin interfacejava.nio.channels.SeekableByteChannel- Parameters:
dst-ByteBufferto which to write the data.- Returns:
- Number of bytes that were read.
- Throws:
java.io.IOException- If something goes wrong while reading to the file.
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOExceptionWrites the content of the providedByteBufferinto theSmbRandomAccessFilehandled by the current instance ofSeekableSMBByteChannel. TheByteBufferis read from its current position to it end.- Specified by:
writein interfacejava.nio.channels.SeekableByteChannel- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Parameters:
src-ByteBufferfrom which to read the data.- Returns:
- Number of bytes that were written.
- Throws:
java.io.IOException- If something goes wrong while writing to the file.
-
position
public long position() throws java.io.IOExceptionReturns the position of the pointer into theSmbRandomAccessFilethat is handled by the current instance ofSeekableSMBByteChannel- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Returns:
- newPosition New position within the file.
- Throws:
java.io.IOException- If something goes wrong while trying to determine file size.
-
size
public long size() throws java.io.IOExceptionReturns the size of the file handled by the current instance ofSeekableSMBByteChannel. The size is given in number of bytes.- Specified by:
sizein interfacejava.nio.channels.SeekableByteChannel- Returns:
- size Size of the SMB file.
- Throws:
java.io.IOException- If something goes wrong while trying to determine file size.
-
position
public java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOExceptionTries to reposition the pointer into theSmbRandomAccessFilethat is handled by the current instance ofSeekableSMBByteChannel- Specified by:
positionin interfacejava.nio.channels.SeekableByteChannel- Parameters:
newPosition- New position within the file.- Returns:
- Current instance of
SeekableSMBByteChannel. - Throws:
java.io.IOException- If something goes wrong while trying to determine file size.
-
truncate
public java.nio.channels.SeekableByteChannel truncate(long size) throws java.io.IOExceptionTruncates theSmbRandomAccessFileby setting its length to the provided value.- Specified by:
truncatein interfacejava.nio.channels.SeekableByteChannel- Parameters:
size- New size of the file.- Returns:
- Current instance of
SeekableSMBByteChannel. - Throws:
java.io.IOException- If something goes wrong during truncation.
-
isOpen
public boolean isOpen()
Determines whether the currentSeekableSMBByteChannelis still opened.- Specified by:
isOpenin interfacejava.nio.channels.Channel- Returns:
- True if
SeekableSMBByteChanneland false otherwise.
-
close
public void close() throws java.io.IOExceptionCloses the currentSeekableSMBByteChannel. After that, it is not possible to either read from or write to the channel.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- If something goes wrong while closing the channel.
-
-