|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.contactless.ndef.NDEFRecord
public class NDEFRecord
This class represents an NDEF record. An NDEF record consists of type, type format, identifier for the payload and the actual payload in a byte array. This class is an abstraction of the NDEF record defined by the NFC Forum NDEF specification and it hides some of the fields defined in that specification and leaves them to the API implementation. NDEF record may contain subrecords. Nested records can be accessed by getting the record payload and then parsing that payload into new NDEF records.
A record type gives an identity to the payload in the record. Based on the record type information the application knows the meaning of the record payload. This information is used to guide the processing of the payload, like for example in the application start as described in the appendix B. The type of the first NDEF record inside NDEF message, by convention, should provide the processing context not only for the first record but for the whole NDEF message.
The NDEF record also contains an optional identifier for the payload. This identifier may be used to refer to the payload in other records. The value of the ID field is an identifier in the form of a URI RFC (3986). This class provides methods for getting and setting this identifier. Character encoding used in identifier field must be UTF-8.
The chunking feature defined in the NDEF specification must be handled below the Java API level. Only complete NDEF records are provided to the Java application. This means that the device implementing this API should have enough memory to handle complete NDEF records.
Constructor Summary | |
---|---|
NDEFRecord(byte[] data,
int offset)
Formulates a new NDEF record from the given byte array starting from the specified index. |
|
NDEFRecord(NDEFRecordType recordType,
byte[] id,
byte[] payload)
Creates a new NDEFRecord with specified record type, identifier
and payload. |
Method Summary | |
---|---|
void |
appendPayload(byte[] payload)
This method appends payload into the end of the NDEF record payload. |
byte[] |
getId()
Returns the identifier for the record payload. |
NDEFMessage |
getNestedNDEFMessage(int offset)
Returns the nested NDEF message from the record payload. |
byte[] |
getPayload()
Returns the payload in the NDEF record as byte array. |
long |
getPayloadLength()
Returns the length of the payload in the NDEF record. |
NDEFRecordType |
getRecordType()
Returns the record type of this record. |
void |
setId(byte[] id)
Sets the identifier for the record payload. |
byte[] |
toByteArray()
Returns the NDEF record as byte array, containing the record type name, type format, identifier, length and the payload of the record. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NDEFRecord(byte[] data, int offset)
Formulates a new NDEF record from the given byte array starting from
the specified index. The byte array should
contain the record type name, type format, identifier, length and the
payload of the record. The offset
must
be a value greater than or equal to 0 and less than the length of the
payload byte array.
data
- the byte array containing the NDEF recordoffset
- start index of the NDEF record data in the payload byte array
java.lang.NullPointerException
- if data
is null
java.lang.ArrayIndexOutOfBoundsException
- if the offset
is invalid
java.lang.IllegalArgumentException
- if the data
cannot be
formulated to NDEF recordpublic NDEFRecord(NDEFRecordType recordType, byte[] id, byte[] payload)
Creates a new NDEFRecord
with specified record type, identifier
and payload. The constructor implementation must
make a copy from the original identifier and payload.
Record identifier is given in the URL format and it may
be null
. In this case it must be
omitted from the NDEF record.
Payload of the NDEF record may be null
or a zero-length array. Both these cases mean that payload
must be omitted from the NDEF record.
If record type format is NDEFRecordType.EMPTY
the identifier and the payload must be omitted
from the NDEF record.
recordType
- record type of the NDEF recordid
- payload identifierpayload
- payload of the record as byte array
java.lang.NullPointerException
- if recordType
is null
Method Detail |
---|
public void appendPayload(byte[] payload)
This method appends payload into the end of the NDEF record payload. If
payload
is an empty array or null
, this method
returns without any additions to the existing payload. If the
record type format is EMPTY
, the payload must
be omitted from the NDEF record and using this method causes an
IllegalArgumentException
to the thrown.
payload
- payload to be added
java.lang.IllegalArgumentException
- if record type format is
EMPTY
and this method is calledpublic byte[] getId()
Returns the identifier for the record payload. This can be used to refer to this payload from other records.
null
if identifier has been omitted
from the NDEF recordpublic NDEFMessage getNestedNDEFMessage(int offset)
Returns the nested NDEF message from the record payload. The beginning of
the message is identified by the offset. The offset
must be a value greater than or equal to 0
and less than the length of the payload byte array. If the NDEF record
does not have payload null
is returned.
offset
- the start index of the NDEF message in the payload byte array
null
if the NDEF record does
not have payload
java.lang.ArrayIndexOutOfBoundsException
- if the offset
is invalid
java.lang.IllegalArgumentException
- if the record payload can not
be formulated to NDEF messagepublic byte[] getPayload()
Returns the payload in the NDEF record as byte array.
null
if payload has been
omitted from the NDEF recordpublic long getPayloadLength()
Returns the length of the payload in the NDEF record. This method is offered for convenience, so that the payload length is available before actually retrieving it.
0
if payload has been omitted
from the NDEF recordpublic NDEFRecordType getRecordType()
Returns the record type of this record. This object contains the actual type and the type format information.
public void setId(byte[] id)
Sets the identifier for the record payload. This identifier can be used
to refer to the payload in this record from other records and it is given
in the URL format. Identifier may be
null
. In this case it must be
omitted from the NDEF record. If the record type format is EMPTY
,
the identifier must be omitted from the NDEF
record and using this method causes an IllegalArgumentException
to the thrown. The implementation must make
a copy from the original identifier.
id
- identifier of the payload
java.lang.IllegalArgumentException
- if record type format is
EMPTY
and this method is calledpublic byte[] toByteArray()
Returns the NDEF record as byte array, containing the record type name,
type format, identifier, length and the payload of the record. This
method has the same effect as calling
NDEFMessage.toByteArray()
for an
NDEFMessage
object that has only a single
NDEFRecord
object. The NDEFRecord
must have both the MB
and
ME
set.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |