public final class ByteArrayLocator extends AbstractStreamLocator
A specialized Locator
implementation that provides access to data
stored in memory as a byte array.
This locator can be initialized either with a byte array or with a string. This data is kept in memory. The locator returns a stream or an URL providing access to exactly this data.
This class is especially useful for providing access to small amounts of data to clients that can deal with locators. It can also be of value for unit tests supporting an easy way of defining test data.
Instances are created using one of the static getInstance()
factory methods. This class is thread-safe and can be used concurrently by
multiple threads. Each invocation of getInputStream()
returns a
new stream instance initialized with the data of this locator.
Modifier and Type | Method and Description |
---|---|
protected URL |
createURL(URLStreamHandler streamHandler)
Creates a URL representing the data of this locator.
|
boolean |
equals(Object obj)
Compares this object with another one.
|
InputStream |
getInputStream()
Returns an input stream for the data of this locator.
|
static ByteArrayLocator |
getInstance(byte[] data)
Creates an instance of
ByteArrayLocator that is initialized
with the specified data. |
static ByteArrayLocator |
getInstance(String data)
Creates an instance of
ByteArrayLocator that is initialized
with the data of the specified string. |
int |
hashCode()
Returns a hash code for this object.
|
String |
toString()
Returns a string representation for this object.
|
getURL
getFile
public static ByteArrayLocator getInstance(byte[] data)
ByteArrayLocator
that is initialized
with the specified data.data
- the data for the locator (must not be null)IllegalArgumentException
- if the data is nullpublic static ByteArrayLocator getInstance(String data)
ByteArrayLocator
that is initialized
with the data of the specified string.data
- the data for the locator (must not be null)IllegalArgumentException
- if the data is nullpublic InputStream getInputStream() throws IOException
getInputStream
in interface Locator
getInputStream
in class AbstractLocator
IOException
- if an error occurspublic boolean equals(Object obj)
public int hashCode()
public String toString()
protected URL createURL(URLStreamHandler streamHandler) throws MalformedURLException
createURL
in class AbstractStreamLocator
streamHandler
- the stream handler to use for this URLMalformedURLException
- if the URL cannot be createdCopyright © 2016 The JGUIraffe Team. All rights reserved.