PageRenderTime 36ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/util/PacketEncoder.java

http://mobicents.googlecode.com/
Java | 153 lines | 21 code | 18 blank | 114 comment | 0 complexity | 3c204719d69236de9a996d588436e4fb MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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. package org.mobicents.protocols.smpp.util;
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25. import org.mobicents.protocols.smpp.Address;
  26. import org.mobicents.protocols.smpp.ErrorAddress;
  27. /**
  28. * Interface specification for a packet encoder.
  29. * @version $Id: PacketEncoder.java 457 2009-01-15 17:37:42Z orank $
  30. */
  31. public interface PacketEncoder {
  32. /**
  33. * Set the output stream this encoder is writing to.
  34. * @param out The output stream to write to.
  35. * @return This packet encoder.
  36. */
  37. PacketEncoder setStream(OutputStream out);
  38. /**
  39. * Get the stream this encoder is writing to.
  40. * @return The stream this encoder is writing to.
  41. */
  42. OutputStream getStream();
  43. /**
  44. * Write a C-String (one that is terminated with a nul byte) to the
  45. * output stream. The characters will be encoded using US-ASCII.
  46. * @param value The string value to write. If <code>value</code> is
  47. * <code>null</code> a single nul-byte will still be written.
  48. * @return This packet encoder.
  49. * @throws IOException If a problem occurs writing to the stream.
  50. */
  51. PacketEncoder writeCString(String value) throws IOException;
  52. /**
  53. * Write a string to the output stream. The characters will be encoded
  54. * using US-ASCII.
  55. * @param value The string value to write.
  56. * @param length The number of characters to write.
  57. * @return This packet encoder.
  58. * @throws IOException If a problem occurs writing to the stream.
  59. * @throws IndexOutOfBoundsException If <code>length</code> is
  60. * longer than the number of characters in <code>value</code>.
  61. */
  62. PacketEncoder writeString(String value, int length) throws IOException;
  63. /**
  64. * Write a 1-byte unsigned integer to the output stream.
  65. * @param value The integer value to send.
  66. * @return This packet encoder.
  67. * @throws IOException If a problem occurs writing to the stream.
  68. */
  69. PacketEncoder writeUInt1(int value) throws IOException;
  70. /**
  71. * Write a 2-byte unsigned integer to the output stream in big-endian
  72. * order.
  73. * @param value The integer value to send.
  74. * @return This packet encoder.
  75. * @throws IOException If a problem occurs writing to the stream.
  76. */
  77. PacketEncoder writeUInt2(int value) throws IOException;
  78. /**
  79. * Write a 4-byte unsigned integer to the output stream in big-endian
  80. * order.
  81. * @param value The integer value to send.
  82. * @return This packet encoder.
  83. * @throws IOException If a problem occurs writing to the stream.
  84. */
  85. PacketEncoder writeUInt4(long value) throws IOException;
  86. /**
  87. * Write a 4-byte integer to the output stream in big-endian
  88. * order.
  89. * @param value The integer value to send.
  90. * @return This packet encoder.
  91. * @throws IOException If a problem occurs writing to the stream.
  92. */
  93. PacketEncoder writeInt4(int value) throws IOException;
  94. /**
  95. * Write an 8-byte integer to the output stream in big-endian
  96. * order.
  97. * @param value The integer value to send.
  98. * @return This packet encoder.
  99. * @throws IOException If a problem occurs writing to the stream.
  100. */
  101. PacketEncoder writeInt8(long value) throws IOException;
  102. /**
  103. * Write an SMPP address to the output stream.
  104. * @param address The address to write to the stream.
  105. * @return This packet encoder.
  106. * @throws IOException If a problem occurs writing to the stream.
  107. */
  108. PacketEncoder writeAddress(Address address) throws IOException;
  109. /**
  110. * Write an SMPP error address to the output stream.
  111. * @param address The error address to write.
  112. * @return This packet encoder.
  113. * @throws IOException If a problem occurs while writing.
  114. */
  115. PacketEncoder writeErrorAddress(ErrorAddress errorAddress) throws IOException;
  116. /**
  117. * Write an SMPP date to the output stream.
  118. * @param date The SMPP date to write to the stream.
  119. * @return This packet encoder.
  120. * @throws IOException If a problem occurs writing to the stream.
  121. */
  122. PacketEncoder writeDate(SMPPDate date) throws IOException;
  123. PacketEncoder writeBytes(byte[] array) throws IOException;
  124. /**
  125. * Write a byte array to the output stream.
  126. * @param array The byte array to write bytes from.
  127. * @param offset The offset to begin copying bytes from.
  128. * @param length The number of bytes to write.
  129. * @return This packet encoder.
  130. * @throws IOException If a problem occurs writing to the stream.
  131. * @throws IndexOutOfBoundsException if there are insufficient bytes
  132. * in the array to satisfy the <code>length</code> parameter.
  133. */
  134. PacketEncoder writeBytes(byte[] array, int offset, int length) throws IOException;
  135. }