org.jboss.media
Class NIOMediaBean

java.lang.Object
  extended byorg.jboss.media.NIOMediaBean
All Implemented Interfaces:
Media (src) , java.io.Serializable

public class NIOMediaBean
extends java.lang.Object
implements Media (src)

An implementation of the Media interface using Java2 1.4's new I/O API. This class is not in use yet...

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.emb.Media (src)
MIME_TYPE_UNKNOWN
 
Constructor Summary
NIOMediaBean(java.io.File mediaFile, java.lang.String mimeType)
           
NIOMediaBean(java.io.InputStream contentStream, java.lang.String mimeType, java.lang.String name)
           
 
Method Summary
 byte[] getContent()
          Returns the complete media content as a byte array.
 MediaFormat (src) getFormat()
          Queries a suitable media format instance from the MediaFormatRegistry singleton and returns it.
 MediaHeader (src) getHeader()
          Returns the receiver's header information.
 java.lang.String getMimeType()
          Returns a mime type for the receiver's content as a string.
 java.lang.String getName()
          Returns the receiver's non-unique name as a String.
 Media (src) getProxy()
          Returns a media object that can be used as a proxy for the receiver, e.g.
 long getSize()
          This operation returns the receiver's content size in number of bytes as a long value.
 int readContent(long position, byte[] buffer)
          Similarly to input streams, this method fills the given buffer with content read from the media object.
 int readContent(long position, byte[] buffer, int offset, int length)
          Similar to input streams, this method fills the given buffer with content read from the media object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NIOMediaBean

public NIOMediaBean(java.io.InputStream contentStream,
                    java.lang.String mimeType,
                    java.lang.String name)
             throws MediaException (src) 

NIOMediaBean

public NIOMediaBean(java.io.File mediaFile,
                    java.lang.String mimeType)
             throws MediaException (src) 
Method Detail

getContent

public byte[] getContent()
                  throws MediaException (src) 
Description copied from interface: Media (src)
Returns the complete media content as a byte array. This method is intended for convenient access to media content up to a few MB in size. Streaming I/O access as defined in readContent() should be used instead to access large content.

Specified by:
getContent in interface Media (src)
Returns:
the media content.
Throws:
MediaException (src)

readContent

public int readContent(long position,
                       byte[] buffer)
                throws MediaException (src) 
Description copied from interface: Media (src)
Similarly to input streams, this method fills the given buffer with content read from the media object. The media content is copied from the given position, and the buffer is filled beginning with offset 0. In case the buffer is larger than the amount of bytes available, it is only partially filled. The buffer may also be filled partially if the implementation uses non-blocking I/O. The method returns the number of bytes copied into the buffer, or -1 in case the given position equals the content size.

Specified by:
readContent in interface Media (src)
Parameters:
position - the position in media to copy from.
buffer - the byte array to store content.
Returns:
the number of bytes copied into the buffer.
Throws:
MediaException (src)

readContent

public int readContent(long position,
                       byte[] buffer,
                       int offset,
                       int length)
                throws MediaException (src) 
Description copied from interface: Media (src)
Similar to input streams, this method fills the given buffer with content read from the media object. The media content is copied from the given position, and the buffer is filled beginning from the given offset with a maximum amount of bytes defined by the given length. In case the buffer is larger than the amount of bytes available, it is only partially filled. The buffer may also be filled partially if the implementation uses non-blocking I/O. The method returns the number of bytes copied into the buffer, or -1 in case the given position equals the content size.

Specified by:
readContent in interface Media (src)
Parameters:
position - the position in media to copy from.
buffer - the byte array to store content.
offset - the offset in the buffer to begin storing content.
length - the number of bytes to copy from the content.
Returns:
number of bytes copied into the buffer.
Throws:
MediaException (src)

getFormat

public MediaFormat (src)  getFormat()
                      throws MediaException (src) 
Description copied from interface: Media (src)
Queries a suitable media format instance from the MediaFormatRegistry singleton and returns it. The file extension contained in the name property is used as a key for this query.

Specified by:
getFormat in interface Media (src)
Returns:
the media format.
Throws:
MediaException (src)

getHeader

public MediaHeader (src)  getHeader()
                      throws MediaException (src) 
Description copied from interface: Media (src)
Returns the receiver's header information. Queries a suitable media format instance from the MediaFormatRegistry singleton and determines the header information based on it.

Specified by:
getHeader in interface Media (src)
Returns:
the media header.
Throws:
MediaException (src)

getMimeType

public java.lang.String getMimeType()
                             throws MediaException (src) 
Description copied from interface: Media (src)
Returns a mime type for the receiver's content as a string. This allows media content to be written directly to a Servlet output stream, as this technique requires a mime type to be specified in case the output is different from HTML. If no mime type has been set explicitly a default mime type is returned, possibly based on the receiver's format.

Specified by:
getMimeType in interface Media (src)
Returns:
the mime type.
Throws:
MediaException (src)

getName

public java.lang.String getName()
                         throws MediaException (src) 
Description copied from interface: Media (src)
Returns the receiver's non-unique name as a String. The name is used as a file name hint in case the media content is to be stored in a file system and therefore may only contain characters that are valid in file names. It contains a file extension that represents the receiver's media format.

Specified by:
getName in interface Media (src)
Returns:
the media name.
Throws:
MediaException (src)

getSize

public long getSize()
             throws MediaException (src) 
Description copied from interface: Media (src)
This operation returns the receiver's content size in number of bytes as a long value.

Specified by:
getSize in interface Media (src)
Returns:
the media size.
Throws:
MediaException (src)

getProxy

public Media (src)  getProxy()
               throws MediaException (src) 
Description copied from interface: Media (src)
Returns a media object that can be used as a proxy for the receiver, e.g. a thumbnail, an icon, a short video/audio clip. Servlets can use this operation whenever a thumbnail or sound bite is required to represent a given media and give users an up front impression of the content. The value returned may have any format and is never null.

Specified by:
getProxy in interface Media (src)
Returns:
the media proxy
Throws:
MediaException (src)