org.jvnet.staxex
Class Base64Data

java.lang.Object
  extended by 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.Cloneable

Binary data represented as base64-encoded string in XML.

Used in conjunction with XMLStreamReaderEx and XMLStreamWriterEx.

Author:
Kohsuke Kawaguchi

Constructor Summary
Base64Data()
          Default constructor
Base64Data(Base64Data that)
          Clone constructor
 
Method Summary
 char charAt(int index)
          Encode this binary data in the base64 encoding and returns the character at the specified position.
 Base64Data clone()
           
 byte[] get()
          Gets the raw data.
 javax.activation.DataHandler getDataHandler()
          Gets the raw data.
 int getDataLen()
          Gets the length of the binary data counted in bytes.
 byte[] getExact()
          Gets the byte[] of the exact length.
 java.io.InputStream getInputStream()
          Gets the data as an InputStream.
 java.lang.String getMimeType()
           
 boolean hasData()
          Returns false if this object only has DataHandler and therefore get() operation is likely going to be expensive.
 int length()
          Gets the number of characters needed to represent this binary data in the base64 encoding.
 void set(byte[] data, int len, java.lang.String mimeType)
          Fills in the data object by a portion of the byte[].
 void set(byte[] data, int len, java.lang.String mimeType, boolean cloneByRef)
          Fills in the data object by a portion of the byte[].
 void set(byte[] data, java.lang.String mimeType)
          Fills in the data object by the byte[] of the exact length.
 void set(javax.activation.DataHandler data)
          Fills in the data object by a DataHandler.
 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.
 java.lang.String toString()
          Returns the base64 encoded string of this data.
 void writeTo(char[] buf, int start)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 data
len - data[0] to data[len-1] are treated as the data.
mimeType - MIME type
cloneByRef - 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 bytes
len - 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(javax.activation.DataHandler data)
Fills in the data object by a DataHandler.

Parameters:
data - DataHandler for the data

getDataHandler

public javax.activation.DataHandler getDataHandler()
Gets the raw data. If the returned DataHandler is StreamingDataHandler, 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.IOException
Gets the data as an InputStream.

Returns:
data as InputStream
Throws:
java.io.IOException - if i/o error occurs

hasData

public boolean hasData()
Returns false if this object only has DataHandler and therefore get() 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 encapsulates DataHandler, this method would have to read the whole thing into byte[] just to count the length, because DataHandler doesn'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:
length in interface java.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:
charAt in interface java.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:
subSequence in interface java.lang.CharSequence

toString

public java.lang.String toString()
Returns the base64 encoded string of this data.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

writeTo

public void writeTo(char[] buf,
                    int start)

clone

public Base64Data clone()
Overrides:
clone in class java.lang.Object


Copyright © 2006-2010. All Rights Reserved.