com.starteam
Class Content

java.lang.Object
  extended by com.starteam.Content

public class Content
extends java.lang.Object

The value of a ContentProperty. Arbitrary data with an advisory content type.


Nested Class Summary
static class Content.AcceptedTypes
          This class represents an Accept request-header field.
static class Content.Type
          This class represents a MIME Content-Type value.
static class Content.WebCacheContent
          Content accessor for cached SDK content contained objects are obtained from the artifact cache
 
Field Summary
static Content VALUE_NOT_SET
          The "not set" value.
 
Method Summary
 boolean equals(java.lang.Object o)
          return true if this Content equals the other.
 boolean equalsEx(Content c)
           
static Content fromBytes(byte[] data, Content.Type contentType, java.lang.String name)
          Creates a content value from a byte array, assigning a given content type.
static Content fromBytes(byte[] data, java.lang.String name)
          Creates a content value from a byte array.
static Content fromFile(java.io.File file)
          Creates a content value from a file on disk.
static Content fromFile(java.io.File file, Content.Type contentType, java.lang.String name)
          Creates a content value from a file on disk, assigning a given content type.
static Content fromStream(java.io.InputStream stream, Content.Type contentType, java.lang.String name)
          Creates a content value from an input stream, assigning a given content type.
static Content fromStream(java.io.InputStream stream, java.lang.String name)
          Creates a content value from an input stream.
static Content fromText(java.lang.String data, Content.Type contentType, Encoding enc)
          Create a text based content value from a string, assigning the specified content type and encoding
 Content.Type getContentType()
          Gets the content type.
 int getID()
          if this Content instance represents an attachment, returns the associated attachment ID
 MD5 getMD5()
           
 java.lang.String getName()
          returns the advisory name (or description) of this content the name is typically associated with a rendering mechanism on the client, e.g.
 long getSize()
           
 boolean isEqualTo(Content c)
          returns true if this Content object can be considered identical to the other
 void setName(java.lang.String name)
          set an advisory name (or description) to be saved along with the content the name may typically be associated with a file name on the local platform and a rendering mechanism; e.g.
 byte[] toBytes()
           
 void toFile(java.io.File file)
          Writes the content data to the given file.
 void toStream(java.io.OutputStream stream)
          Writes the content data to the given stream.
 java.lang.String toString()
          Returns a String representation of the structure of this content Note that the returned string is not a representation of the content itself but rather the internal identifiers used to store the Content in the server vault This method will throw an exception if this content object is new or dirty and has not yet been saved to the repository
 java.lang.String toText()
          Converts this content value to a string that is an appropriate value for a TextProperty.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VALUE_NOT_SET

public static final Content VALUE_NOT_SET
The "not set" value.

Method Detail

fromFile

public static Content fromFile(java.io.File file)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
Creates a content value from a file on disk. The content type is assumed to be CONTENT_TYPE_BINARY.

Parameters:
file - The file containing the content data. The file name is used as the advisory name of the content
Returns:
A new content value.
Throws:
java.io.FileNotFoundException
java.io.IOException

fromFile

public static Content fromFile(java.io.File file,
                               Content.Type contentType,
                               java.lang.String name)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
Creates a content value from a file on disk, assigning a given content type.

Parameters:
file - The file containing the content data.
contentType - The content type.
name - an advisory name for the content e.g. training.doc
Returns:
A new content value.
Throws:
java.io.FileNotFoundException
java.io.IOException

fromStream

public static Content fromStream(java.io.InputStream stream,
                                 java.lang.String name)
                          throws java.io.IOException
Creates a content value from an input stream. The content type is assumed to be CONTENT_TYPE_BINARY.

Parameters:
stream - The input stream providing the content data.
name - an advisory name for the content e.g. training.doc
Returns:
A new content value.
Throws:
java.io.IOException

fromStream

public static Content fromStream(java.io.InputStream stream,
                                 Content.Type contentType,
                                 java.lang.String name)
                          throws java.io.IOException
Creates a content value from an input stream, assigning a given content type.

Parameters:
stream - The input stream providing the content data.
contentType - The content type.
name - an advisory name for the content e.g. training.doc
Returns:
A new content value.
Throws:
java.io.IOException

fromBytes

public static Content fromBytes(byte[] data,
                                java.lang.String name)
