public abstract class SObject extends Object implements ISObject
The implementation of ISObject
Modifier and Type | Field and Description |
---|---|
protected Throwable |
cause |
protected boolean |
valid |
ATTR_CONTENT_LENGTH, ATTR_CONTENT_TYPE, ATTR_FILE_NAME, ATTR_SS_CTX, ATTR_SS_ID, ATTR_URL, VERSION
Modifier and Type | Method and Description |
---|---|
void |
consumeOnce(Lang.Function<InputStream,?> consumer)
Consume the inputstream of this storage object one time and then close the input stream
|
String |
getAttribute(String key)
Return attribute associated with this storage object by key.
|
Map<String,String> |
getAttributes() |
String |
getContentType()
Return
content type attribute |
Throwable |
getException()
Return previous exception that cause the sobject invalid
|
String |
getFilename()
Returns
filename attribute |
static SObject |
getInvalidObject(String key,
Throwable cause) |
String |
getKey() |
String |
getUrl()
Returns URL set to this SObject.
|
boolean |
hasAttribute() |
boolean |
isDumb()
Returns
true if this SObject is dumb |
boolean |
isEmpty()
Is content is empty
|
boolean |
isValid()
Is this storage object valid.
|
static SObject |
lazyLoad(String key,
IStorageService ss) |
static SObject |
lazyLoad(String key,
IStorageService ss,
Map<String,String> conf) |
static SObject |
lazyLoad(String key,
IStorageService ss,
String... attrs) |
static SObject |
loadResource(String url)
Load an sobject from classpath by given url path
|
static SObject |
of(byte[] buf)
Construct an sobject with content in byte array and a random generated key
|
static SObject |
of(byte[] buf,
int len)
Construct an SObject with random generated key, byte array and number of bytes
|
static SObject |
of(File file)
Construct an SObject with file specified.
|
static SObject |
of(InputStream is)
Construct an sobject with specified input stream and a randomly generated key.
|
static SObject |
of(String content)
Construct an sobject with specified content in String and a randomly generated key
|
static SObject |
of(String key,
byte[] buf)
Construct an sobject with specified key and byte array.
|
static SObject |
of(String key,
byte[] buf,
int len)
Construct an SObject with specified key, byte array and number of bytes
|
static SObject |
of(String key,
byte[] buf,
Map<String,String> attrs)
Construct an sobject with specified key, content as byte array and attributes in
Map |
static SObject |
of(String key,
byte[] buf,
String... attrs)
Construct an sobject with specified key, content in byte array and attributes in sequence of key1, val1, key1, val2, …
|
static SObject |
of(String key,
File file)
Construct an SObject with key and file specified
|
static SObject |
of(String key,
File file,
Map<String,String> attributes)
Construct an SObject with specified key, file and attributes specified in
Map |
static SObject |
of(String key,
File file,
String... attrs)
Construct an SObject with key, file and attributes specified in key1, val1, key2, val2… sequence
|
static SObject |
of(String key,
InputStream is)
Construct an SObject with key and input stream.
|
static SObject |
of(String key,
InputStream is,
Map<String,String> conf)
Construct a sobject with key, input stream and attributes specified in a
Map . |
static SObject |
of(String key,
InputStream is,
String... attrs)
Construct a sobject with key, input stream and attributes specified in a sequence like key1, val1, key2, val2, …
|
static SObject |
of(String key,
String content)
Construct an sobject with content and key specified
|
static SObject |
of(String key,
String content,
Map<String,String> attrs)
Construct an sobject with content, key and attributes specified in
Map |
static SObject |
of(String key,
String content,
String... attrs)
Construct an sobject with key, content and attributes specified in sequence key1, val1, key2, val2, …
|
ISObject |
setAttribute(String key,
String val)
Set an attribute to the storage object associated by key specified.
|
ISObject |
setAttributes(Map<String,String> attrs)
Set attributes to the storage object
|
protected void |
setAttrs(Map<String,String> attrs) |
void |
setContentType(String contentType)
Set
content type attribute |
void |
setFilename(String filename)
Set
filename attribute |
protected String |
suffix() |
static SObject |
valueOf(String key,
byte[] buf)
Deprecated.
|
static SObject |
valueOf(String key,
byte[] buf,
Map<String,String> attrs)
Deprecated.
|
static SObject |
valueOf(String key,
byte[] buf,
String... attrs)
Deprecated.
|
static SObject |
valueOf(String key,
File f)
Deprecated.
|
static SObject |
valueOf(String key,
File file,
Map<String,String> conf)
Deprecated.
|
static SObject |
valueOf(String key,
File file,
String... attrs)
Deprecated.
|
static SObject |
valueOf(String key,
InputStream is)
Deprecated.
|
static SObject |
valueOf(String key,
InputStream is,
Map<String,String> conf)
Deprecated.
|
static SObject |
valueOf(String key,
InputStream is,
String... attrs)
Deprecated.
|
static SObject |
valueOf(String key,
ISObject copy) |
static SObject |
valueOf(String key,
String content)
Deprecated.
|
static SObject |
valueOf(String key,
String content,
Map<String,String> attrs)
Deprecated.
|
static SObject |
valueOf(String key,
String content,
String... attrs)
Deprecated.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asByteArray, asFile, asInputStream, asString, asString, getLength
protected boolean valid
protected Throwable cause
public boolean isDumb()
ISObject
Returns true
if this SObject is dumb
public String getUrl()
ISObject
Returns URL set to this SObject.
Calling to this method shall have the same result as
calling ISObject.getAttribute(String)
using
ISObject.ATTR_URL
:
String url = sobj.getAttribute(ISObject.ATTR_URL);
public String getFilename()
ISObject
Returns filename
attribute
getFilename
in interface ISObject
public String getContentType()
ISObject
Return content type
attribute
getContentType
in interface ISObject
public void setFilename(String filename)
ISObject
Set filename
attribute
setFilename
in interface ISObject
filename
- the filename to be setpublic void setContentType(String contentType)
ISObject
Set content type
attribute
setContentType
in interface ISObject
contentType
- the content type to be setpublic String getAttribute(String key)
ISObject
Return attribute associated with this storage object by key. If there is no such attribute found then null
is returned
getAttribute
in interface ISObject
null
if not foundpublic ISObject setAttribute(String key, String val)
ISObject
Set an attribute to the storage object associated by key specified.
setAttribute
in interface ISObject
key
- attribute keyval
- attribute valuepublic ISObject setAttributes(Map<String,String> attrs)
ISObject
Set attributes to the storage object
setAttributes
in interface ISObject
public boolean hasAttribute()
hasAttribute
in interface ISObject
true
if the storage object has attributespublic Map<String,String> getAttributes()
getAttributes
in interface ISObject
public boolean isEmpty()
ISObject
Is content is empty
public boolean isValid()
ISObject
Is this storage object valid. A storage object is not valid if the file/input stream is not readable
public Throwable getException()
ISObject
Return previous exception that cause the sobject invalid
getException
in interface ISObject
public void consumeOnce(Lang.Function<InputStream,?> consumer)
ISObject
Consume the inputstream of this storage object one time and then close the input stream
consumeOnce
in interface ISObject
consumer
- the consumer functionprotected final String suffix()
public static SObject of(File file)
Construct an SObject with file specified. The key to the sobject is the file’s path
file
- the filepublic static SObject of(String key, File file)
Construct an SObject with key and file specified
of(String, File, Map)
@Deprecated public static SObject valueOf(String key, File f)
Deprecated
of(String, File)
public static SObject of(String key, File file, Map<String,String> attributes)
Construct an SObject with specified key, file and attributes specified in Map
of(String, File, String...)
@Deprecated public static SObject valueOf(String key, File file, Map<String,String> conf)
of(String, File, Map)
public static SObject of(String key, File file, String... attrs)
Construct an SObject with key, file and attributes specified in key1, val1, key2, val2… sequence
of(String, File, Map)
@Deprecated public static SObject valueOf(String key, File file, String... attrs)
Deprecated
of(String, File, String...)
public static SObject of(InputStream is)
Construct an sobject with specified input stream and a randomly generated key.
Node the sobject constrcuted from input stream has limits please see the comment to of(String, InputStream)
of(String, InputStream)
public static SObject loadResource(String url)
Load an sobject from classpath by given url path
This method will call Class.getResource(String)
method to open an inputstream to the resource and then construct an SObject with the inputstream
url
- the resource url pathnull
if cannot load resource from the urlpublic static SObject of(String key, InputStream is)
Construct an SObject with key and input stream. Note unlike sobject constructed with String, byte array or file, the sobject constructed with input stream can only be read for one time. If the program tries to access the Sobject the second time, it will encountered an UnexpectedIOException
. Another limit of this sobject is it does not support ISObject.getLength()
method
If it needs to construct an SObject without these limits from an input stream, then it shall first read the inputstream into a bytearray, and use the byte array to construct the sobject like following code
InputStream is = … … ISObject sobj = SObject.of(IO.readContent(is))
@Deprecated public static SObject valueOf(String key, InputStream is)
deprecated
of(String, InputStream)
public static SObject of(String key, InputStream is, Map<String,String> conf)
Construct a sobject with key, input stream and attributes specified in a Map
.
Node the sobject constrcuted from input stream has limits please see the comment to of(String, InputStream)
of(String, InputStream)
@Deprecated public static SObject valueOf(String key, InputStream is, Map<String,String> conf)
deprecated
of(String, InputStream, Map)
public static SObject of(String key, InputStream is, String... attrs)
Construct a sobject with key, input stream and attributes specified in a sequence like key1, val1, key2, val2, …
Node the sobject constrcuted from input stream has limits please see the comment to of(String, InputStream)
of(String, InputStream)
@Deprecated public static SObject valueOf(String key, InputStream is, String... attrs)
deprecated
of(String, File, String...)
public static SObject of(String content)
Construct an sobject with specified content in String and a randomly generated key
of(String, String)
public static SObject of(String key, String content)
Construct an sobject with content and key specified
of(String, String, Map)
@Deprecated public static SObject valueOf(String key, String content)
Deprecated
of(String, String)
public static SObject of(String key, String content, Map<String,String> attrs)
Construct an sobject with content, key and attributes specified in Map
@Deprecated public static SObject valueOf(String key, String content, Map<String,String> attrs)
Deprecated
of(String, String, Map)
public static SObject of(String key, String content, String... attrs)
Construct an sobject with key, content and attributes specified in sequence key1, val1, key2, val2, …
of(String, String, Map)
@Deprecated public static SObject valueOf(String key, String content, String... attrs)
Deprecated
of(String, String, String...)
public static SObject of(byte[] buf)
Construct an sobject with content in byte array and a random generated key
of(String, byte[])
public static SObject of(String key, byte[] buf)
Construct an sobject with specified key and byte array.
Note the byte array will be used directly without copying into an new array.
of(String, byte[], Map)
public static SObject of(byte[] buf, int len)
Construct an SObject with random generated key, byte array and number of bytes
buf
- the source byte arraylen
- the number of bytes in the array should be stored in the returing objectpublic static SObject of(String key, byte[] buf, int len)
Construct an SObject with specified key, byte array and number of bytes
key
- the keybuf
- the source byte arraylen
- the number of bytes in the array should be stored in the returing object@Deprecated public static SObject valueOf(String key, byte[] buf)
Deprecated
of(String, byte[])
public static SObject of(String key, byte[] buf, Map<String,String> attrs)
Construct an sobject with specified key, content as byte array and attributes in Map
of(String, byte[], String...)
@Deprecated public static SObject valueOf(String key, byte[] buf, Map<String,String> attrs)
Deprecated
of(String, byte[], Map)
public static SObject of(String key, byte[] buf, String... attrs)
Construct an sobject with specified key, content in byte array and attributes in sequence of key1, val1, key1, val2, …
of(String, byte[], Map)
@Deprecated public static SObject valueOf(String key, byte[] buf, String... attrs)
Deprecated
of(String, byte[], String...)
public static SObject lazyLoad(String key, IStorageService ss)
public static SObject lazyLoad(String key, IStorageService ss, String... attrs)
Copyright © 2014–2018 OSGL (Open Source General Library). All rights reserved.