Class AVPKitIO
- java.lang.Object
-
- com.avpkit.core.io.AVPKitIO
-
- All Implemented Interfaces:
IURLProtocolHandlerFactory
public class AVPKitIO extends java.lang.Object implements IURLProtocolHandlerFactory
Allows AVPKit to read from and write to many different types of Java I/O objects, plus customIURLProtocolHandlerobjects.Most of the time, IContainer hides this away from you, but in case you're interested, here's the underlying class doing the IO magic.
To use for reading (assuming an InputStream object called inputStream):IContainer container = IContainer.make(); container.open(inputStream, null);
or for writing:
IContainer container = IContainer.make(); container.open(outputStream, null);
Really. That's it.
All streams that are mapped in this factory share the same name space, even if registered under different protocols. So, if "exampleone" and "exampletwo" were both registered as protocols for this factory, then "exampleone:filename" is the same as "exampletwo:filename" and will map to the same input and output streams. In reality, they are all mapped to the
DEFAULT_PROTOCOLprotocol.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_PROTOCOLThe default protocol string that this factory uses ( "avpkit").
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgenerateUniqueName(java.lang.Object src)Generates a unique name suitable for using in the map methods for the URL parameter.static java.lang.StringgenerateUniqueName(java.lang.Object src, java.lang.String extension)Generates a unique name suitable for using in the map methods for the URL parameter.static AVPKitIOgetFactory()Get the singleton factory object for this class.IURLProtocolHandlergetHandler(java.lang.String url, int flags)Called by FFMPEG in order to get a handler to use for a given file.static java.lang.Stringmap(IURLProtocolHandler handler)Maps aIURLProtocolHandlerto a url that AVPKit can open.static java.lang.Stringmap(java.io.DataInput input)Maps aDataInputobject to a URL for use by AVPKit.static java.lang.Stringmap(java.io.DataOutput output)Maps aDataOutputobject to a URL for use by AVPKit.static java.lang.Stringmap(java.io.InputStream in)Maps anInputStreamto a URL for use by AVPKit.static java.lang.Stringmap(java.io.OutputStream out)Maps anOutputStreamto a URL for use by AVPKit.static java.lang.Stringmap(java.io.RandomAccessFile file)Maps aRandomAccessFileobject to a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, IURLProtocolHandler handler)Maps aIURLProtocolHandlerto a url that AVPKit can open.static java.lang.Stringmap(java.lang.String url, IURLProtocolHandler handler, boolean unmapUrlOnOpen)Maps aIURLProtocolHandlerto a url that AVPKit can open.static java.lang.Stringmap(java.lang.String url, java.io.DataInput input)Maps aDataInputobject to a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.DataInput in, java.io.DataOutput out, boolean unmapOnOpen, boolean closeOnClose)Maps aDataInputorDataOutputobject to a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.DataOutput output)Maps aDataOutputobject to a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.InputStream in)Maps anInputStreamto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.InputStream in, java.io.OutputStream out, boolean unmapOnOpen, boolean closeOnClose)Maps anInputStreamorOutputStreamto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.OutputStream out)Maps anOutputStreamto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.io.RandomAccessFile file)Maps aRandomAccessFileobject to a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.nio.channels.ByteChannel channel)Maps aByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.nio.channels.ReadableByteChannel channel)Maps aReadableByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.nio.channels.ReadableByteChannel in, java.nio.channels.WritableByteChannel out, boolean unmapOnOpen, boolean closeOnClose)Maps anReadableByteChannelorWritableByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.lang.String url, java.nio.channels.WritableByteChannel channel)Maps aWritableByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.nio.channels.ByteChannel channel)Maps aByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.nio.channels.ReadableByteChannel channel)Maps aReadableByteChannelto a URL for use by AVPKit.static java.lang.Stringmap(java.nio.channels.WritableByteChannel channel)Maps aWritableByteChannelto a URL for use by AVPKit.IURLProtocolHandlermapIO(java.lang.String url, IURLProtocolHandler handler, boolean unmapUrlOnOpen)Maps the given url or file name to the givenIURLProtocolHandleror so that AVPKit calls to open the URL it will call back to the handler.static IURLProtocolHandlerunmap(java.lang.String url)Undoes a URL toInputStreamorOutputStreammapping.IURLProtocolHandlerunmapIO(java.lang.String url)Unmaps a registration between a URL and the underlying i/o objects.
-
-
-
Field Detail
-
DEFAULT_PROTOCOL
public static final java.lang.String DEFAULT_PROTOCOL
The default protocol string that this factory uses ( "avpkit").- See Also:
- Constant Field Values
-
-
Method Detail
-
getFactory
public static AVPKitIO getFactory()
Get the singleton factory object for this class.- Returns:
- the factory
-
generateUniqueName
public static java.lang.String generateUniqueName(java.lang.Object src)
Generates a unique name suitable for using in the map methods for the URL parameter.- Parameters:
src- The object you want to generate a unique name for, or null if you don't have one.- Returns:
- A unique name (will be unique across time and space).
-
generateUniqueName
public static java.lang.String generateUniqueName(java.lang.Object src, java.lang.String extension)
Generates a unique name suitable for using in the map methods for the URL parameter.- Parameters:
src- The object you want to generate a unique name for, or null if you don't have one.extension- an option extension to append to the generated URL.- Returns:
- A unique name (will be unique across time and space).
-
map
public static java.lang.String map(IURLProtocolHandler handler)
Maps aIURLProtocolHandlerto a url that AVPKit can open.unmap(String)will be called automatically after this URL is opened.- Parameters:
handler- the handler- Returns:
- a string that is suitable for passing to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, IURLProtocolHandler handler)
Maps aIURLProtocolHandlerto a url that AVPKit can open.unmap(String)will be called automatically after this URL is opened.- Parameters:
url- the unique string to use for the mapping.handler- the handler- Returns:
- a string that is suitable for passing to
IContainer's open methods.
-
map
public static java.lang.String map(java.io.DataInput input)
Maps aDataInputobject to a URL for use by AVPKit.- Parameters:
input- theDataInput- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.io.DataInput input)
Maps aDataInputobject to a URL for use by AVPKit.- Parameters:
url- the URL to use.input- theDataInput- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.io.DataOutput output)
Maps aDataOutputobject to a URL for use by AVPKit.- Parameters:
output- theDataOutput- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.io.DataOutput output)
Maps aDataOutputobject to a URL for use by AVPKit.- Parameters:
url- the URL to use.output- theDataOutput- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.io.RandomAccessFile file)
Maps aRandomAccessFileobject to a URL for use by AVPKit.- Parameters:
file- theRandomAccessFile- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.io.RandomAccessFile file)
Maps aRandomAccessFileobject to a URL for use by AVPKit.- Parameters:
url- the URL to use.file- theRandomAccessFile- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.nio.channels.ReadableByteChannel channel)
Maps aReadableByteChannelto a URL for use by AVPKit.- Parameters:
channel- theReadableByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.nio.channels.ReadableByteChannel channel)
Maps aReadableByteChannelto a URL for use by AVPKit.- Parameters:
url- the URL to use.channel- theReadableByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.nio.channels.WritableByteChannel channel)
Maps aWritableByteChannelto a URL for use by AVPKit.- Parameters:
channel- theWritableByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.nio.channels.WritableByteChannel channel)
Maps aWritableByteChannelto a URL for use by AVPKit.- Parameters:
url- the URL to use.channel- theWritableByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.nio.channels.ByteChannel channel)
Maps aByteChannelto a URL for use by AVPKit.- Parameters:
channel- theByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.lang.String url, java.nio.channels.ByteChannel channel)
Maps aByteChannelto a URL for use by AVPKit.- Parameters:
url- the URL to use.channel- theByteChannel- Returns:
- a string that can be passed to
IContainer's open methods.
-
map
public static java.lang.String map(java.io.InputStream in)
Maps anInputStreamto a URL for use by AVPKit.- Parameters:
in- the stream- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, java.io.InputStream in)
Maps anInputStreamto a URL for use by AVPKit.- Parameters:
url- the URL to use.in- the stream- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.io.OutputStream out)
Maps anOutputStreamto a URL for use by AVPKit.- Parameters:
out- the stream- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, java.io.OutputStream out)
Maps anOutputStreamto a URL for use by AVPKit.- Parameters:
url- the URL to use.out- the stream- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, java.io.DataInput in, java.io.DataOutput out, boolean unmapOnOpen, boolean closeOnClose)
Maps aDataInputorDataOutputobject to a URL for use by AVPKit.- Parameters:
url- the urlin- the input to useout- the output to useunmapOnOpen- should we remove the mapping as soon as the resulting handler is opened?closeOnClose- should we callCloseable.close()on the underlying input or output objects whenIURLProtocolHandler.close()is called (if supported by the underlying object)?- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, java.nio.channels.ReadableByteChannel in, java.nio.channels.WritableByteChannel out, boolean unmapOnOpen, boolean closeOnClose)
Maps anReadableByteChannelorWritableByteChannelto a URL for use by AVPKit.- Parameters:
url- the urlin- the input to useout- the output to useunmapOnOpen- should we remove the mapping as soon as the resulting handler is opened?closeOnClose- should we callCloseable.close()on the underlying input or output objects whenIURLProtocolHandler.close()is called (if supported by the underlying object)?- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, java.io.InputStream in, java.io.OutputStream out, boolean unmapOnOpen, boolean closeOnClose)
Maps anInputStreamorOutputStreamto a URL for use by AVPKit.- Parameters:
url- the urlin- the input to useout- the output to useunmapOnOpen- should we remove the mapping as soon as the resulting handler is opened?closeOnClose- should we callCloseable.close()on the underlying input or output objects whenIURLProtocolHandler.close()is called?- Returns:
- Returns a URL that can be passed to AVPKit's
IContainer's open method, and will result in IO being performed on the passed in streams.
-
map
public static java.lang.String map(java.lang.String url, IURLProtocolHandler handler, boolean unmapUrlOnOpen)
Maps aIURLProtocolHandlerto a url that AVPKit can open.- Parameters:
url- the unique string to use for the mapping.handler- the handlerunmapUrlOnOpen- if true, when AVPKit opens theIURLProtocolHandler,unmap(String)will be called automatically.- Returns:
- a string that is suitable for passing to
IContainer's open methods.
-
unmap
public static IURLProtocolHandler unmap(java.lang.String url)
-
mapIO
public IURLProtocolHandler mapIO(java.lang.String url, IURLProtocolHandler handler, boolean unmapUrlOnOpen)
Maps the given url or file name to the givenIURLProtocolHandleror so that AVPKit calls to open the URL it will call back to the handler.If you set unmapOnOpen to false, or you never actually open this mapping, then you must ensure that you call
unmapIO(String)at some point in time to remove the mapping, or we will hold onto references to the handler you passed in.- Parameters:
url- A file or URL. If a URL, the protocol will be stripped off and replaced withDEFAULT_PROTOCOLwhen registering.handler- AnIURLProtocolHandlerfor the urlunmapUrlOnOpen- If true, the handler will unmap itself after anIContaineropens the registered URL. If true, you do not need to callunmapIO(String)for this url.- Returns:
- The previous handler for this url, or null if none.
- Throws:
java.lang.IllegalArgumentException- if url is null or zero lengthjava.lang.IllegalArgumentException- if handler is null
-
unmapIO
public IURLProtocolHandler unmapIO(java.lang.String url)
Unmaps a registration between a URL and the underlying i/o objects.If URL contains a protocol it is ignored when trying to find the matching IO stream.
- Parameters:
url- The stream name to unmap- Returns:
- the
IURLProtocolHandlerthat had been registered for that url, or null if none.
-
getHandler
public IURLProtocolHandler getHandler(java.lang.String url, int flags)
Called by FFMPEG in order to get a handler to use for a given file.- Specified by:
getHandlerin interfaceIURLProtocolHandlerFactory- Parameters:
url- The URL that FFMPEG is trying to open.flags- The flags that FFMPEG will pass toIURLProtocolHandler.open(String, int)- Returns:
- A
IURLProtocolHandlerto use, or null. If null, a file not found error will be passed back to FFMPEG.
-
-