Package org.mp4parser.muxer
Interface DataSource
-
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
FileDataSourceImpl,FileDataSourceViaHeapImpl,MemoryDataSourceImpl,MultiFileDataSourceImpl
public interface DataSource extends Closeable
-
-
Method Summary
Modifier and Type Method Description voidclose()Tries to free all resources.ByteBuffermap(long startPosition, long size)Maps a part of thisDataSourceinto aByteBuffer.longposition()Returns the DataSource's current position.voidposition(long nuPos)Sets the DataSource's position.intread(ByteBuffer byteBuffer)Reads a sequence of bytes from this channel into the given buffer.longsize()Returns the current size of this DataSource.longtransferTo(long position, long count, WritableByteChannel target)Transfers bytes from this DataSource to the given writable byte channel.
-
-
-
Method Detail
-
read
int read(ByteBuffer byteBuffer) throws IOException
Reads a sequence of bytes from this channel into the given buffer. Bytes are read starting at this channel's current position, and then the file position is updated with the number of bytes actually read.- Parameters:
byteBuffer- sink for this read operation- Returns:
- number of bytes actually read
- Throws:
IOException- If some I/O error occurs
-
size
long size() throws IOException
Returns the current size of this DataSource.- Returns:
- The current size of this DataSource, measured in bytes
- Throws:
IOException- If some I/O error occurs
-
position
long position() throws IOExceptionReturns the DataSource's current position.- Returns:
- This DataSource's file position, a non-negative integer counting the number of bytes from the beginning of the data to the current position
- Throws:
IOException- If some I/O error occurs
-
position
void position(long nuPos) throws IOExceptionSets the DataSource's position.- Parameters:
nuPos- The new position, a non-negative integer counting the number of bytes from the beginning of the data- Throws:
IOException- If some I/O error occurs
-
transferTo
long transferTo(long position, long count, WritableByteChannel target) throws IOExceptionTransfers bytes from this DataSource to the given writable byte channel.
An attempt should be made to read up to count bytes starting at the given position in this DataSource and write them to the target channel. An invocation of this method may or may not transfer all of the requested bytes;- Parameters:
position- The position within the DataSource at which the transfer is to begin; must be non-negativecount- The maximum number of bytes to be transferred; must be non-negativetarget- The target channel- Returns:
- the actual number of bytes written
- Throws:
IOException- If some I/O error occurs
-
map
ByteBuffer map(long startPosition, long size) throws IOException
Maps a part of thisDataSourceinto aByteBuffer. It might utilize an operating system supported memory mapped file or potentially just reads the requested portion of the file into the memory.- Parameters:
startPosition- where the requested block startsize- size of the requested block- Returns:
- the requested portion of the
DataSource - Throws:
IOException- If some I/O error occurs
-
close
void close() throws IOExceptionTries to free all resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- If some I/O error occurs
-
-