Apache SOAP API Reference

org.apache.soap.util.mime
Class ByteArrayDataSource

java.lang.Object
  |
  +--org.apache.soap.util.mime.ByteArrayDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class ByteArrayDataSource
extends java.lang.Object
implements javax.activation.DataSource

This class implements a typed DataSource from an InputStream, a byte array, a String, a File.

Author:
Wouter Cloetens (wcloeten@raleigh.ibm.com)

Constructor Summary
ByteArrayDataSource(byte[] data, java.lang.String type)
          Create a datasource from a byte array.
ByteArrayDataSource(java.io.File f, java.lang.String type)
          Create a datasource from a File.
ByteArrayDataSource(java.io.InputStream is, java.lang.String type)
          Create a datasource from an input stream.
ByteArrayDataSource(java.lang.String data, java.lang.String type)
          Create a datasource from a String.

 

Method Summary
 java.lang.String getContentType()
          Get the content type.
 java.io.InputStream getInputStream()
          Return an InputStream to read the content.
 java.lang.String getName()
          getName() is not implemented.
 java.io.OutputStream getOutputStream()
          This DataSource cannot return an OutputStream, so this method is not implemented.
 int getSize()
          Return the number of bytes in the content.
 java.lang.String getText()
          Return the content as a String.
 void setContentType(java.lang.String type)
          Set the content type.
 byte[] toByteArray()
          Return the content as a byte array.
 void writeTo(java.io.OutputStream os)
          Write the content to an OutputStream.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

ByteArrayDataSource

public ByteArrayDataSource(java.io.File f,
                           java.lang.String type)
                    throws java.io.IOException
Create a datasource from a File. If the Content-Type parameter is null, the type will be derived from the filename extension.
Parameters:
f - File object
type - Content-Type

ByteArrayDataSource

public ByteArrayDataSource(java.io.InputStream is,
                           java.lang.String type)
                    throws java.io.IOException
Create a datasource from an input stream.
Parameters:
is - InputStream
type - Content-Type

ByteArrayDataSource

public ByteArrayDataSource(byte[] data,
                           java.lang.String type)
Create a datasource from a byte array.
Parameters:
data - byte array
type - Content-Type

ByteArrayDataSource

public ByteArrayDataSource(java.lang.String data,
                           java.lang.String type)
Create a datasource from a String. This method defaults to a String encoding of iso-8859-1. For a different encoding, specify a Mime "charset" in the Content-Type parameter.
Parameters:
data - byte array
type - Content-Type
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Return an InputStream to read the content.
Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
an InputStream with the content
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
This DataSource cannot return an OutputStream, so this method is not implemented.
Specified by:
getOutputStream in interface javax.activation.DataSource
java.io.IOException

getContentType

public java.lang.String getContentType()
Get the content type.
Specified by:
getContentType in interface javax.activation.DataSource
Returns:
Content-Type string

setContentType

public void setContentType(java.lang.String type)
Set the content type.

getName

public java.lang.String getName()
getName() is not implemented.
Specified by:
getName in interface javax.activation.DataSource

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException
Write the content to an OutputStream.
Parameters:
os - OutputStream to write the entire content to
java.io.IOException

toByteArray

public byte[] toByteArray()
Return the content as a byte array.
Returns:
byte array with the content

getSize

public int getSize()
Return the number of bytes in the content.
Returns:
size of the byte array, or -1 if not set.

getText

public java.lang.String getText()
Return the content as a String. The Content-Type "charset" parameter will be used to determine the encoding, and if that's not available or invalid, "iso-8859-1".
Returns:
a String with the content

Apache SOAP API Reference

Copyright © 2001 Apache XML Project. All Rights Reserved.