ByteArrayDataSource

public class ByteArrayDataSource implements DataSource

ByteArrayDataSource is an implementation of the javax.activation.DataSource that represents a data source of a byte array.

Author:Hugo Y. K. Lam

Constructors

ByteArrayDataSource

public ByteArrayDataSource(byte[] bytes)

Creates a new instance of ByteArrayDataSource.

Parameters:
  • bytes – the bytes source.

ByteArrayDataSource

public ByteArrayDataSource(byte[] bytes, String contentType)

Creates a new instance of ByteArrayDataSource.

Parameters:
  • bytes – the bytes source.
  • contentType – the content type.

ByteArrayDataSource

public ByteArrayDataSource(byte[] bytes, String contentType, String name)

Creates a new instance of ByteArrayDataSource.

Parameters:
  • bytes – the bytes source.
  • contentType – the content type.
  • name – the name of the underlying content.

Methods

getContentType

public String getContentType()

Gets the content type.

Returns:the content type.

See also: javax.activation.DataSource.getContentType()

getInputStream

public InputStream getInputStream()

Returns a new input stream representing the bytes source.

Returns:a new byte array input stream.

See also: javax.activation.DataSource.getInputStream()

getName

public String getName()

Gets the name of the underlying content.

Returns:the name of the underlying content.

See also: javax.activation.DataSource.getName()

getOutputStream

public OutputStream getOutputStream()

This method always throw IO exception.

Throws:
  • IOException – as output stream is not supported by this data source.

See also: javax.activation.DataSource.getOutputStream()