|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.structure.container.ByteArrayContainer
public class ByteArrayContainer
This class is a simple container to hold a byte array.
It additionally offers some simple methods to load the byte array from different ways.
| Field Summary | |
|---|---|
static String |
DEFAULTENCODING
UTF-8 |
static String |
DEFAULTZIPFILENAME
|
static String |
ENCODING_UTF8
|
static Class<? extends ByteArrayContainer> |
implementationForByteArrayContainerClass
Used by the factory method. |
| Constructor Summary | |
|---|---|
ByteArrayContainer()
Default ByteArrayContainer creating an instance with no content. |
|
ByteArrayContainer(byte[] content)
Creates an ByteArrayContainer with a copied byte array content. |
|
ByteArrayContainer(CharSequence charsequence)
|
|
ByteArrayContainer(CharSequence charsequence,
String encoding)
|
|
ByteArrayContainer(InputStream sourceInputStream)
|
|
ByteArrayContainer(Readable readable)
|
|
ByteArrayContainer(String content)
|
|
ByteArrayContainer(String content,
String encoding)
|
|
| Method Summary | ||
|---|---|---|
void |
clear()
Clears the content. |
|
ByteArrayContainer |
copyFrom(byte[] source)
Copies the content from a byte array into the container. |
|
ByteArrayContainer |
copyFrom(ByteArrayContainer sourceByteArrayContainer)
Copies the content from another container into this one. |
|
ByteArrayContainer |
copyFrom(CharSequence charSequence)
Copies the content of a CharSequence into the ByteArrayContainer using the "utf-8". |
|
ByteArrayContainer |
copyFrom(CharSequence charSequence,
String encoding)
Copies the content of a CharSequence into the ByteArrayContainer. |
|
ByteArrayContainer |
copyFrom(File file)
Copies the content of the given File into the ByteArrayContainer. |
|
ByteArrayContainer |
copyFrom(InputStream sourceInputStream)
Copies the content from an InputStream into the ByteArrayContainer without closing the InputStream If the copy operation fails the content of the ByteArrayContainer is set to invalid. |
|
ByteArrayContainer |
copyFrom(Readable readable)
Copies the content from a Readable using the "utf-8" encoding |
|
ByteArrayContainer |
copyFrom(Readable readable,
String encoding)
Copies the content from a Readable using the given encoding |
|
ByteArrayContainer |
copyFrom(String string)
Copies the content of a String into the container. |
|
ByteArrayContainer |
copyFrom(String string,
String encoding)
Copies the content of a String into the ByteArrayContainer. |
|
ByteArrayContainer |
copyFrom(URL url)
Uses the given URL.openStream() to retrieve data which will be available within the ByteArrayContainer If the data cannot be resolved completely the isContentInvalid() will return true afterwards. |
|
ByteArrayContainer |
copyFrom(URLConnection urlConnection)
Similar to copyFrom(URL) |
|
|
copyFromAsSerialized(S element)
Serializes any given Serializable element and stores it |
|
static ByteArrayContainer |
createNewInstance()
Creates a new instance of this class. |
|
void |
download(String urlStr)
Downloads the content from the given url resource. |
|
void |
download(URI uri)
|
|
void |
download(URL url)
Downloads the content from the given url resource. |
|
byte[] |
getContent()
|
|
InputStream |
getInputStream()
|
|
OutputStream |
getOutputStream()
Returns an outputstream, that allows to write the byte array content directly. |
|
OutputStreamWriter |
getOutputStreamWriter()
Like getOutputStreamWriter(String) using the DEFAULTENCODING |
|
OutputStreamWriter |
getOutputStreamWriter(String encoding)
Returns an OutputStreamWriter using the given encoding |
|
PrintStream |
getPrintStreamWriter()
Returns a new PrintStream using the "utf-8" encoding |
|
PrintStream |
getPrintStreamWriter(String encoding)
Returns a new PrintStream |
|
PrintStream |
getPrintStreamWriter(String encoding,
boolean autoFlush)
Returns a new PrintStream |
|
Reader |
getReader()
Returns a Reader with the default encoding "utf-8" |
|
Reader |
getReader(String encoding)
Returns a Reader using the given encoing |
|
boolean |
isContentInvalid()
Returns true if a previous operation on the ByteArrayContainer has put the content into a malformed state. |
|
boolean |
isEmpty()
|
|
boolean |
isNotEmpty()
|
|
void |
load(File file)
Deprecated. use copyFrom(File) instead |
|
void |
save(File file)
Deprecated. use writeTo(File) instead |
|
ByteArrayContainer |
setContent(byte[] content)
|
|
void |
setContentInvalid(boolean isContentInvalid)
Sets the content of the ByteArrayContainer to be marked as invalid |
|
ByteArrayContainer |
setExceptionHandler(ExceptionHandler exceptionHandler)
|
|
|
toDeserializedElement()
Deserializes the content into an element |
|
String |
toString()
Transforms the content into a String. |
|
String |
toString(String encoding)
Transforms the content into a String. |
|
List<String> |
toStringList()
Returns the content as a list of strings, separated by line feed and/or carriage return. |
|
List<String> |
toStringList(String encoding)
Returns the content as a list of strings, separated by line feed and/or carriage return. |
|
List<String> |
toStringList(String encoding,
String regExDelimiter)
Returns the content as a list of strings, separated by an arbitrary regular expression. |
|
Map<String,ByteArrayContainer> |
unzip()
Converts a zip file content into unzipped content. |
|
static Map<String,ByteArrayContainer> |
unzipIntoFilenameByteArrayContainerMap(ByteArrayContainer byteArrayContainer)
Unzipps the given ByteArrayContainer object into a map containing the filenames and unzipped ByteArrayContainer objects for each file. |
|
static Map<String,ByteArrayContainer> |
unzipIntoFilenameByteArrayContainerMap(ByteArrayContainer byteArrayContainer,
ExceptionHandler exceptionHandler)
Unzipps the given ByteArrayContainer object into a map containing the filenames and unzipped ByteArrayContainer objects for each file. |
|
static ByteArrayContainer |
valueOf(ByteArrayContainer byteArrayContainer)
Returns a new ByteArrayContainer instance mapping the same byte[] array as the given ByteArrayContainer |
|
boolean |
writeTo(Appendable appendable,
String encoding)
Writes the content of the ByteArrayContainer to an Appendable e.g. a StringBuilder or
StringBuffer |
|
void |
writeTo(File file)
Writes the content of the ByteArrayContainer to the given File |
|
boolean |
writeTo(OutputStream outputStream)
Writes the content of the ByteArrayContainer to a given OutputStream without closing the OutputStream
but flushing the content to it. |
|
boolean |
writeTo(Writer writer)
Similar to writeTo(Writer, String) using the default encoding "utf-8" |
|
boolean |
writeTo(Writer writer,
String encoding)
Writes the content of the ByteArrayContainer to the given Writer instance. |
|
void |
zip()
|
|
void |
zip(String zipFileName)
Converts the content into a zip file content. |
|
static ByteArrayContainer |
zipFilenameByteArrayContainerMap(Map<String,ByteArrayContainer> byteArrayContainerMap)
Zipps all ByteArrayContainers of a given map, which contains filenames with corresponding unzipped ByteArrayContainer objects. |
|
static ByteArrayContainer |
zipFilenameByteArrayContainerMap(Map<String,ByteArrayContainer> byteArrayContainerMap,
ExceptionHandler exceptionHandler)
Zipps all ByteArrayContainers of a given map, which contains filenames with corresponding unzipped ByteArrayContainer objects. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String ENCODING_UTF8
public static final String DEFAULTENCODING
public static final String DEFAULTZIPFILENAME
public static Class<? extends ByteArrayContainer> implementationForByteArrayContainerClass
createNewInstance()| Constructor Detail |
|---|
public ByteArrayContainer()
ByteArrayContainer creating an instance with no content.
public ByteArrayContainer(byte[] content)
ByteArrayContainer with a copied byte array content.
content - copyFrom(byte[])public ByteArrayContainer(String content)
content - copyFrom(String)
public ByteArrayContainer(String content,
String encoding)
content - copyFrom(String, String)
public ByteArrayContainer(CharSequence charsequence,
String encoding)
charsequence - copyFrom(CharSequence)public ByteArrayContainer(InputStream sourceInputStream)
sourceInputStream - copyFrom(InputStream)public ByteArrayContainer(CharSequence charsequence)
charsequence - copyFrom(CharSequence)public ByteArrayContainer(Readable readable)
readable - ByteArrayContainer,
copyFrom(Readable)| Method Detail |
|---|
public boolean isEmpty()
isNotEmpty()public boolean isNotEmpty()
isEmpty()public void download(URI uri)
uri - download(URL)public void download(URL url)
url - download(URI),
download(String)public void download(String urlStr)
urlStr - download(URI),
download(URL)@Deprecated public void load(File file)
copyFrom(File) instead
file - public ByteArrayContainer copyFrom(File file)
File into the ByteArrayContainer. isContentInvalid() will return true
file - File
isContentInvalid()@Deprecated public void save(File file)
writeTo(File) instead
ByteArrayContainer to a given File
file - Filepublic void writeTo(File file)
ByteArrayContainer to the given File
file - Filepublic ByteArrayContainer copyFrom(ByteArrayContainer sourceByteArrayContainer)
sourceByteArrayContainer -
public ByteArrayContainer copyFrom(InputStream sourceInputStream)
InputStream into the ByteArrayContainer without closing the InputStream ByteArrayContainer is set to invalid.
sourceInputStream -
isContentInvalid()public ByteArrayContainer copyFrom(URL url)
URL.openStream() to retrieve data which will be available within the ByteArrayContainer isContentInvalid() will return true afterwards.
url - URL
isContentInvalid(),
copyFrom(InputStream)public ByteArrayContainer copyFrom(URLConnection urlConnection)
copyFrom(URL)
urlConnection - URLConnection
public ByteArrayContainer copyFrom(Readable readable)
Readable using the "utf-8" encoding
readable -
public ByteArrayContainer copyFrom(Readable readable,
String encoding)
Readable using the given encoding
readable - encoding -
public ByteArrayContainer copyFrom(String string,
String encoding)
String into the ByteArrayContainer. ByteArrayContainer is set to invalid.
string - encoding -
isContentInvalid()public ByteArrayContainer copyFrom(String string)
string -
public ByteArrayContainer copyFrom(CharSequence charSequence)
CharSequence into the ByteArrayContainer using the "utf-8".
charSequence -
public ByteArrayContainer copyFrom(CharSequence charSequence,
String encoding)
CharSequence into the ByteArrayContainer.
charSequence - encoding -
public ByteArrayContainer copyFrom(byte[] source)
source -
public <S extends Serializable> ByteArrayContainer copyFromAsSerialized(S element)
Serializable element and stores it
element -
toDeserializedElement()public <S extends Serializable> S toDeserializedElement()
copyFromAsSerialized(Serializable)public String toString()
toString in class ObjecttoString(String)public String toString(String encoding)
encoding - specifies the encoding of the binary data. Example: "utf-8"
toString()public List<String> toStringList()
public List<String> toStringList(String encoding)
encoding - : for example = "utf-8"
public List<String> toStringList(String encoding,
String regExDelimiter)
encoding - : for example = "utf-8"
ENCODING_UTF8
public boolean writeTo(Writer writer,
String encoding)
ByteArrayContainer to the given Writer instance. The Writer.flush() method
will be invoked afterwards but it will not be closed.
writer - encoding -
writeTo(Writer)public boolean writeTo(Writer writer)
writeTo(Writer, String) using the default encoding "utf-8"
writer -
writeTo(Writer, String)
public boolean writeTo(Appendable appendable,
String encoding)
ByteArrayContainer to an Appendable e.g. a StringBuilder or
StringBuffer
appendable - encoding -
public boolean writeTo(OutputStream outputStream)
ByteArrayContainer to a given OutputStream without closing the OutputStream
but flushing the content to it.
outputStream -
public void clear()
public byte[] getContent()
public ByteArrayContainer setContent(byte[] content)
content -
public InputStream getInputStream()
public Reader getReader()
Reader with the default encoding "utf-8"
public Reader getReader(String encoding)
Reader using the given encoing
encoding -
public OutputStream getOutputStream()
public OutputStreamWriter getOutputStreamWriter(String encoding)
OutputStreamWriter using the given encoding
encoding -
public OutputStreamWriter getOutputStreamWriter()
getOutputStreamWriter(String) using the DEFAULTENCODING
getOutputStreamWriter(String)public void zip(String zipFileName)
public void zip()
zip(String)public static ByteArrayContainer zipFilenameByteArrayContainerMap(Map<String,ByteArrayContainer> byteArrayContainerMap)
byteArrayContainerMap -
public static ByteArrayContainer zipFilenameByteArrayContainerMap(Map<String,ByteArrayContainer> byteArrayContainerMap,
ExceptionHandler exceptionHandler)
byteArrayContainerMap - exceptionHandler - ExceptionHandlerpublic Map<String,ByteArrayContainer> unzip()
unzipIntoFilenameByteArrayContainerMap(ByteArrayContainer)public static Map<String,ByteArrayContainer> unzipIntoFilenameByteArrayContainerMap(ByteArrayContainer byteArrayContainer)
byteArrayContainer -
public static Map<String,ByteArrayContainer> unzipIntoFilenameByteArrayContainerMap(ByteArrayContainer byteArrayContainer,
ExceptionHandler exceptionHandler)
byteArrayContainer - exceptionHandler - ExceptionHandler
public static ByteArrayContainer createNewInstance()
implementationForByteArrayContainerClasspublic boolean isContentInvalid()
ByteArrayContainer has put the content into a malformed state.
copyFrom(InputStream),
copyFrom(String)public void setContentInvalid(boolean isContentInvalid)
ByteArrayContainer to be marked as invalid
isContentInvalid - public PrintStream getPrintStreamWriter()
PrintStream using the "utf-8" encoding
PrintStreampublic PrintStream getPrintStreamWriter(String encoding)
PrintStream
encoding -
PrintStream
public PrintStream getPrintStreamWriter(String encoding,
boolean autoFlush)
PrintStream
encoding - autoFlush -
PrintStreampublic ByteArrayContainer setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler - ExceptionHandler
public static ByteArrayContainer valueOf(ByteArrayContainer byteArrayContainer)
ByteArrayContainer instance mapping the same byte[] array as the given ByteArrayContainer
byteArrayContainer -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||