Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:FileMangement.PathFinder.java

@SuppressWarnings("empty-statement")
public Path[] FileCreator(String filename, boolean m3uCheck) throws IOException {

    File paths = new File(filename);
    String[] pattern;// w w w .j a v a 2  s  .  c o  m

    if (m3uCheck != true) {
        pattern = patternCreator.patternCreator(true, false, false, false, 1);
    } else {
        pattern = new String[1];
        pattern[0] = "*.m3u";
    }

    String str = paths.toString();
    String slash = "\\";

    String s = new StringBuilder(str).append(slash).toString();
    Path startingDir = Paths.get(s);

    int i = 0;
    while (i < pattern.length) {
        Finder finder = new Finder(pattern[i]);
        Files.walkFileTree(startingDir, finder);

        listOfPaths = ArrayUtils.addAll(listOfPaths, NullCleaner(finder.returnArray()));
        finalTotal = finder.done(finalTotal);
        i++;
    }

    //    StringBuffer sb = new StringBuffer(listOfPaths[1].getFileName().toString());
    //  sb.delete(sb.length()-4,sb.length()) ;

    //  System.out.println(sb);

    //  System.out.println(Arrays.toString(listOfPaths));

    //   System.out.println("Total Matched Number of Files : " + finalTotal);

    return listOfPaths;
}

From source file:com.rom.jmultipatcher.Utils.java

public static void checkFilePermissions(final String filepath, final boolean canRead, final boolean canWrite) {
    final Path path = Paths.get(filepath);
    final File file = path.toFile();
    if (canRead && !file.canRead()) {
        throw new IllegalArgumentException("Can't read file" + filepath);
    }/*from ww w .ja  v a2 s .c o  m*/
    if (canWrite && !file.canWrite()) {
        throw new IllegalArgumentException("Can't write to file" + filepath);
    }
}

From source file:at.tfr.securefs.client.TestWebSocket.java

@Ignore
@Test/*from w w w.ja  v a2 s  .com*/
public void testSendFile() throws Exception {

    Path path = Paths.get(getClass().getResource("/test.txt").toURI());
    Message m = new Message(MessageType.OPEN, "test.txt");

    WebsocketHandler wh = new WebsocketHandler(new URI(localhost), m, path.getParent());
    wh.connectBlocking();
    synchronized (wh) {
        wh.wait(100000L);
    }

}

From source file:de.ifsr.adam.JSONStuff.java

/**
 * Imports a JSONArray from a JSON file.
 *
 * @param filePath The file path to the JSONArray you want to import.
 * @return//from   www .ja v a2s  .  c o  m
 */
public final static JSONArray importJSONArray(String filePath) {
    Path path = Paths.get(filePath);
    String jsonStr = new String();
    JSONArray result = null;
    try (final Scanner scanner = new Scanner(path, ENCODING.name())) {
        while (scanner.hasNext()) {
            jsonStr += scanner.nextLine();
        }
        result = new JSONArray(jsonStr);
    } catch (IOException e) {
        JSONStuff.log.error("Failed to find JSON File at: " + filePath, e);
    } catch (JSONException e) {
        JSONStuff.log.error("Not a valid JSON file at:" + filePath, e);
    }
    return result;
}

From source file:ch.uzh.phys.ecn.oboma.map.api.MapFactory.java

