- java.lang.Object
- 
- jakarta.mail.util.ByteArrayDataSource
 
- 
- All Implemented Interfaces:
- jakarta.activation.DataSource
 
 public class ByteArrayDataSource extends java.lang.Object implements jakarta.activation.DataSourceA DataSource backed by a byte array. The byte array may be passed in directly, or may be initialized from an InputStream or a String.- Author:
- John Mani, Bill Shannon, Max Spivak
 
- 
- 
Constructor SummaryConstructors Constructor Description ByteArrayDataSource(byte[] data, java.lang.String type)Create a ByteArrayDataSource with data from the specified byte array and with the specified MIME type.ByteArrayDataSource(java.io.InputStream is, java.lang.String type)Create a ByteArrayDataSource with data from the specified InputStream and with the specified MIME type.ByteArrayDataSource(java.lang.String data, java.lang.String type)Create a ByteArrayDataSource with data from the specified String and with the specified MIME type.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetContentType()Get the MIME content type of the data.java.io.InputStreamgetInputStream()Return an InputStream for the data.java.lang.StringgetName()Get the name of the data.java.io.OutputStreamgetOutputStream()Return an OutputStream for the data.voidsetName(java.lang.String name)Set the name of the data.
 
- 
- 
- 
Constructor Detail- 
ByteArrayDataSourcepublic ByteArrayDataSource(java.io.InputStream is, java.lang.String type) throws java.io.IOExceptionCreate a ByteArrayDataSource with data from the specified InputStream and with the specified MIME type. The InputStream is read completely and the data is stored in a byte array.- Parameters:
- is- the InputStream
- type- the MIME type
- Throws:
- java.io.IOException- errors reading the stream
 
 - 
ByteArrayDataSourcepublic ByteArrayDataSource(byte[] data, java.lang.String type)Create a ByteArrayDataSource with data from the specified byte array and with the specified MIME type.- Parameters:
- data- the data
- type- the MIME type
 
 - 
ByteArrayDataSourcepublic ByteArrayDataSource(java.lang.String data, java.lang.String type) throws java.io.IOExceptionCreate a ByteArrayDataSource with data from the specified String and with the specified MIME type. The MIME type should include acharsetparameter specifying the charset to be used for the string. If the parameter is not included, the default charset is used.- Parameters:
- data- the String
- type- the MIME type
- Throws:
- java.io.IOException- errors reading the String
 
 
- 
 - 
Method Detail- 
getInputStreampublic java.io.InputStream getInputStream() throws java.io.IOExceptionReturn an InputStream for the data. Note that a new stream is returned each time this method is called.- Specified by:
- getInputStreamin interface- jakarta.activation.DataSource
- Returns:
- the InputStream
- Throws:
- java.io.IOException- if no data has been set
 
 - 
getOutputStreampublic java.io.OutputStream getOutputStream() throws java.io.IOExceptionReturn an OutputStream for the data. Writing the data is not supported; anIOExceptionis always thrown.- Specified by:
- getOutputStreamin interface- jakarta.activation.DataSource
- Throws:
- java.io.IOException- always
 
 - 
getContentTypepublic java.lang.String getContentType() Get the MIME content type of the data.- Specified by:
- getContentTypein interface- jakarta.activation.DataSource
- Returns:
- the MIME type
 
 - 
getNamepublic java.lang.String getName() Get the name of the data. By default, an empty string ("") is returned.- Specified by:
- getNamein interface- jakarta.activation.DataSource
- Returns:
- the name of this data
 
 - 
setNamepublic void setName(java.lang.String name) Set the name of the data.- Parameters:
- name- the name of this data
 
 
- 
 
-