public class Attachment extends BinaryProperty
Defines an file attachment (such as an image or document) that is associated with the component to which it belongs.
Code sample:
VEvent event = new VEvent(); //from a byte array byte[] data = ... Attachment attach = new Attachment("image/png", data); event.addAttachment(attach); //from a file File file = new File("image.png"); attach = new Attachment("image/png", file); event.addAttachment(attach); //referencing a URL attach = new Attachment("image/png", "http://example.com/image.png"); event.addAttachment(attach);
data, uri
parameters
Constructor and Description |
---|
Attachment(Attachment original)
Copy constructor.
|
Attachment(String formatType,
byte[] data)
Creates a new attachment.
|
Attachment(String formatType,
File file)
Creates a new attachment.
|
Attachment(String formatType,
String uri)
Creates a new attachment.
|
Modifier and Type | Method and Description |
---|---|
Attachment |
copy()
Creates a copy of this property object.
|
boolean |
equals(Object obj) |
String |
getContentId()
Sets the content ID.
|
int |
hashCode() |
void |
setContentId(String contentId)
Sets the content ID.
|
void |
setData(byte[] data)
Sets the property's binary data.
|
void |
setUri(String uri)
Sets the property's URI.
|
protected Map<String,Object> |
toStringValues()
Gets string representations of the class's fields for the
ICalProperty.toString() method. |
protected void |
validate(List<ICalComponent> components,
ICalVersion version,
List<ValidationWarning> warnings)
Checks the property for data consistency problems or deviations from the
specifications.
|
getData, getFormatType, getUri, setFormatType
addParameter, getParameter, getParameters, getParameters, removeParameter, setParameter, setParameter, setParameters, toString, validate
public Attachment(String formatType, File file) throws IOException
formatType
- the content-type of the data (e.g. "image/png")file
- the file to attachIOException
- if there's a problem reading from the filepublic Attachment(String formatType, byte[] data)
formatType
- the content-type of the data (e.g. "image/png")data
- the binary datapublic Attachment(String formatType, String uri)
formatType
- the content-type of the data (e.g. "image/png")uri
- a URL pointing to the resource (e.g.
"http://example.com/image.png")public Attachment(Attachment original)
original
- the property to make a copy ofpublic void setData(byte[] data)
BinaryProperty
setData
in class BinaryProperty
data
- the binary datapublic void setUri(String uri)
BinaryProperty
setUri
in class BinaryProperty
uri
- the URI (e.g. "http://example.com/image.png")public String getContentId()
public void setContentId(String contentId)
contentId
- the content IDprotected void validate(List<ICalComponent> components, ICalVersion version, List<ValidationWarning> warnings)
ICalProperty
Checks the property for data consistency problems or deviations from the specifications.
This method should be overridden by child classes that wish to provide validation logic. The default implementation of this method does nothing.
validate
in class BinaryProperty
components
- the hierarchy of components that the property belongs
toversion
- the version to validate againstwarnings
- the list to add the warnings toprotected Map<String,Object> toStringValues()
ICalProperty
Gets string representations of the class's fields for the
ICalProperty.toString()
method.
Meant to be overridden by child classes. The default implementation returns an empty map.
toStringValues
in class BinaryProperty
public Attachment copy()
ICalProperty
Creates a copy of this property object.
The default implementation of this method uses reflection to look for a copy constructor. Child classes SHOULD override this method to avoid the performance overhead involved in using reflection.
The child class's copy constructor, if present, MUST invoke the
ICalProperty.ICalProperty(ICalProperty)
super constructor to ensure that the
parameters are also copied.
This method MUST be overridden by the child class if the child class does
not have a copy constructor. Otherwise, an
UnsupportedOperationException
will be thrown when an attempt is
made to copy the property (such as in the
ICalendar class's copy constructor
).
copy
in class ICalProperty
public int hashCode()
hashCode
in class BinaryProperty
public boolean equals(Object obj)
equals
in class BinaryProperty
Copyright © 2013-2017 Michael Angstadt. All Rights Reserved.