3 * A class for handling incoming (encoded) raw data with start and end markers.
4 * The "stream" is being verified by its length (if modulo 4 of it is always
5 * zero) and if the "stream" contains all valid characters (the BASE64
8 * Since the latest refacturing this class works "handler-less".
10 * @author Roland Haeder <webmaster@ship-simu.org>
12 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Developer Team
13 * @license GNU GPL 3.0 or any newer version
14 * @link http://www.ship-simu.org
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 class RawDataInputStream extends BaseStream implements InputStreamable {
31 * Protected constructor
35 protected function __construct () {
36 // Call parent constructor
37 parent::__construct(__CLASS__);
41 * Creates an instance of this node class
43 * @return $streamInstance An instance of this node class
45 public final static function createRawDataInputStream () {
47 $streamInstance = new RawDataInputStream();
49 // Return the instance
50 return $streamInstance;
54 * Streams the data and maybe does something to it
56 * @param $data The data (string mostly) to "stream"
57 * @return $data The data (string mostly) to "stream"
58 * @todo Do we need to do something more here?
59 * @throws Base64EncodingModuloException If the data's length modulo 4 is not zero
60 * @throws Base64EncodingBadException If the data contains characters which are not in the "alphabet" of BASE64 messages.
62 public function streamData ($data) {
63 // Do we have start and end marker again?
64 assert($this->ifStartEndMarkersSet($data));
67 $data = substr($data, strlen(BaseRawDataHandler::STREAM_START_MARKER), -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER));
69 // Can it be validated?
70 if ((strlen($data) % 4) != 0) {
71 // Length modulo 4 must be zero, else it is an invalid Base64 message
72 throw new Base64EncodingModuloException(array($this, $data), self::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4);
73 } elseif (!$this->isBase64Encoded($data)) {
74 // Is not a valid Base64-encoded message
75 throw new Base64EncodingBadException(array($this, $data), self::EXCEPTION_BASE64_BAD_ENCODING);
77 // Decode the data with BASE64-encoding
78 $data = base64_decode($data);
82 //* NOISY-DEBUG: */ $this->debugOutput('RAW-INPUT-STREAM: Length of data is now ' . strlen($data) . ' Bytes.');