public static INodeMap buildDefaultSBBMap() throws Exception {
    NodeMap map = new NodeMap();
    Random rand = new Random();
    int stationCount = 0;
    int trainCount = 0;

    JSONParser parser = new JSONParser();

    try {//from  w w w  .  j  av a 2s  .  c  o  m
        JSONArray stations = (JSONArray) parser.parse(Files.newBufferedReader(Paths.get("data/stations.json")));
        for (Object o : stations) {
            JSONObject station = (JSONObject) o;

            String id = (String) station.get("id");
            String name = (String) station.get("name");
            JSONObject coord = (JSONObject) ((JSONObject) station.get("location")).get("wgs");
            Double lat = (Double) coord.get("y");
            Double lng = (Double) coord.get("x");

            Node node = new Node(id, name, lat, lng, 0, 0);
            map.add(node);
            stationCount++;

            LOGGER.info(String.format("Station Node %s (%s) added", id, name));
        }

        JSONArray connections = (JSONArray) parser
                .parse(Files.newBufferedReader(Paths.get("data/connections.json")));
        for (Object o : connections) {
            JSONObject connection = (JSONObject) o;

            String from = (String) connection.get("from");
            String to = (String) connection.get("to");
            int time = (int) ((long) connection.get("time"));

            String id1 = String.format("%s-%s", from, to);
            String name1 = String.format("Train %s - %s", from, to);
            String id2 = String.format("%s-%s", to, from);
            String name2 = String.format("Train %s - %s", to, from);
            int seats = rand.nextInt(1000) + 1;

            Node node1 = new TrainNode(id1, name1, 0, 0, time, seats);
            Node node2 = new TrainNode(id2, name2, 0, 0, time, seats);
            try {
                map.add(node1, from, to);
                map.add(node2, to, from);
                trainCount++;
                LOGGER.info(String.format("Train Node %s (%s -> %s) added (%d seats)", id1, from, to, seats));
            } catch (Exception pEx) {
                // either from or to do not exist
            }
        }

        LOGGER.info(String.format("%d stations added / %d trains added", stationCount, trainCount));
    } catch (Exception pEx) {
        throw new Exception("Could not build map", pEx);
    }

    return map;
}

From source file:audiomanagershell.commands.FavCommand.java

public FavCommand(Path appPath, Path reference) {
    super(reference);
    String OS = System.getProperty("os.name").toLowerCase();
    if (OS.equals("windows"))
        favFile = Paths.get(appPath.toString() + "\\" + "favList.txt");
    else//from  ww w  . j a  v a 2s. co m
        favFile = Paths.get(appPath.toString() + "/" + "favList");

}

From source file:io.undertow.server.handlers.file.ContentEncodedResourceTestCase.java

@BeforeClass
public static void setup() throws IOException {

    tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), DIR_NAME);

    final PathResourceManager resourceManager = new PathResourceManager(tmpDir, 10485760);
    DefaultServer//  ww w. j  a v a  2s  .c om
            .setRootHandler(
                    new ResourceHandler(resourceManager)
                            .setContentEncodedResourceManager(
                                    new ContentEncodedResourceManager(tmpDir,
                                            new CachingResourceManager(100, 10000, null, resourceManager, -1),
                                            new ContentEncodingRepository().addEncodingHandler("deflate",
                                                    new DeflateEncodingProvider(), 50, null),
                                            0, 100000, null)));
}

From source file:org.openbaton.vnfm.generic.utils.LogDispatcher.java

private static List<String> readFile(String path, Charset encoding) throws IOException {
    try {// w w w .j a va  2 s  .c  om

        return Files.readAllLines(Paths.get(path), encoding);
    } catch (java.nio.file.NoSuchFileException e) {
        return new ArrayList<>();
    }
    //        return new String(encoded, encoding);
}

From source file:download.XBRLFileCleaner.java

/**
 * Deletes all non xbrl file in the, master directory
 *
 * @throws java.io.IOException/*from   w w w.  j a  va2s .c o m*/
 */
public void deleteNonXBRLFiles() throws IOException {
    File masterDirectory = new File(XBRLFilePaths.XBRL_FILING_DIRECTORY);

    // lists all files that are not directories except rfd object files
    Collection<File> files = FileUtils.listFiles(masterDirectory, new String[] { "zip", "xdr", "xsd", "xml" },
            true);

    // deletes the files that are not xbrl files
    for (File file : files) {
        if (!isXBRLFile(file.getName())) {
            Files.delete(Paths.get(file.getAbsolutePath()));
        } else {
            file.renameTo(
                    new File(file.getParent() + File.separatorChar + file.getParentFile().getName() + ".xml"));
        }
    }

}

From source file:com.fizzed.blaze.jdk.BlazeJdkEngineTest.java

@BeforeClass
static public void clearCache() throws IOException {
    Context context = new ContextImpl(null, Paths.get(System.getProperty("user.home")), null, null);
    Path classesDir = ConfigHelper.userBlazeEngineDir(context, "java");
    FileUtils.deleteDirectory(classesDir.toFile());
}