YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.share.HeldFileSource Class Reference

A file of another app that is kept readable by holding its descriptor open. More...

Inheritance diagram for de.yaacc.share.HeldFileSource:
Inheritance graph
Collaboration diagram for de.yaacc.share.HeldFileSource:
Collaboration graph

Classes

class  NotSeekableException
 The descriptor does not support positional reads (pipe, socket, device, not a regular file).
 

Static Public Member Functions

static boolean isSeekable (FileDescriptor fd)
 Whether positional reads work on the descriptor: a regular file (fstat) on which lseek(SEEK_CUR) succeeds (it fails with ESPIPE for pipes and sockets).
 
static HeldFileSource open (AssetFileDescriptor afd) throws IOException
 Holds the file behind the provider's descriptor.
 

Protected Member Functions

int readAtInternal (long position, byte[] buf, int off, int len) throws IOException
 Reads from the backend.
 
void closeInternal ()
 Closes the backend.
 
- Protected Member Functions inherited from de.yaacc.share.PositionalSource
 PositionalSource (long size)
 

Additional Inherited Members

- Public Member Functions inherited from de.yaacc.share.PositionalSource
final long size ()
 
final int readAt (long position, byte[] buf, int off, int len) throws IOException
 Reads up to len bytes starting at position.
 
final boolean isClosing ()
 
final void close ()
 Refuses new reads and closes the backend: now if nothing is reading, else when the last running read ends.
 

Detailed Description

A file of another app that is kept readable by holding its descriptor open.

The registry (as an AutoCloseable target of a LOCAL_FILE entry) closes it; closing never blocks and never happens while a read runs (PositionalSource).

Reads use Os#pread, which does not touch the file offset, so any number of responses read different ranges of the one descriptor. The held descriptor is a dup of the provider's one, and the provider's is closed, so the provider process is not pinned by a stable reference. The start offset and length the provider declares are clamped to the real file size (clampLength).

Member Function Documentation

◆ closeInternal()

void de.yaacc.share.HeldFileSource.closeInternal ( )
protected

Closes the backend.

Called exactly once, never while a read is running, possibly on a reader's thread. Should not throw; an exception is swallowed.

Reimplemented from de.yaacc.share.PositionalSource.

◆ isSeekable()

static boolean de.yaacc.share.HeldFileSource.isSeekable ( FileDescriptor fd)
static

Whether positional reads work on the descriptor: a regular file (fstat) on which lseek(SEEK_CUR) succeeds (it fails with ESPIPE for pipes and sockets).

Cheap and does not change the descriptor.

Returns
false for anything else, also when the check itself fails

Referenced by de.yaacc.share.HeldFileSource.open().

Here is the caller graph for this function:

◆ open()

static HeldFileSource de.yaacc.share.HeldFileSource.open ( AssetFileDescriptor afd) throws IOException
static

Holds the file behind the provider's descriptor.

On success this method has duplicated the descriptor and closed afd, so the caller must not use or close it any more. On any failure afd is left open, untouched and still owned by the caller (who may then fall back to copying from it, and closes it).

Do not call on the main thread: fstat on a provider descriptor can block.

Exceptions
NotSeekableExceptionif the descriptor cannot be read positionally
IOExceptionif the descriptor is unusable (empty window, offset beyond the end, dup failed)

Referenced by de.yaacc.share.SharedFileOpener.openDescriptor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAtInternal()

int de.yaacc.share.HeldFileSource.readAtInternal ( long position,
byte[] buf,
int off,
int len ) throws IOException
protected

Reads from the backend.

Called with 0 <= position < size(), len > 0 and a valid buffer range; possibly from several threads at once; never after the backend was closed. May return fewer bytes than asked. Returns -1 (or 0) if the backend has no more data at that position.

Reimplemented from de.yaacc.share.PositionalSource.


The documentation for this class was generated from the following file: