/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/util/PacketEncoder.java
Java | 153 lines | 21 code | 18 blank | 114 comment | 0 complexity | 3c204719d69236de9a996d588436e4fb MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.protocols.smpp.util; 24 25import java.io.IOException; 26import java.io.OutputStream; 27 28import org.mobicents.protocols.smpp.Address; 29import org.mobicents.protocols.smpp.ErrorAddress; 30 31/** 32 * Interface specification for a packet encoder. 33 * @version $Id: PacketEncoder.java 457 2009-01-15 17:37:42Z orank $ 34 */ 35public interface PacketEncoder { 36 37 /** 38 * Set the output stream this encoder is writing to. 39 * @param out The output stream to write to. 40 * @return This packet encoder. 41 */ 42 PacketEncoder setStream(OutputStream out); 43 44 /** 45 * Get the stream this encoder is writing to. 46 * @return The stream this encoder is writing to. 47 */ 48 OutputStream getStream(); 49 50 /** 51 * Write a C-String (one that is terminated with a nul byte) to the 52 * output stream. The characters will be encoded using US-ASCII. 53 * @param value The string value to write. If <code>value</code> is 54 * <code>null</code> a single nul-byte will still be written. 55 * @return This packet encoder. 56 * @throws IOException If a problem occurs writing to the stream. 57 */ 58 PacketEncoder writeCString(String value) throws IOException; 59 60 /** 61 * Write a string to the output stream. The characters will be encoded 62 * using US-ASCII. 63 * @param value The string value to write. 64 * @param length The number of characters to write. 65 * @return This packet encoder. 66 * @throws IOException If a problem occurs writing to the stream. 67 * @throws IndexOutOfBoundsException If <code>length</code> is 68 * longer than the number of characters in <code>value</code>. 69 */ 70 PacketEncoder writeString(String value, int length) throws IOException; 71 72 /** 73 * Write a 1-byte unsigned integer to the output stream. 74 * @param value The integer value to send. 75 * @return This packet encoder. 76 * @throws IOException If a problem occurs writing to the stream. 77 */ 78 PacketEncoder writeUInt1(int value) throws IOException; 79 80 /** 81 * Write a 2-byte unsigned integer to the output stream in big-endian 82 * order. 83 * @param value The integer value to send. 84 * @return This packet encoder. 85 * @throws IOException If a problem occurs writing to the stream. 86 */ 87 PacketEncoder writeUInt2(int value) throws IOException; 88 89 /** 90 * Write a 4-byte unsigned integer to the output stream in big-endian 91 * order. 92 * @param value The integer value to send. 93 * @return This packet encoder. 94 * @throws IOException If a problem occurs writing to the stream. 95 */ 96 PacketEncoder writeUInt4(long value) throws IOException; 97 98 /** 99 * Write a 4-byte integer to the output stream in big-endian 100 * order. 101 * @param value The integer value to send. 102 * @return This packet encoder. 103 * @throws IOException If a problem occurs writing to the stream. 104 */ 105 PacketEncoder writeInt4(int value) throws IOException; 106 107 /** 108 * Write an 8-byte integer to the output stream in big-endian 109 * order. 110 * @param value The integer value to send. 111 * @return This packet encoder. 112 * @throws IOException If a problem occurs writing to the stream. 113 */ 114 PacketEncoder writeInt8(long value) throws IOException; 115 116 /** 117 * Write an SMPP address to the output stream. 118 * @param address The address to write to the stream. 119 * @return This packet encoder. 120 * @throws IOException If a problem occurs writing to the stream. 121 */ 122 PacketEncoder writeAddress(Address address) throws IOException; 123 124 /** 125 * Write an SMPP error address to the output stream. 126 * @param address The error address to write. 127 * @return This packet encoder. 128 * @throws IOException If a problem occurs while writing. 129 */ 130 PacketEncoder writeErrorAddress(ErrorAddress errorAddress) throws IOException; 131 132 /** 133 * Write an SMPP date to the output stream. 134 * @param date The SMPP date to write to the stream. 135 * @return This packet encoder. 136 * @throws IOException If a problem occurs writing to the stream. 137 */ 138 PacketEncoder writeDate(SMPPDate date) throws IOException; 139 140 PacketEncoder writeBytes(byte[] array) throws IOException; 141 142 /** 143 * Write a byte array to the output stream. 144 * @param array The byte array to write bytes from. 145 * @param offset The offset to begin copying bytes from. 146 * @param length The number of bytes to write. 147 * @return This packet encoder. 148 * @throws IOException If a problem occurs writing to the stream. 149 * @throws IndexOutOfBoundsException if there are insufficient bytes 150 * in the array to satisfy the <code>length</code> parameter. 151 */ 152 PacketEncoder writeBytes(byte[] array, int offset, int length) throws IOException; 153}