pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util.io
Class SerializableDataSource

java.lang.Object
  extended by org.torweg.pulse.util.io.SerializableDataSource
All Implemented Interfaces:
java.io.Serializable, javax.activation.DataSource, INamed

public class SerializableDataSource
extends java.lang.Object
implements javax.activation.DataSource, INamed, java.io.Serializable

represents a serialisable data source.

Version:
$Revision: 2026 $
Author:
Thomas Weber
See Also:
Serialized Form

Constructor Summary
SerializableDataSource(byte[] byteArray, java.lang.String n, java.lang.String c)
          creates a new data source from a given byte buffer, the given name and the given content-type.
SerializableDataSource(javax.activation.DataSource s)
          creates a new serialisable data source from a given DataSource.
SerializableDataSource(java.io.File f)
          creates a new data source from a given file.
SerializableDataSource(java.io.File f, java.lang.String n)
          creates a new data source from a given file with the given name.
SerializableDataSource(java.io.InputStream i, java.lang.String n)
          creates a new data source from a given InputStream and the given name with a content-type of "application/octet-stream", which will be buffered until sending time.
SerializableDataSource(java.io.InputStream i, java.lang.String n, java.lang.String c)
          creates a new data source from a given InputStream, the given name and the given content-type.
SerializableDataSource(java.lang.String s, java.lang.String n, java.lang.String c)
          creates a data source from a given string, the given name and the given content-type.
SerializableDataSource(VirtualFile f)
          creates a new data source from a given virtual file.
SerializableDataSource(VirtualFile f, java.lang.String n)
          creates a new data source from a given virtual file with the given name.
 
Method Summary
 java.lang.String getContentType()
          returns the content-type of the data source.
 java.io.InputStream getInputStream()
          returns an InputStream for the data source.
 long getLength()
          returns the length of the source.
 java.lang.String getName()
          returns the name.
 java.io.OutputStream getOutputStream()
          will always throw an IOException.
 void setContentType(java.lang.String type)
          sets the content type.
 java.lang.String toString()
          returns a string representation of the SerializableDataSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SerializableDataSource

public SerializableDataSource(javax.activation.DataSource s)
                       throws java.io.IOException
creates a new serialisable data source from a given DataSource.

Parameters:
s - the source DataSource
Throws:
java.io.IOException - on errors reading from the DataSource's InputStream

SerializableDataSource

public SerializableDataSource(java.io.File f)
creates a new data source from a given file.

This constructor assumes that the file will still be at the given location upon sending time. If you are working with a temporary file, use SerializableDataSource(InputStream,String) instead.

Parameters:
f - the file

SerializableDataSource

public SerializableDataSource(java.io.File f,
                              java.lang.String n)
creates a new data source from a given file with the given name.

This constructor assumes that the file will still be at the given location upon sending time. If you are working with a temporary file, use SerializableDataSource(InputStream, String) instead.

Parameters:
f - the file
n - the name

SerializableDataSource

public SerializableDataSource(VirtualFile f)
creates a new data source from a given virtual file.

This constructor assumes that the virtual file will still be at the given location upon sending time. If you are working with a temporary file, use SerializableDataSource(InputStream,String) instead.

Parameters:
f - the file

SerializableDataSource

public SerializableDataSource(VirtualFile f,
                              java.lang.String n)
creates a new data source from a given virtual file with the given name.

This constructor assumes that the virtual file will still be at the given location upon sending time. If you are working with a temporary file, use SerializableDataSource(InputStream,String) instead.

Parameters:
f - the file
n - the name

SerializableDataSource

public SerializableDataSource(java.io.InputStream i,
                              java.lang.String n)
                       throws java.io.IOException
creates a new data source from a given InputStream and the given name with a content-type of "application/octet-stream", which will be buffered until sending time.

Parameters:
i - the input stream
n - the name
Throws:
java.io.IOException - on errors during buffering

SerializableDataSource

public SerializableDataSource(java.io.InputStream i,
                              java.lang.String n,
                              java.lang.String c)
                       throws java.io.IOException
creates a new data source from a given InputStream, the given name and the given content-type. The stream will be buffered until sending time.

Parameters:
i - the input stream
n - the name
c - the content-type
Throws:
java.io.IOException - on errors during buffering

SerializableDataSource

public SerializableDataSource(byte[] byteArray,
                              java.lang.String n,
                              java.lang.String c)
creates a new data source from a given byte buffer, the given name and the given content-type.

Parameters:
byteArray - the buffer
n - the name
c - the content-type

SerializableDataSource

public SerializableDataSource(java.lang.String s,
                              java.lang.String n,
                              java.lang.String c)
creates a data source from a given string, the given name and the given content-type.

Parameters:
s - the text content as a string
n - the name
c - the content type
Method Detail

getContentType

public final java.lang.String getContentType()
returns the content-type of the data source.

Specified by:
getContentType in interface javax.activation.DataSource
Returns:
the content-type
See Also:
DataSource.getContentType()

setContentType

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

Parameters:
type - the content type to set

getInputStream

public final java.io.InputStream getInputStream()
                                         throws java.io.IOException
returns an InputStream for the data source.

Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
an input stream
Throws:
java.io.IOException - on errors accessing the InputStream
See Also:
DataSource.getInputStream()

getName

public final java.lang.String getName()
returns the name.

Specified by:
getName in interface javax.activation.DataSource
Specified by:
getName in interface INamed
Returns:
the name
See Also:
DataSource.getName()

getOutputStream

public final java.io.OutputStream getOutputStream()
                                           throws java.io.IOException
will always throw an IOException.

Specified by:
getOutputStream in interface javax.activation.DataSource
Returns:
nothing
Throws:
java.io.IOException - always
See Also:
DataSource.getOutputStream()

getLength

public final long getLength()
returns the length of the source.

Returns:
the length of the source

toString

public java.lang.String toString()
returns a string representation of the SerializableDataSource.

Overrides:
toString in class java.lang.Object
Returns:
a string representation