Package org.mp4parser.muxer
Class FileDataSourceViaHeapImpl
- java.lang.Object
-
- org.mp4parser.muxer.FileDataSourceViaHeapImpl
-
- All Implemented Interfaces:
Closeable,AutoCloseable,DataSource
public class FileDataSourceViaHeapImpl extends Object implements DataSource
-
-
Constructor Summary
Constructors Constructor Description FileDataSourceViaHeapImpl(File f)FileDataSourceViaHeapImpl(String f)FileDataSourceViaHeapImpl(FileChannel fc)FileDataSourceViaHeapImpl(FileChannel fc, String filename)
-
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.StringtoString()longtransferTo(long startPosition, long count, WritableByteChannel sink)Transfers bytes from this DataSource to the given writable byte channel.
-
-
-
Constructor Detail
-
FileDataSourceViaHeapImpl
public FileDataSourceViaHeapImpl(File f) throws FileNotFoundException
- Throws:
FileNotFoundException
-
FileDataSourceViaHeapImpl
public FileDataSourceViaHeapImpl(String f) throws FileNotFoundException
- Throws:
FileNotFoundException
-
FileDataSourceViaHeapImpl
public FileDataSourceViaHeapImpl(FileChannel fc)
-
FileDataSourceViaHeapImpl
public FileDataSourceViaHeapImpl(FileChannel fc, String filename)
-
-
Method Detail
-
read
public int read(ByteBuffer byteBuffer) throws IOException
Description copied from interface:DataSourceReads 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.- Specified by:
readin interfaceDataSource- Parameters:
byteBuffer- sink for this read operation- Returns:
- number of bytes actually read
- Throws:
IOException- If some I/O error occurs
-
size
public long size() throws IOExceptionDescription copied from interface:DataSourceReturns the current size of this DataSource.- Specified by:
sizein interfaceDataSource- Returns:
- The current size of this DataSource, measured in bytes
- Throws:
IOException- If some I/O error occurs
-
position
public long position() throws IOExceptionDescription copied from interface:DataSourceReturns the DataSource's current position.- Specified by:
positionin interfaceDataSource- 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
public void position(long nuPos) throws IOExceptionDescription copied from interface:DataSourceSets the DataSource's position.- Specified by:
positionin interfaceDataSource- 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
public long transferTo(long startPosition, long count, WritableByteChannel sink) throws IOExceptionDescription copied from interface:DataSourceTransfers 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;- Specified by:
transferToin interfaceDataSource- Parameters:
startPosition- 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-negativesink- The target channel- Returns:
- the actual number of bytes written
- Throws:
IOException- If some I/O error occurs
-
map
public ByteBuffer map(long startPosition, long size) throws IOException
Description copied from interface:DataSourceMaps 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.- Specified by:
mapin interfaceDataSource- 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
public void close() throws IOExceptionDescription copied from interface:DataSourceTries to free all resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDataSource- Throws:
IOException- If some I/O error occurs
-
-