private function getDataArrayFromFile (SplFileInfo $infoInstance): array {
// Init compressed data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-LOCAL-FILE-DATABASE: infoInstance=%s - CALLED!', $infoInstance->__toString()));
- $compressedData = $this->getFileIoInstance()->loadFileContents($infoInstance);
+ $compressedData = $this->getFileIoInstance()->loadFileContentsAsArray($infoInstance);
// Is it valid?
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LOCAL-FILE-DATABASE: compressedData[]=%s', gettype($compressedData)));
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: infoInstance=%s - CALLED!', $infoInstance));
$inputBuffer = '';
$lastBuffer = '';
- $header = [];
- $data = [];
- $readData = ''; // This will contain our read data
// Get a file input handler
$fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($infoInstance));
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('FILE-IO-STREAM: Closing file ...');
unset($fileInstance);
+ // Return read raw data
+ return $inputBuffer;
+ }
+
+ /**
+ * Reads from a local file as array
+ *
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $array An array with the element 'header' and 'data
+ * @see FileInputStreamer
+ */
+ public final function loadFileContentsAsArray (SplFileInfo $infoInstance): array {
+ // Invoke above method
+ $inputBuffer = $this->loadFileContents($infoInstance);
+
+ // Initialize some arrays
+ $readData = '';
+ $header = [];
+ $data = [];
+
// Convert it into an array
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: Read inputBuffer=%d bytes from infoInstance=%s', strlen($inputBuffer), $infoInstance));
$inputArray = explode(chr(10), $inputBuffer);
// Was raw lines read and no header/data?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('FILE-IO-STREAM: readData()=%d,header()=%d,data()=%d', strlen($readData), count($header), count($data)));
if ((!empty($readData)) && (count($header) == 0) && (count($data) == 0)) {
- // Return raw lines back
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-STREAM: readData()=%d - EXIT!', strlen($readData)));
- return $readData;
+ // Abort here @TODO
+ throw new InvalidEncodedFileException();
}
// Was a header found?
*
* @param $infoInstance An instance of a SplFileInfo class
* @return $content Raw file content
- * @throws InvalidArrayCountException If an array has not the expected size
- * @throws InvalidMD5ChecksumException If two MD5 hashes did not match
*/
public function loadFileContents (SplFileInfo $infoInstance): string {
/*
throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
}
+ /**
+ * Reads from a local or remote file as array
+ *
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $array An array with the element 'header' and 'data
+ */
+ public function loadFileContentsAsArray (SplFileInfo $infoInstance): array {
+ /*
+ * This class (or its implementations) are special file readers/writers.
+ * There is no need to read/write the whole file.
+ */
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: infoInstance=' . $infoInstance);
+ throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
}
*/
function loadFileContents (SplFileInfo $infoInstance): string;
+ /**
+ * Reads from a local or remote file and returns an array with 'header' and 'data' elements
+ *
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $array An array with the element 'header' and 'data
+ * @throws InvalidArrayCountException If an array has not the expected size
+ * @throws InvalidMD5ChecksumException If two MD5 hashes did not match
+ */
+ function loadFileContentsAsArray (SplFileInfo $infoInstance): array;
+
}
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-HANDLER: EXIT!');
}
- /** Loads data from a file over the input handler
+ /**
+ * Loads data from a file over the input handler
*
* @param $infoInstance An instance of a SplFileInfo class
* @return $content Raw file content
return $this->getInputStreamerInstance()->loadFileContents($infoInstance);
}
+ /**
+ * Loads data from a file over the input handler as array
+ *
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $array An array with the element 'header' and 'data
+ */
+ public function loadFileContentsAsArray (SplFileInfo $infoInstance): array {
+ // Read from the input handler
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-HANDLER: infoInstance=%s - CALLED!', $infoInstance->__toString()));
+ return $this->getInputStreamerInstance()->loadFileContentsAsArray($infoInstance);
+ }
+
/**
* Determines seek position
*