Creates a content value from a byte array. The content type is assumed to be CONTENT_TYPE_BINARY.

Parameters:
data - The byte array representing the content data.
name - An advisory name for the content; e.g.training.doc
Returns:
A new content value.

fromBytes

public static Content fromBytes(byte[] data,
                                Content.Type contentType,
                                java.lang.String name)
Creates a content value from a byte array, assigning a given content type.

Parameters:
data - The byte array representing the content data.
contentType - The content type.
name - An advisory name for the content
Returns:
A new content value.

fromText

public static Content fromText(java.lang.String data,
                               Content.Type contentType,
                               Encoding enc)
Create a text based content value from a string, assigning the specified content type and encoding

Parameters:
data - the payload
contentType - the content type, should not be BINARY
enc - a character encoding to use for translation
Returns:
a Content object initialized to the specified data, but not yet stored on the server

getContentType

public Content.Type getContentType()
Gets the content type. The content type indicates how the content should be interpreted by a client application. The value is a string having the same format as the standard content-type HTTP/1.1 header, as defined in RFC 2616, section 14.17. The content type is advisory; no attempt is made to ensure that the data has any specific format.

Returns:
The content type.

getSize

public long getSize()
Returns:
The size of the content data, in bytes. If the content is being extracted from an attachment, the MD5 and size are unknown until the content is actually written out to a disk file
See Also:
Content.toFile(java.io.File), Content.getMD5()

getID

public int getID()
if this Content instance represents an attachment, returns the associated attachment ID

Returns:
the attachment ID or -1 if this is not content associated with an attachment

getName

public java.lang.String getName()
returns the advisory name (or description) of this content the name is typically associated with a rendering mechanism on the client, e.g. .doc, .pdf, etc. Note that the advisory name is only stored for Attachments, and is meaningless for Content instances associated with the Content Properties

Returns:
the advisory name (or description) of this content

setName

public void setName(java.lang.String name)
set an advisory name (or description) to be saved along with the content the name may typically be associated with a file name on the local platform and a rendering mechanism; e.g. .doc, .pdf, .gif. Note that the advisory name is only stored for Attachments, and is meaningless for Content instances associated with the Content Properties

Parameters:
name - an advisory name to be stored along with the content

getMD5

public MD5 getMD5()
Returns:
The MD5 signature of the content data. If the content is being extracted from an attachment, the MD5 and size are unknown until the content is actually written out to a disk file
See Also:
Content.toFile(java.io.File), Content.getMD5()

toStream

public void toStream(java.io.OutputStream stream)
              throws java.io.IOException
Writes the content data to the given stream.

Parameters:
stream - The stream to which the data is written.
Throws:
java.io.IOException

toFile

public void toFile(java.io.File file)
            throws java.io.FileNotFoundException,
                   java.io.IOException
Writes the content data to the given file.

Parameters:
file - The file to which the data is written.
Throws:
java.io.FileNotFoundException
java.io.IOException

toBytes

public byte[] toBytes()
Returns:
The content data as an array of bytes.

toText

public java.lang.String toText()
Converts this content value to a string that is an appropriate value for a TextProperty. Succeeds if:

(a) The content type is one of text/*, and
(b) The character encoding is specified in the content type (for example, text/plain; charset=UTF-8), and
(c) The character encoding is supported on the current platform.

Returns:
A text representation of this content value.

toString

public java.lang.String toString()
Returns a String representation of the structure of this content Note that the returned string is not a representation of the content itself but rather the internal identifiers used to store the Content in the server vault This method will throw an exception if this content object is new or dirty and has not yet been saved to the repository

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the structure of the content

isEqualTo

public boolean isEqualTo(Content c)
returns true if this Content object can be considered identical to the other

Parameters:
c - the Content to compare against
Returns:
true if the two can be considered functionally identical

equals

public boolean equals(java.lang.Object o)
return true if this Content equals the other. equality is measured by comparing all data members of 'this' content object to the 'other' which include md5, size, hiveID, etc, i.e. markers indicating the storage criteria of the content in the hive For a shallow equality test of Content, see Content.equalsEx(Content) A shallow test simply compares the Content Type and the data payload

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare against
Returns:
true if the two can be considered functionally identical

equalsEx

public boolean equalsEx(Content c)


StarTeam SDK 14.0, Build 21
Copyright © 2003-2012 Borland Software Corporation. All rights reserved.