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

Opens a shared file after the user confirmed: the provider's descriptor is held if it can seek (HeldFileSource), otherwise the file is copied to cache/incoming/ and the copy is held (and deleted when the source is closed). More...

Collaboration diagram for de.yaacc.share.SharedFileOpener:
Collaboration graph

Classes

class  Opened
 The first step: what the provider handed out.
 
class  OpenException
 The file cannot be shared; getReason() says why.
 
enum  Reason
 Why a file could not be opened. More...
 

Static Public Member Functions

static Opened openDescriptor (ContentResolver resolver, Uri uri) throws OpenException
 Opens the provider's descriptor and holds it if it can seek.
 
static PositionalSource copyAndHold (AssetFileDescriptor afd, File incomingDir) throws OpenException
 The copy fallback: copies the provider's descriptor to cache/incoming/ (byte cap, free space reserve, directory cap, one copy at a time) and holds the copy; the returned source deletes the copy when it is closed.
 

Detailed Description

Opens a shared file after the user confirmed: the provider's descriptor is held if it can seek (HeldFileSource), otherwise the file is copied to cache/incoming/ and the copy is held (and deleted when the source is closed).

Thin glue: the rules (what to copy, how much, how to stop) live in the plain-Java classes it calls.

Worker thread only: every call goes to the provider. The caller owns the returned source and must close it; this class closes and deletes everything it opened itself when it fails. Nothing here logs the URI, the name or the provider's text.

Member Function Documentation

◆ copyAndHold()

static PositionalSource de.yaacc.share.SharedFileOpener.copyAndHold ( AssetFileDescriptor afd,
File incomingDir ) throws OpenException
static

The copy fallback: copies the provider's descriptor to cache/incoming/ (byte cap, free space reserve, directory cap, one copy at a time) and holds the copy; the returned source deletes the copy when it is closed.

Closes afd in every case and deletes a partial copy on every failure.

Takes as long as the copy takes, off the main thread, but at most ShareLimits#COPY_MAX_MILLIS: the copy runs on its own worker and this call waits with a deadline (WatchedCopy), because a provider whose pipe never delivers a byte would block the read for ever. At the deadline the descriptor is closed from this thread (which wakes the blocked read), the partial file is deleted, the copy slot is given back and the call fails, even if the worker stays stuck.

Exceptions
OpenExceptionfor every failure
Here is the call graph for this function:

◆ openDescriptor()

static Opened de.yaacc.share.SharedFileOpener.openDescriptor ( ContentResolver resolver,
Uri uri ) throws OpenException
static

Opens the provider's descriptor and holds it if it can seek.

A provider call that can block: run it through BoundedCall, never on the main thread.

Parameters
resolverthe content resolver
urithe validated shared URI
Exceptions
OpenExceptionfor every failure (nothing is left open)
Here is the call graph for this function:

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