Package org.jvnet.staxex
Class Base64Data
- java.lang.Object
-
- org.jvnet.staxex.Base64Data
-
- All Implemented Interfaces:
java.lang.CharSequence,java.lang.Cloneable
public class Base64Data extends java.lang.Object implements java.lang.CharSequence, java.lang.CloneableBinary data represented as base64-encoded string in XML.Used in conjunction with
XMLStreamReaderExandXMLStreamWriterEx.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classBase64Data.Base64DataSourceprivate classBase64Data.Base64StreamingDataHandlerprivate static classBase64Data.FilterDataHandler
-
Field Summary
Fields Modifier and Type Field Description private static intCHUNK_SIZEprivate byte[]dataprivate booleandataCloneByRefTrue ifdatacan be cloned by reference if Base64Data instance is cloned.private jakarta.activation.DataHandlerdataHandlerprivate intdataLenLength of the valid data indata.private java.lang.StringhrefCidprivate static java.util.logging.Loggerloggerprivate java.lang.StringmimeTypeOptional MIME type ofdata.
-
Constructor Summary
Constructors Constructor Description Base64Data()Default constructorBase64Data(Base64Data that)Clone constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int index)Encode this binary data in the base64 encoding and returns the character at the specified position.Base64Dataclone()byte[]get()Gets the raw data.jakarta.activation.DataHandlergetDataHandler()Gets the raw data.intgetDataLen()Gets the length of the binary data counted in bytes.byte[]getExact()Gets the byte[] of the exact length.java.lang.StringgetHrefCid()java.io.InputStreamgetInputStream()Gets the data as anInputStream.java.lang.StringgetMimeType()(package private) static java.lang.StringgetProperty(java.lang.String propName)booleanhasData()Returns false if this object only hasDataHandlerand thereforeget()operation is likely going to be expensive.intlength()Gets the number of characters needed to represent this binary data in the base64 encoding.voidset(byte[] data, int len, java.lang.String mimeType)Fills in the data object by a portion of the byte[].voidset(byte[] data, int len, java.lang.String mimeType, boolean cloneByRef)Fills in the data object by a portion of the byte[].voidset(byte[] data, java.lang.String mimeType)Fills in the data object by the byte[] of the exact length.voidset(jakarta.activation.DataHandler data)Fills in the data object by aDataHandler.voidsetHrefCid(java.lang.String cid)java.lang.CharSequencesubSequence(int start, int end)Internally this is only used to split a text to a list, which doesn't happen that much for base64.java.lang.StringtoString()Returns the base64 encoded string of this data.voidwriteTo(char[] buf, int start)voidwriteTo(javax.xml.stream.XMLStreamWriter output)
-
-
-
Field Detail
-
dataHandler
private jakarta.activation.DataHandler dataHandler
-
data
private byte[] data
-
hrefCid
private java.lang.String hrefCid
-
dataLen
private int dataLen
Length of the valid data indata.
-
dataCloneByRef
private boolean dataCloneByRef
True ifdatacan be cloned by reference if Base64Data instance is cloned.
-
mimeType
private java.lang.String mimeType
Optional MIME type ofdata. Unused whendataHandleris set. UseDataHandler.getContentType()in that case.
-
logger
private static final java.util.logging.Logger logger
-
CHUNK_SIZE
private static final int CHUNK_SIZE
-
-
Constructor Detail
-
Base64Data
public Base64Data()
Default constructor
-
Base64Data
public Base64Data(Base64Data that)
Clone constructor- Parameters:
that- needs to be cloned
-
-
Method Detail
-
set
public void set(byte[] data, int len, java.lang.String mimeType, boolean cloneByRef)Fills in the data object by a portion of the byte[].- Parameters:
data- actual datalen- data[0] to data[len-1] are treated as the data.mimeType- MIME typecloneByRef- true if data[] can be cloned by reference
-
set
public void set(byte[] data, int len, java.lang.String mimeType)Fills in the data object by a portion of the byte[].- Parameters:
data- actual data byteslen- data[0] to data[len-1] are treated as the data.mimeType- MIME type
-
set
public void set(byte[] data, java.lang.String mimeType)Fills in the data object by the byte[] of the exact length.- Parameters:
data- this buffer may be owned directly by the unmarshaleld JAXB object.mimeType- MIME type
-
set
public void set(jakarta.activation.DataHandler data)
Fills in the data object by aDataHandler.- Parameters:
data- DataHandler for the data
-
getDataHandler
public jakarta.activation.DataHandler getDataHandler()
Gets the raw data. If the returned DataHandler isStreamingDataHandler, callees may need to downcast to take advantage of its capabilities.- Returns:
- DataHandler for the data
- See Also:
StreamingDataHandler
-
getExact
public byte[] getExact()
Gets the byte[] of the exact length.- Returns:
- byte[] for data
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionGets the data as anInputStream.- Returns:
- data as InputStream
- Throws:
java.io.IOException- if i/o error occurs
-
hasData
public boolean hasData()
Returns false if this object only hasDataHandlerand thereforeget()operation is likely going to be expensive.- Returns:
- false if it has only DataHandler
-
get
public byte[] get()
Gets the raw data. The size of the byte array maybe larger than the actual length.- Returns:
- data as byte[], the array may be larger
-
getDataLen
public int getDataLen()
Gets the length of the binary data counted in bytes. Note that if this object encapsulatesDataHandler, this method would have to read the whole thing intobyte[]just to count the length, becauseDataHandlerdoesn't easily expose the length.- Returns:
- no of bytes
-
getMimeType
public java.lang.String getMimeType()
-
length
public int length()
Gets the number of characters needed to represent this binary data in the base64 encoding.- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
Encode this binary data in the base64 encoding and returns the character at the specified position.- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)Internally this is only used to split a text to a list, which doesn't happen that much for base64. So this method should be smaller than faster.- Specified by:
subSequencein interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
Returns the base64 encoded string of this data.- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
writeTo
public void writeTo(char[] buf, int start)
-
writeTo
public void writeTo(javax.xml.stream.XMLStreamWriter output) throws java.io.IOException, javax.xml.stream.XMLStreamException- Throws:
java.io.IOExceptionjavax.xml.stream.XMLStreamException
-
clone
public Base64Data clone()
- Overrides:
clonein classjava.lang.Object
-
getProperty
static java.lang.String getProperty(java.lang.String propName)
-
getHrefCid
public java.lang.String getHrefCid()
-
setHrefCid
public void setHrefCid(java.lang.String cid)
-
-