|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mycore.datamodel.ifs2.MCRContent
public class MCRContent
Used to read/write content from any source to any target. Sources and targets can be strings, local files, Apache VFS file objects, XML documents, byte[] arrays and streams. MCRContent can only be consumed once, otherwise the getters throw MCRUsageException. Use makeCopies() to avoid this. The underlying input stream is closed after consumption, excepted you use getInputStream(), of course.
| Field Summary | |
|---|---|
protected boolean |
consumed
If true, this content already was used and cannot be used again |
protected InputStream |
in
The content itself |
protected boolean |
isXML
If true, we are absolutely sure that source is XML |
| Method Summary | |
|---|---|
byte[] |
asByteArray()
Returns the raw content |
String |
asString()
Returns content as String, assuming UTF-8 encoding |
String |
asString(String encoding)
Returns the content as String, assuming the provided encoding |
Document |
asXML()
Parses content, assuming it is XML, and returns the parsed document. |
protected void |
checkConsumed()
Ensures that this content is not already consumed, because it can only be used once. |
MCRContent |
ensureXML()
Ensures that content is XML |
MCRContentInputStream |
getContentInputStream()
Returns content as content input stream, which provides MD5 functionality. |
InputStream |
getInputStream()
Returns content as input stream. |
MCRContent[] |
makeCopies(int numCopies)
Makes copies of the content, consuming this content |
static MCRContent |
readFrom(byte[] bytes)
Creates content from byte[] arrray |
static MCRContent |
readFrom(Document xml)
Creates content from XML document. |
static MCRContent |
readFrom(File file)
Creates content from a local file |
static MCRContent |
readFrom(org.apache.commons.vfs.FileObject fo)
Creates content from Apache VFS file object |
static MCRContent |
readFrom(InputStream in)
Creates new content from input stream |
static MCRContent |
readFrom(String text)
Creates content from a String, using UTF-8 encoding |
static MCRContent |
readFrom(String text,
String encoding)
Creates content from a String, using the given encoding |
static MCRContent |
readFrom(URL url)
Creates new content reading from the given URL. |
void |
sendTo(File target)
Sends content to the given local file |
void |
sendTo(org.apache.commons.vfs.FileObject target)
Sends the content to the given file object |
void |
sendTo(OutputStream out)
Sends content to the given OutputStream |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected InputStream in
protected boolean consumed
protected boolean isXML
| Method Detail |
|---|
public static MCRContent readFrom(String text)
throws IOException,
UnsupportedEncodingException
text - the content
IOException
UnsupportedEncodingException
public static MCRContent readFrom(String text,
String encoding)
throws IOException,
UnsupportedEncodingException
text - the contentencoding - the encoding to be used to write bytes
IOException
UnsupportedEncodingException
public static MCRContent readFrom(File file)
throws IOException
file - the local file to read
IOException
public static MCRContent readFrom(org.apache.commons.vfs.FileObject fo)
throws org.apache.commons.vfs.FileSystemException
fo - the file object to read content from
org.apache.commons.vfs.FileSystemException
public static MCRContent readFrom(byte[] bytes)
throws IOException
bytes - the content's bytes
IOException
public static MCRContent readFrom(Document xml)
throws Exception
xml - the XML document to read in as content
Exceptionpublic static MCRContent readFrom(InputStream in)
in - the input stream to read content from
public static MCRContent readFrom(URL url)
throws org.apache.commons.vfs.FileSystemException
url - the url to read content from
org.apache.commons.vfs.FileSystemException
public MCRContent ensureXML()
throws Exception
Exceptionpublic InputStream getInputStream()
public MCRContentInputStream getContentInputStream()
public void sendTo(OutputStream out)
throws IOException
out - the OutputStream to write the content to
IOException
public void sendTo(File target)
throws IOException
target - the file to write the content to
IOException
public void sendTo(org.apache.commons.vfs.FileObject target)
throws IOException,
org.apache.commons.vfs.FileSystemException
target - the file to write the content to
IOException
org.apache.commons.vfs.FileSystemException
public Document asXML()
throws JDOMException,
IOException
JDOMException
IOException
public byte[] asByteArray()
throws IOException
IOException
public String asString(String encoding)
throws IOException,
UnsupportedEncodingException
encoding - the encoding to use to build the characters
IOException
UnsupportedEncodingException
public String asString()
throws IOException,
UnsupportedEncodingException
IOException
UnsupportedEncodingExceptionprotected void checkConsumed()
public MCRContent[] makeCopies(int numCopies)
throws IOException
numCopies - the number of copies to make
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||