View Javadoc

1   /* ***** BEGIN LICENSE BLOCK *****
2    * Version: MPL 1.1
3    *
4    * The contents of this file are subject to the Mozilla Public License Version
5    * 1.1 (the "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis,
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11   * for the specific language governing rights and limitations under the
12   * License.
13   *
14   * The Original Code is "SMS Library for the Java platform".
15   *
16   * The Initial Developer of the Original Code is Markus Eriksson.
17   * Portions created by the Initial Developer are Copyright (C) 2002
18   * the Initial Developer. All Rights Reserved.
19   *
20   * Contributor(s):
21   *
22   * ***** END LICENSE BLOCK ***** */
23  package org.marre.sms.nokia;
24  
25  import java.io.ByteArrayOutputStream;
26  import java.io.IOException;
27  
28  import org.marre.sms.SmsConstants;
29  import org.marre.sms.SmsPortAddressedMessage;
30  import org.marre.sms.SmsUserData;
31  
32  /***
33   * Nokia Group Graphic (CLI) message
34   * <p>
35   * <b>Note!</b> I haven't been able to verify that this class works since
36   * I don't have access to a phone that can handle Group Graphic.
37   * @author Markus Eriksson
38   * @version $Id: NokiaGroupGraphic.java,v 1.10 2004/11/20 19:02:35 c95men Exp $
39   */
40  public class NokiaGroupGraphic extends SmsPortAddressedMessage
41  {
42      protected byte[] myOtaBitmap;
43      
44      /***
45       * Creates a group graphic SMS message
46       *
47       * @param theOtaBitmap An OtaBitmap object representing the
48       * image to send
49       */
50      public NokiaGroupGraphic(OtaBitmap theOtaBitmap)
51      {
52          this(theOtaBitmap.getBytes());
53      }
54  
55      /***
56       * Creates a group graphic SMS message
57       * <p>
58       * The given byte array must be in the Nokia OTA image format.
59       *
60       * @param theOtaImage The ota image as a byte-array
61       */
62      public NokiaGroupGraphic(byte[] theOtaImage)
63      {
64          super(SmsConstants.PORT_NOKIA_CLI_LOGO, 0);
65          
66          myOtaBitmap = theOtaImage;
67      }
68  
69      public SmsUserData getUserData()
70      {
71          ByteArrayOutputStream baos = new ByteArrayOutputStream(140);
72  
73          try
74          {
75              // Type?
76              baos.write(0x30);
77              // bitmap
78              baos.write(myOtaBitmap);
79  
80              baos.close();
81          }
82          catch (IOException ex)
83          {
84              // Should not happen!
85          }
86          
87          return new SmsUserData(baos.toByteArray());
88      }
89  }