Parse the 'du' output.

@param string $duOutput
@param array  $mountPaths

@return array A list of mount sizes (in bytes) keyed by mount path.
198811
private function parseDu($duOutput, array $mountPaths)
    {
        $mountSizes = [];
        $duOutputSplit = explode("\n", $duOutput, count($mountPaths));
        foreach ($mountPaths as $i => $mountPath) {
            if (!isset($duOutputSplit[$i])) {
                throw new \RuntimeException("Failed to find row $i of 'du' command output: \n" . $duOutput);
            }
            list($mountSizes[$mountPath],) = explode("\t", $duOutputSplit[$i], 2);
        }

        return $mountSizes;
    }
1354573
public function getSkrillAmount($stringFormat = false)
    {
        $amount = (double)$this->data['mb_amount'];

        if ($stringFormat) {
            $amount = number_format($amount, 2, '.', '');
        }

        return $amount;
    }
624236
public static List<UnixMountInfo> getUnixMountInfo() throws IOException {
    Preconditions.checkState(OSUtils.isLinux() || OSUtils.isMacOS());
    String output = execCommand(MOUNT_COMMAND);
    List<UnixMountInfo> mountInfo = new ArrayList<>();
    for (String line : output.split("\n")) {
      mountInfo.add(parseMountInfo(line));
    }
    return mountInfo;
  }
119821
public static function normalizeOutputsStruct(array $outputs) {
        $result = [];

        foreach ($outputs as $k => $v) {
            if (is_numeric($k)) {
                if (!is_array($v)) {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }

                if (isset($v['address']) && isset($v['value'])) {
                    $address = $v['address'];
                    $value = $v['value'];
                } elseif (count($v) == 2 && isset($v[0]) && isset($v[1])) {
                    $address = $v[0];
                    $value = $v[1];
                } else {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }
            } else {
                $address = $k;
                $value = $v;
            }

            $result[] = ['address' => $address, 'value' => $value];
        }

        return $result;
    }
88729
protected function splitUnionRemainder($queries, $unionType, $outputArray)
    {
        $finalQuery = [];

        //If this token contains a matching pair of brackets at the start and end, use it as the final query
        $finalQueryFound = false;
        if (count($outputArray) === 1) {
            $tokenAsArray = str_split(trim($outputArray[0]));
            if ($tokenAsArray[0] == '(' && $tokenAsArray[count($tokenAsArray)-1] == ')') {
                $queries[$unionType][] = $outputArray;
                $finalQueryFound = true;
            }
        }

        if (!$finalQueryFound) {
            foreach ($outputArray as $key => $token) {
                if (strtoupper($token) == 'ORDER') {
                    break;
                } else {
                    $finalQuery[] = $token;
                    unset($outputArray[$key]);
                }
            }
        }


        $finalQueryString = trim(implode($finalQuery));

        if (!empty($finalQuery) && $finalQueryString != '') {
            $queries[$unionType][] = $finalQuery;
        }

        $defaultProcessor = new DefaultProcessor($this->options);
        $rePrepareSqlString = trim(implode($outputArray));

        if (!empty($rePrepareSqlString)) {
            $remainingQueries = $defaultProcessor->process($rePrepareSqlString);
            $queries[] = $remainingQueries;
        }

        return $queries;
    }
1258448
protected void unpackXARToOutputDirectory(Artifact artifact, String[] includes, String[] excludes)
        throws MojoExecutionException
    {
        if (!this.outputBuildDirectory.exists()) {
            this.outputBuildDirectory.mkdirs();
        }

        File file = artifact.getFile();
        unpack(file, this.outputBuildDirectory, "XAR Plugin", false, includes, excludes);
    }
171029
public function parseListOutput($output, array $arguments = array())
    {
        if (!isset($arguments['--xml']) || false === $arguments['--xml']) {
            // non xml results are not supported
            return $output;
        }

        $head = $this->getClient()->getHead();

        $sxml = simplexml_load_string($output);

        $retval = array();
        foreach ($sxml->xpath('//entry') as $item) {
            $filename = (string) $item->name;
            $kind     = (string) $item->attributes()->kind;
            $revision = (string) $item->commit->attributes()->revision;
            $date     = (string) $item->commit->date;
            $author   = (string) $item->commit->author;

            $commit = new Commit($revision, new \DateTime($date), $author);

            $file = new VcsFileInfo($filename, $head, $kind);
            $file->setCommit($commit);

            $retval[] = $file;
        }

        return $retval;
    }
1366518
protected function getMountPoint(/*# string */ $path)/*# : string */
    {
        while ($path !== '') {
            if (isset($this->filesystems[$path])) {
                return $path;
            }
            $path = substr($path, 0, strrpos($path, '/'));
        }
        return '/';
    }
392687
private List<String> readDupAccounts(InputStream dupAccountsStream)
        throws IOException {
        ObjectMapper objMapper = new ObjectMapper();
        return objMapper.readValue(
            dupAccountsStream,
            new TypeReference<List<String>>() {
            });
    }
