001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.tck.wma.cbs;
028:
029: import com.sun.tck.wma.sms.MessagePacket;
030:
031: import java.io.IOException;
032:
033: /**
034: * A CBS data packet which is the interface between an application and the data
035: * stream. Methods are included to read/write data from/to the data stream, in
036: * CBS format.
037: */
038: public class CBSPacket extends MessagePacket {
039:
040: /**
041: * Construct a new CBS data packet with no payload (Empty data stream.).
042: */
043: public CBSPacket() {
044: super ();
045: }
046:
047: /**
048: * Construct a new CBS data packet with a data stream (payload)..
049: *
050: * @param payload The array of bytes representing the CBS data.
051: */
052: public CBSPacket(byte[] payload) {
053: super (payload);
054: }
055:
056: /**
057: * Write the encoding type to the data stream. The type can be text,
058: * ucs2, binary.
059: *
060: * @param type The encoding type.
061: */
062: public void setEncodingType(int type) throws IOException {
063: putInt(type);
064: }
065:
066: /**
067: * Get the encoding type from the data stream.
068: *
069: * @return The encoding type.
070: */
071: public int getEncodingType() {
072: return getInt();
073: }
074:
075: /**
076: * Set the message ID, or the channel to listen to, in the data stream..
077: *
078: * @param msgID The message ID.
079: */
080: public void setMessageID(int msgID) throws IOException {
081: putInt(msgID);
082: }
083:
084: /**
085: * Get the message ID from the data stream..
086: *
087: * @return The message ID.
088: */
089: public int getMessageID() {
090: return getInt();
091: }
092:
093: /**
094: * Write the length of the message in the data stream..
095: *
096: * @param msgLen The length, in bytes, of the CBS payload.
097: */
098: public void setMessageLength(int msgLen) throws IOException {
099: putInt(msgLen);
100: }
101:
102: /**
103: * Get the length, in bytes, of the message from the data stream.
104: *
105: * @return The length of the message.
106: */
107: public int getMessageLength() {
108: return getInt();
109: }
110:
111: /**
112: * Write the message bytes to the data stream.
113: *
114: * @param msg The array of bytes to write.
115: */
116: public void setMessage(byte[] msg) throws IOException {
117: putBytes(msg);
118: }
119:
120: /**
121: * Get the message bytes from the data stream.
122: *
123: * @param len The number of bytes to read from the stream.
124: *
125: * @return The array of bytes read from the data stream.
126: */
127: public byte[] getMessage(int len) {
128: return getBytes(len);
129: }
130: }
|