AttachmentDataSource

public class AttachmentDataSource implements DataSource

This is an implementation of javax.activation.DataSource that encapsulates attachment data in a SOAP message.

Author:cyng

Constructors

AttachmentDataSource

public AttachmentDataSource(byte[] data, String contentType)

Constructs an AttachmentDataSource object from an array of binary data.

Parameters:
  • data – Byte array containing data for the AttachmentDataSource
  • contentType – Content type of the data.

AttachmentDataSource

public AttachmentDataSource(byte[] data, String contentType, String name)

Constructs an AttachmentDataSource object from an array of binary data, and assign a name to the data source.

Parameters:
  • data – Byte array containing data for the AttachmentDataSource
  • contentType – Content type of the data.
  • name – Name assigned to the AttachmentDataSource

AttachmentDataSource

public AttachmentDataSource(byte[] data, String contentType, String encoding, String name)

Constructs an AttachmentDataSource object from an array of binary data, and assign a name to the data source.

Parameters:
  • data – Byte array containing data for the AttachmentDataSource
  • contentType – Content type of the data.
  • encoding – Content-Transfer-Encoding of the data.
  • name – Name assigned to the AttachmentDataSource

AttachmentDataSource

public AttachmentDataSource(String fileName, String contentType)

Constructs an AttachmentDataSource object from a file.

Parameters:
  • fileName – Name of the file to be loaded.
  • contentType – Content type of the file.
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(String fileName, String contentType, boolean loadToMem)

Constructs an AttachmentDataSource object from a file.

Parameters:
  • fileName – Name of the file to be loaded.
  • contentType – Content type of the file.
  • loadToMem – Load all data to memory upon creation
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(File file, String contentType)

Constructs an AttachmentDataSource object from a File object.

Parameters:
  • fileFile object containing information on the file to be loaded.
  • contentType – Content type of the file.
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(File file, String contentType, boolean loadToMem)

Constructs an AttachmentDataSource object from a File object.

Parameters:
  • fileFile object containing information on the file to be loaded.
  • contentType – Content type of the file.
  • loadToMem – Load all data to memory upon creation
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(InputStream in, String contentType)

Constructs an AttachmentDataSource object from an InputStream.

Parameters:
  • inInputStream from which the data is read and stored in the data source.
  • contentType – Content type of the data.
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(InputStream in, String contentType, String name)

Constructs an AttachmentDataSource object from an InputStream with a given name.

Parameters:
  • inInputStream from which the data is read and stored in the data source.
  • contentType – Content type of the data.
  • name – Name assigned to the AttachmentDataSource.
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(InputStream in, String contentType, String encoding, String name)

Constructs an AttachmentDataSource object from an InputStream with the specified Content-Transfer-Encoding and name.

Parameters:
  • inInputStream from which the data is read and stored in the data source.
  • contentType – Content type of the data.
  • encoding – Content-Transfer-Encoding of the data.
  • name – Name assigned to the AttachmentDataSource.
Throws:
  • IOException

AttachmentDataSource

public AttachmentDataSource(String fileName, long offset, long length, String contentType)

Constructs an AttachmentDataSource object using the data of length in a file starting from offset with the specified Content-Type.

Parameters:
  • fileName – Name of the file to be loaded.
  • offset – Offset from the start of the file.
  • length – Length of data to be read.
  • contentType – Content type of the data.

AttachmentDataSource

public AttachmentDataSource(String fileName, long offset, long length, String contentType, boolean loadToMem)

Constructs an AttachmentDataSource object using the data of length in a file starting from offset with the specified Content-Type.

Parameters:
  • fileName – Name of the file to be loaded.
  • offset – Offset from the start of the file.
  • length – Length of data to be read.
  • contentType – Content type of the data.
  • loadToMem – Load all data to memory upon creation

AttachmentDataSource

public AttachmentDataSource(String fileName, long offset, long length, String contentType, String encoding)

Constructs an AttachmentDataSource object using the data of length in a file starting from offset. with the specified Content-Type and Content-Transfer-Encoding.

Parameters:
  • fileName – Name of the file to be loaded.
  • offset – Offset from the start of the file.
  • length – Length of data to be read.
  • contentType – Content type of the data.
  • encoding – Content-Transfer-Encoding of the data.

AttachmentDataSource

public AttachmentDataSource(String fileName, long offset, long length, String contentType, String encoding, boolean loadToMem)

Constructs an AttachmentDataSource object using the data of length in a file starting from offset. with the specified Content-Type and Content-Transfer-Encoding.

Parameters:
  • fileName – Name of the file to be loaded.
  • offset – Offset from the start of the file.
  • length – Length of data to be read.
  • contentType – Content type of the data.
  • encoding – Content-Transfer-Encoding of the data.
  • loadToMem – Load all data to memory upon creation

AttachmentDataSource

public AttachmentDataSource(DataSource dataSource, long offset, long length, String contentType, String encoding, boolean loadToMem)

Methods

getByteArray

public byte[] getByteArray()

Gets a byte array of data in this data source.

Returns:A byte array of data.

getContentType

public String getContentType()

Gets the content type of data stored in this AttachmentDataSource.

Returns:Content type of data stored in data source.

getInputStream

public InputStream getInputStream()

Gets InputStream from which data in the AttachmentDataSource can be read.

Throws:
  • IOException
Returns:

An InputStream.

getLength

public long getLength()

Gets the length of data in this data source

Returns:length of data

getName

public String getName()

Gets the name of the AttachmentDataSource.

Returns:Name of data source.

getOutputStream

public OutputStream getOutputStream()

This method should never be called. It implements the getOutputStream() method of the javax.activation.DataSource interface and IOException will be thrown as the result of invocation.

Throws:
  • IOException
Returns:

This method always result in IOException; it never returns normally.

setName

public void setName(String name)

Sets the name of the AttachmentDataSource.

Parameters:
  • name – Name of data source.