Java Path File List nio asPathsList(final File[] files)

Here you can find the source of asPathsList(final File[] files)

Description

Convert an array of java.io.File to a List of java.nio.file.Path

License

Open Source License

Parameter

Parameter Description
files An array of java.io.File

Return

If files is null or empty, then an empty list, otherwise a list of corresponding

Declaration

public static List<Path> asPathsList(final File[] files) 

Method Source Code


//package com.java2s;
/*/*  w  ww  .j  a  v a2s . co  m*/
 * eXist Open Source Native XML Database
 * Copyright (C) 2001-2015 The eXist Project
 * http://exist-db.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

import java.io.File;

import java.nio.file.*;

import java.util.*;

import java.util.stream.Collectors;

public class Main {
    /**
     * Convert an array of {@link java.io.File}
     * to a List of {@link java.nio.file.Path}
     *
     * @param files An array of {@link java.io.File}
     *
     * @return If files is null or empty, then
     *  an empty list, otherwise a list of corresponding
     *  {@link java.nio.file.Path}
     */
    public static List<Path> asPathsList(final File[] files) {
        return Optional.ofNullable(files)
                .map(fs -> Arrays.stream(fs).map(File::toPath).collect(Collectors.toList()))
                .orElse(Collections.EMPTY_LIST);
    }
}

Related

  1. addNonEmptyLinesFromFile(final ArrayList result, final String path)
  2. anyPathMatcher(final ImmutableList pathMatchers)
  3. archive(Path archive, List targetFiles)
  4. asFileList(Object... paths)
  5. compileTreeWithErrors(JavaCompiler compiler, List options, File targetFolder, DiagnosticListener diagnosticListener, boolean addProcessorsToClasspath)
  6. deepListChildren(Path directory)
  7. fileListDeep(Path dir)
  8. findExpectedResultForTestcase(final Path testcase, final LinkedList expectedResults)