public abstract class SObject extends Object implements ISObject
The implementation of ISObject
| Modifier and Type | Class and Description |
|---|---|
static class |
SObject.ByteArraySObject |
static class |
SObject.FileSObject |
static class |
SObject.InputStreamSObject |
static class |
SObject.LazyLoadSObject |
static class |
SObject.StringSObject |
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
accessDenied |
protected RuntimeException |
cause |
protected boolean |
exists |
ATTR_CONTENT_LENGTH, ATTR_CONTENT_TYPE, ATTR_FILE_NAME, ATTR_SS_CTX, ATTR_SS_ID, ATTR_URL, VERSION| Modifier and Type | Method and Description |
|---|---|
static SObject |
accessDeniedObject(String key,
Throwable cause) |
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() |
static SObject |
invalidObject(String key,
Throwable cause) |
boolean |
isAccessDenied()
Is access to the resource represented by this sobject denied.
|
boolean |
isBinary()
Probe if the storage object is binary or text
|
boolean |
isDumb()
Returns
true if this SObject is dumb |
boolean |
isEmpty()
Is content is empty
|
boolean |
isExists()
Is the resource exists.
|
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 |
notFoundObject(String key,
Throwable cause) |
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, …
|
static SObject |
of(URL url)
Construct an sobject with specified URL.
|
protected boolean |
probeBinary() |
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) |
protected void |
setCause(Throwable cause) |
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, waitasByteArray, asFile, asInputStream, asString, asString, getLengthprotected boolean exists
protected boolean accessDenied
protected RuntimeException cause
public SObject(String key)
public boolean isDumb()
ISObjectReturns true if this SObject is dumb
public String getKey()
protected void setCause(Throwable cause)
public String getUrl()
ISObjectReturns 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()
ISObjectReturns filename attribute
getFilename in interface ISObjectpublic String getContentType()
ISObjectReturn content type attribute
getContentType in interface ISObjectpublic void setFilename(String filename)
ISObjectSet filename attribute
setFilename in interface ISObjectfilename - the filename to be setpublic void setContentType(String contentType)
ISObjectSet content type attribute
setContentType in interface ISObjectcontentType - the content type to be setpublic String getAttribute(String key)
ISObjectReturn attribute associated with this storage object by key. If there is no such attribute found then null is returned
getAttribute in interface ISObjectnull if not foundpublic ISObject setAttribute(String key, String val)
ISObjectSet an attribute to the storage object associated by key specified.
setAttribute in interface ISObjectkey - attribute keyval - attribute valuepublic ISObject setAttributes(Map<String,String> attrs)
ISObjectSet attributes to the storage object
setAttributes in interface ISObjectpublic boolean hasAttribute()
hasAttribute in interface ISObjecttrue if the storage object has attributespublic Map<String,String> getAttributes()
getAttributes in interface ISObjectpublic boolean isEmpty()
ISObjectIs content is empty
public boolean isExists()
ISObjectIs the resource exists.
Note if this method returns true then ISObject.isValid() must return false.
public boolean isValid()
ISObjectIs this storage object valid. A storage object is not valid if the file/input stream is not readable
public boolean isAccessDenied()
ISObjectIs access to the resource represented by this sobject denied.
Note if this method returns true then false`ISObject.isValid() must
return
isAccessDenied in interface ISObjecttrue if access to the resource back this sobject denied, false otherwise.public Throwable getException()
ISObjectReturn previous exception that cause the sobject invalid
getException in interface ISObjectpublic void consumeOnce(Lang.Function<InputStream,?> consumer)
ISObjectConsume the inputstream of this storage object one time and then close the input stream
consumeOnce in interface ISObjectconsumer - the consumer functionpublic boolean isBinary()
ISObjectProbe if the storage object is binary or text
protected boolean probeBinary()
protected 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 of(URL url)
Construct an sobject with specified URL.
url - 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–2021 OSGL (Open Source General Library). All rights reserved.