@LcdService(service=ILcdInputStreamFactory.class, priority=20000) public class TLcdInputStreamFactory extends Object implements ILcdInputStreamFactory
Source names ending in .zip or .gz are unzipped automatically.
The defaultAllowUserInteraction flag and the defaultUseCaches flag are passed on to any URL connection.
The passwordProvider can be set for URLs that require a password.
The returned streams are automatically wrapped with a buffered input stream, to avoid a performance penalty.
This InputStreamFactory asks by default the data over HTTP to be compressed.
If the server does not allow it, it falls back on non-compressed data.
This behaviour can be changed using setAcceptCompressedEncoding(boolean)
or by setting the com.luciad.io.TLcdInputStreamFactory.acceptHttpCompressedEncoding
system property to the desired behaviour.
Constructor and Description |
---|
TLcdInputStreamFactory()
Creates a new TLcdInputStreamFactory.
|
TLcdInputStreamFactory(int aBufferSize)
Creates a new TLcdInputStreamFactory that creates input streams with the given buffer size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canCreateInputStream(String aSource)
Checks whether this input stream factory can provide access to
aSource . |
InputStream |
createInputStream(String aSourceName)
Creates an input stream from the given source name.
|
int |
getBufferSize() |
int |
getConnectTimeout()
Returns the connect timeout value, or zero if the option is disabled
(that is, a timeout of infinity).
|
boolean |
getDefaultAllowUserInteraction()
Indicates whether user interaction is allowed.
|
String |
getDefaultRequestProperty(String aKey)
Returns the request property value for the given key.
|
boolean |
getDefaultUseCaches()
Indicates whether default caching is turned on.
|
static boolean |
getMayUseNIO()
Returns whether the Java NIO package may be used to read data from files.
|
ILcdPasswordProvider |
getPasswordProvider()
Returns the password provider for HTTP connections that need a password.
|
int |
getReadTimeout()
Returns setting for read timeout, or zero if the timeout option is disabled (that is, a timeout of infinity).
|
boolean |
getUnzipAutomatically()
Returns whether source names ending with .zip are unzipped automatically.
|
boolean |
getUseNIO()
Returns whether the Java NIO package will be used to read data from files.
|
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
static void |
setAcceptCompressedEncoding(boolean acceptCompressedEncoding)
Sets the behaviour of all
TLcdInputStreamFactory instances regarding the request of compressed content. |
void |
setBufferSize(int aBufferSize)
Sets the buffer size of input streams created by this factory.
|
static void |
setClassTraceOn(boolean aClassTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setConnectTimeout(int aConnectTimeout)
Sets a specified timeout value, in milliseconds, to be used
when opening a URLConnection.
|
void |
setDefaultAllowUserInteraction(boolean aDefaultAllowUserInteraction)
Sets whether user interaction is allowed (used in URL connections).
|
void |
setDefaultRequestProperty(String aKey,
String aValue)
Sets a default request property for connecting (used in URL connections).
|
void |
setDefaultUseCaches(boolean aDefaultUseCaches)
Sets whether to use default caching on connecting (used in URL connections).
|
static void |
setMayUseNIO(boolean aMayUseNIO)
Sets globally whether the Java NIO package may be used to read data
from files.
|
void |
setPasswordProvider(ILcdPasswordProvider aPasswordProvider)
Sets the password provider for HTTP connections that need a password.
|
void |
setReadTimeout(int aReadTimeout)
Sets the read timeout to the given value in milliseconds.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setUnzipAutomatically(boolean aUnzipAutomatically)
Sets whether to unzip source names ending with .zip automatically,
returning the contents of the first entry in the zip archive.
|
void |
setUseNIO(boolean aUseNIO)
Sets whether to use the Java NIO package to read data from files.
|
public TLcdInputStreamFactory()
public TLcdInputStreamFactory(int aBufferSize)
aBufferSize
- The size of the buffer in bytes.public static void setMayUseNIO(boolean aMayUseNIO)
true
. You may want to set this
to false
if the NIO code is blocking the modification or
removal of your files in Windows, for instance.aMayUseNIO
- specifies whether or not the Java NIO package may be used.setUseNIO(boolean)
public static boolean getMayUseNIO()
setUseNIO(boolean)
public static void setClassTraceOn(boolean aClassTraceOn)
true
then all log messages are recorded, otherwise only
the informative, warning and error messages are recorded.aClassTraceOn
- if true then all log messages are recorded,
otherwise only the informative, warning and error messages are recorded.public static void setAcceptCompressedEncoding(boolean acceptCompressedEncoding)
TLcdInputStreamFactory
instances regarding the request of compressed content.
This is achieved using (or not) the "Accept-Encoding" field in the request's header.acceptCompressedEncoding
- the new boolean value. True if TLcdInputStreamFactory should ask for compressed data (i.e. gzip, deflate, compress)public void setTraceOn(boolean aTraceOn)
true
or false
as argument automatically turns
off tracing for all other class instances for which
setTraceOn
has not been called.
If the argument is false
then only the informative, warning
and error log messages are recorded.aTraceOn
- if true then all log messages are recorded for this
instance. If false, then only the informative, warning and
error log messages are recorded.public boolean isTraceOn()
public void setDefaultAllowUserInteraction(boolean aDefaultAllowUserInteraction)
true
.aDefaultAllowUserInteraction
- true to allow user interaction when creating a connection.getDefaultAllowUserInteraction()
public boolean getDefaultAllowUserInteraction()
setDefaultAllowUserInteraction(boolean)
public void setDefaultUseCaches(boolean aDefaultUseCaches)
true
.aDefaultUseCaches
- true to use default caching on connecting.getDefaultUseCaches()
public boolean getDefaultUseCaches()
setDefaultUseCaches(boolean)
public void setDefaultRequestProperty(String aKey, String aValue)
aKey
- the request property key.aValue
- the request property value.getDefaultRequestProperty(String)
public String getDefaultRequestProperty(String aKey)
aKey
- the request property key.setDefaultRequestProperty(String, String)
public void setUseNIO(boolean aUseNIO)
false
.aUseNIO
- specifies whether or not to use the Java NIO package.getUseNIO()
,
setMayUseNIO(boolean)
public boolean getUseNIO()
setUseNIO(boolean)
public void setUnzipAutomatically(boolean aUnzipAutomatically)
true
.aUnzipAutomatically
- true
if source names ending
with .zip must be unzipped automatically,
false
otherwise.getUnzipAutomatically()
public boolean getUnzipAutomatically()
true
if source names ending with .zip are unzipped
automatically, false
otherwise.setUnzipAutomatically(boolean)
public void setPasswordProvider(ILcdPasswordProvider aPasswordProvider)
aPasswordProvider
- the password provider for HTTP connections that need a password.getPasswordProvider()
public ILcdPasswordProvider getPasswordProvider()
setPasswordProvider(com.luciad.util.ILcdPasswordProvider)
public int getBufferSize()
public void setBufferSize(int aBufferSize)
aBufferSize
- the buffer size. Must be larger than 0.public void setConnectTimeout(int aConnectTimeout)
aConnectTimeout
- the timeout value in millisecondsIllegalArgumentException
- if the timeout parameter is negativegetConnectTimeout()
,
URLConnection.setConnectTimeout(int)
public int getConnectTimeout()
setConnectTimeout(int)
,
(int)
public void setReadTimeout(int aReadTimeout)
aReadTimeout
- the timeout value in millisecondsIllegalArgumentException
- if the timeout parameter is negativegetReadTimeout()
,
URLConnection.setReadTimeout(int)
public int getReadTimeout()
setReadTimeout(int)
,
URLConnection.getReadTimeout()
public boolean canCreateInputStream(String aSource)
aSource
. It is acceptable for this method to
return true
for a source while createInputStream
throws an exception for that same source.
For performance reasons, we strongly recommend that implementations perform only a simple test.
For example: check the structure of aSource
to see if it is a URI with a specific scheme, but do not verify
that aSource
really is accessible.
The default implementation of this method returns true
.
Make sure to override this method if you can easily reject sources. This can help avoid pointless invocations of
createInputStream
which would have to throw exceptions for unsupported sources.
The implementation in TLcdInputStreamFactory
requires aSource
to be non-empty and, if it
appears to have a URL scheme, it must be possible to create a URL
from it.
canCreateInputStream
in interface ILcdInputStreamFactory
aSource
- the data source to be verified; typically a file name or a URL.true
if this input stream factory can likely access the source, false
otherwise.ILcdInputStreamFactory.createInputStream(String)
public InputStream createInputStream(String aSourceName) throws IOException
createInputStream
in interface ILcdInputStreamFactory
aSourceName
- the source from which data can be read.IOException
- when accessing the location with the given source name failed.ILcdInputStreamFactory.canCreateInputStream(String)