]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/FileObject.php
4 * Description of FileObject
8 abstract class FileObject
{
9 private $byteLength = -1;
11 public function __construct($byteLength = -1){
12 $this->byteLength
= $byteLength;
15 public function getByteLength(){
16 if($this->byteLength
>= 0){
17 return $this->byteLength
;
19 return $this->getLength();
22 public function getLength(){
23 throw new Exception("Sub-class needs to implement this if it doesn't have a fixed length");
27 * Convert a string to byte format (maximum 4 bytes)
28 * @param string $string Input string
29 * @return int Output integer
31 public function toInt($string){
33 for($i = 0, $len = min(4, strlen($string)); $i < $len; $i++
){
34 $out = $out | (ord($string[$i]) << (($len-$i-1)*8));
40 * Convert a byte (stored in an integer) to a string
44 public function byteToString($int){
45 return $this->toString($int, 1);
49 * Convert a byte (stored in an integer) to a string
53 public function byteAsString($int){
54 return $this->asString($int, 1);
58 * Convert a short (stored in an integer) to a string
62 public function shortToString($int){
63 return $this->toString($int, 2);
67 * Convert a short (stored in an integer) to a string
71 public function shortAsString($int){
72 return $this->asString($int, 2);
76 * Convert a tri-byte (stored in an integer) to a string
77 * @param tri-byte $int
80 public function triToString($int){
81 return $this->toString($int, 3);
85 * Convert a tri-byte (stored in an integer) to a string
86 * @param tri-byte $int
89 public function triAsString($int){
90 return $this->asString($int, 3);
94 * Convert an integer to a string
98 public function intToString($int){
99 return $this->toString($int, 4);
103 * Convert an integer to a string
107 public function intAsString($int){
108 return $this->asString($int, 4);
112 * Convert a number of n bytes to a string
113 * @param int $int Number that should be converted
114 * @param int $size Number of bytes to convert
115 * @return string Output string
117 private function toString($int, $size){
119 for($i = 0; $i < $size; $i++
){
120 $out = chr($int & 0xFF).$out;
127 * Convert a number of n bytes to a string
128 * @param int $int Number that should be converted
129 * @param int $size Number of bytes to convert
130 * @return string Output string
132 private function asString($int, $size){
134 for($i = 0; $i < $size; $i++
){
135 if($i > 0) $out = " ".$out;
136 $byte = dechex($int & 0xFF);
137 if(strlen($byte) == 1) $byte = "0".$byte;
146 * @return mixed Value to get
148 abstract public function get();
152 * @return mixed Value to set
154 abstract public function set($value);
157 * Serialize the object
158 * @return string String representation
160 abstract public function serialize();
163 * Unserialize the object
164 * @param string $data String representation
166 abstract public function unserialize($data);