1084672
private function _filesystems()
    {
        if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
            $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
            if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
                $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
                foreach ($lines as $line) {
                    $a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
                    $fsdev[$a[0]] = $a[4];
                }
            }
            foreach ($mounts as $mount) {
                $ar_buf = preg_split("/\s+/", $mount, 6);
                $dev = new DiskDevice();
                $dev->setName($ar_buf[0]);
                $dev->setTotal($ar_buf[1] * 1024);
                $dev->setUsed($ar_buf[2] * 1024);
                $dev->setFree($ar_buf[3] * 1024);
                $dev->setMountPoint($ar_buf[5]);
                if (isset($fsdev[$ar_buf[0]])) {
                    $dev->setFsType($fsdev[$ar_buf[0]]);
                }
                $this->sys->setDiskDevices($dev);
            }
        }
    }
462489
private List<String> existingRWPaths() {
        String[] lines = mountReader();
        List<String> pathsFound = new ArrayList<>();
        for (String line : lines) {
            // Split lines into parts
            String[] args = line.split(" ");
            if (args.length < 4){
                // If we don't have enough options per line, skip this and log an error
                Log.e(TAG, String.format("Error formatting mount: %s", line));
                continue;
            }
            String mountPoint = args[1];
            String mountOptions = args[3];

            for (String pathToCheck : PATHS_THAT_SHOULD_NOT_BE_WRITABLE) {
                if (mountPoint.equalsIgnoreCase(pathToCheck)) {
                    // Split options out and compare against "rw" to avoid false positives
                    for (String option : mountOptions.split(",")){
                        if (option.equalsIgnoreCase("rw")){
                            pathsFound.add(pathToCheck);
                            break;
                        }
                    }
                }
            }
        }
        return pathsFound;
    }
1167106
private function parseOutputLines(array $outputLines)
    {
        $this->diffObjects = [];
        $splitArray = Utilities::pregSplitArray($outputLines, '/^diff --git SRC\/(.*) DST\/(.*)$/');
        foreach ($splitArray as $diffObjectLines) {
            $this->diffObjects[] = new DiffObject($diffObjectLines);
        }
    }
529497
public static function getImageResolution($filePath, $throwException = false)
    {
        $dimensions = @getimagesize(Yii::getAlias($filePath));
        
        $width = 0;
        $height = 0;
        
        if (isset($dimensions[0]) && isset($dimensions[1])) {
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];
        } elseif ($throwException) {
            throw new Exception("Unable to determine the resoltuions of the file $filePath.");
        }
        
        return [
            'width' => $width,
            'height' => $height,
        ];
    }
1341247
public function readStringMulti($delims, &$delimfound = null)
    {

        // Get position of delimiters
        $pos = [];
        foreach ($delims as $delim) {
            if ($p = strpos($this->data, $delim, min($this->index, $this->length))) {
                $pos[] = $p;
            }
        }

        // If none are found then return whole buffer
        if (empty($pos)) {
            return $this->read(strlen($this->data) - $this->index);
        }

        // Read the string and remove the delimiter
        sort($pos);
        $string = $this->read($pos[0] - $this->index);
        $delimfound = $this->read();

        return $string;
    }
1297545
public function parseStatusOutput($output, array $arguments = array())
    {
        if (!isset($arguments['--porcelain']) || false === $arguments['--porcelain']) {
            // non porcelain results are not supported
            return $output;
        }

        if ('' === trim($output)) {
            return array();
        }

        $lines = explode("\n", rtrim($output));

        $retval = array();
        foreach ($lines as $line) {
            if (preg_match('/([A-Z\?\s])([A-Z\?\s])\s(.*)( -> (.*))?/', $line, $matches)) {
                list($fullmatch, $x, $y, $file) = $matches;

                $file = new VcsFileInfo($file, $this->getClient()->getHead());
                $file->setStatus($x);

                $retval[] = $file;
            } else {
                throw new \Exception('Unable to parse line "'. $line . '"');
            }
        }

        return $retval;
    }
518777
private function parsePathsSettings(\DOMNode $paths) {

		if(is_null($this->paths)) {
			$this->paths = [];
		}

		foreach($paths->getElementsByTagName('path') as $path) {

			$id = $path->getAttribute('id');
			$subdir = $path->getAttribute('subdir') ?: '';

			if(!$id || !$subdir) {
				continue;
			}

			$subdir = '/' . trim($subdir, '/') . '/';

			// additional attributes are currently ignored

			$this->paths[$id] = ['subdir' => $subdir];

		}

	}
994537
private function parseAggregationsProviders(\DOMXPath $xpath, \DOMNode $rootNode)
    {
        $providers = [];

        foreach ($xpath->query(self::AGGREGATIONS_PROVIDERS_PATH, $rootNode) as $providerNode) {
            $providers[$providerNode->getAttribute('name')] = $providerNode->nodeValue;
        }

        return $providers;
    }