Example usage for java.nio.file FileSystems getDefault

List of usage examples for java.nio.file FileSystems getDefault

Introduction

In this page you can find the example usage for java.nio.file FileSystems getDefault.

Prototype

public static FileSystem getDefault() 

Source Link

Document

Returns the default FileSystem .

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:/home/docs/users.txt");
    FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
    UserPrincipal userPrincipal = view.getOwner();

    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
    userPrincipal = lookupService.lookupPrincipalByName("users");
    view.setOwner(userPrincipal);//from ww w . ja v a  2s .c om
    System.out.println("UserPrincipal set: " + userPrincipal.getName());

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    Path path = Paths.get("C:\\Java_Dev\\test1.txt");

    FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);

    UserPrincipal owner = foav.getOwner();
    System.out.format("Original owner  of  %s  is %s%n", path, owner.getName());

    FileSystem fs = FileSystems.getDefault();
    UserPrincipalLookupService upls = fs.getUserPrincipalLookupService();

    UserPrincipal newOwner = upls.lookupPrincipalByName("brice");
    foav.setOwner(newOwner);//from w ww .j a v a  2 s  .  c  o m

    UserPrincipal changedOwner = foav.getOwner();
    System.out.format("New owner  of  %s  is %s%n", path, changedOwner.getName());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:\\Java_Dev\\test1.txt");

    AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
    if (aclView == null) {
        System.out.format("ACL view  is not  supported.%n");
        return;/*from  w  ww . j a  va2s .  c  o m*/
    }
    UserPrincipal bRiceUser = FileSystems.getDefault().getUserPrincipalLookupService()
            .lookupPrincipalByName("brice");

    Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA,
            AclEntryPermission.WRITE_DATA);

    AclEntry.Builder builder = AclEntry.newBuilder();
    builder.setPrincipal(bRiceUser);
    builder.setType(AclEntryType.ALLOW);
    builder.setPermissions(permissions);
    AclEntry newEntry = builder.build();

    List<AclEntry> aclEntries = aclView.getAcl();

    aclEntries.add(newEntry);

    aclView.setAcl(aclEntries);
}

From source file:net.sourceforge.pmd.docs.GenerateRuleDocsCmd.java

public static void main(String[] args) throws RuleSetNotFoundException {
    long start = System.currentTimeMillis();
    Path output = FileSystems.getDefault().getPath(args[0]).resolve("..").toAbsolutePath().normalize();
    System.out.println("Generating docs into " + output);

    RuleSetFactory ruleSetFactory = new RuleSetFactory();
    Iterator<RuleSet> registeredRuleSets = ruleSetFactory.getRegisteredRuleSets();
    List<String> additionalRulesets = findAdditionalRulesets(output);

    RuleDocGenerator generator = new RuleDocGenerator(new DefaultFileWriter(), output);
    generator.generate(registeredRuleSets, additionalRulesets);

    System.out.println("Generated docs in " + (System.currentTimeMillis() - start) + " ms");
}

From source file:csv.sorting.PrepareWeatherData.java

public static void main(String[] args) throws Exception {

    // Path to read the CSV data from:
    final Path csvStationDataFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503station.txt");
    final Path csvLocalWeatherDataUnsortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly.txt");
    final Path csvLocalWeatherDataSortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly_sorted.txt");

    // A map between the WBAN and Station for faster Lookups:
    final Map<String, Station> stationMap = getStationMap(csvStationDataFilePath);

    // Holds the List of Sorted DateTimes (including ZoneOffset):
    List<Integer> indices = new ArrayList<>();

    // Comparator for sorting the File:
    Comparator<OffsetDateTime> byMeasurementTime = (e1, e2) -> e1.compareTo(e2);

    // Get the sorted indices from the stream of LocalWeatherData Elements:
    try (Stream<CsvMappingResult<csv.model.LocalWeatherData>> stream = getLocalWeatherData(
            csvLocalWeatherDataUnsortedFilePath)) {

        // Holds the current line index, when processing the input Stream:
        AtomicInteger currentIndex = new AtomicInteger(1);

        // We want to get a list of indices, which sorts the CSV file by measurement time:
        indices = stream/* w w w  .  j ava 2s.co m*/
                // Skip the CSV Header:
                .skip(1)
                // Start by enumerating ALL mapping results:
                .map(x -> new ImmutablePair<>(currentIndex.getAndAdd(1), x))
                // Then only take those lines, that are actually valid:
                .filter(x -> x.getRight().isValid())
                // Now take the parsed entity from the CsvMappingResult:
                .map(x -> new ImmutablePair<>(x.getLeft(), x.getRight().getResult()))
                // Take only those measurements, that are also available in the list of stations:
                .filter(x -> stationMap.containsKey(x.getRight().getWban()))
                // Get the OffsetDateTime from the LocalWeatherData, which includes the ZoneOffset of the Station:
                .map(x -> {
                    // Get the matching station:
                    csv.model.Station station = stationMap.get(x.getRight().getWban());
                    // Calculate the OffsetDateTime from the given measurement:
                    OffsetDateTime measurementTime = OffsetDateTime.of(x.getRight().getDate(),
                            x.getRight().getTime(), ZoneOffset.ofHours(0));
                    // Build the Immutable pair with the Index again:
                    return new ImmutablePair<>(x.getLeft(), measurementTime);
                })
                // Now sort the Measurements by their Timestamp:
                .sorted((x, y) -> byMeasurementTime.compare(x.getRight(), y.getRight()))
                // Take only the Index:
                .map(x -> x.getLeft())
                // And turn it into a List:
                .collect(Collectors.toList());
    }

    // Now sorts the File by Line Number:
    writeSortedFileByIndices(csvLocalWeatherDataUnsortedFilePath, indices, csvLocalWeatherDataSortedFilePath);
}

From source file:io.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java

public static void main(String[] args) throws Exception {
    Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv");
    Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv");
    BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8);
    BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8);
    Random rand = new Random();
    int sequenceNumber = 0;
    for (int i = 0; i < 20; i++) {
        int product = rand.nextInt(10);
        UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build();
        for (int j = 0; j < 20; j++) {
            double value = rand.nextDouble();
            buildData.write("2016010101");
            buildData.write('\t');
            buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data
            buildData.write('\t');
            buildData.write(Integer.toString(product)); // product dimension
            buildData.write('\t');
            buildData.write(Double.toString(value));
            buildData.newLine();/*from w  ww .j  a v  a2 s  .  co m*/
            sketch.update(value);
            sequenceNumber++;
        }
        sketchData.write("2016010101");
        sketchData.write('\t');
        sketchData.write(Integer.toString(product)); // product dimension
        sketchData.write('\t');
        sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true)));
        sketchData.newLine();
    }
    buildData.close();
    sketchData.close();
}

From source file:org.apache.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java

public static void main(String[] args) throws Exception {
    Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv");
    Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv");
    BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8);
    BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8);
    Random rand = ThreadLocalRandom.current();
    int sequenceNumber = 0;
    for (int i = 0; i < 20; i++) {
        int product = rand.nextInt(10);
        UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build();
        for (int j = 0; j < 20; j++) {
            double value = rand.nextDouble();
            buildData.write("2016010101");
            buildData.write('\t');
            buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data
            buildData.write('\t');
            buildData.write(Integer.toString(product)); // product dimension
            buildData.write('\t');
            buildData.write(Double.toString(value));
            buildData.newLine();/*w w w  .  ja  va 2  s .  co  m*/
            sketch.update(value);
            sequenceNumber++;
        }
        sketchData.write("2016010101");
        sketchData.write('\t');
        sketchData.write(Integer.toString(product)); // product dimension
        sketchData.write('\t');
        sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true)));
        sketchData.newLine();
    }
    buildData.close();
    sketchData.close();
}

From source file:Search.java

public static void main(String[] args) throws IOException {

    Path searchFile = Paths.get("Demo.jpg");
    Search walk = new Search(searchFile);
    EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);

    Iterable<Path> dirs = FileSystems.getDefault().getRootDirectories();
    for (Path root : dirs) {
        if (!walk.found) {
            Files.walkFileTree(root, opts, Integer.MAX_VALUE, walk);
        }//ww  w. j av  a 2  s .  co  m
    }

    if (!walk.found) {
        System.out.println("The file " + searchFile + " was not found!");
    }
}

From source file:com.octo.mbo.CopyNotes.java

public static void main(String[] args) throws JAXBException, IOException {
    try {/*  w  w w.jav  a2 s  . com*/
        CommandLine cli = parseCommandLine(args);

        final String srcFilePath = cli.getOptionValue("s");
        final String targetFilePath = cli.getOptionValue("t");

        //Dependency injection
        com.octo.mbo.io.Util util = new Util();
        Loader loader = new Loader(new XmlPackageFactory(), new Pptx4jPackageFactory(), util);
        Processor processor = new Processor(new Merger(), loader, new SlideUpdator(), new XmlPackageFactory(),
                util);
        Orchestrator orchestrator = new Orchestrator(loader, processor);
        orchestrator.run(srcFilePath, targetFilePath, FileSystems.getDefault());

    } catch (CommandLineException clex) {
        log.debug("Error parsing the command line. Please use CopyComment --help", clex);
        //Error messages are already printed by the parseCommandeLine() method
        log.error(clex.getMessage());
        System.exit(-1);
    } catch (CopyNotesException ccex) {
        log.error("Internal error processing the document. Exiting", ccex);
        System.exit(-1);
    }
}

From source file:com.nexmo.client.examples.TestVoiceCall.java

public static void main(String[] argv) throws Exception {
    Options options = new Options().addOption("v", "Verbosity")
            .addOption("f", "from", true, "Phone number to call from")
            .addOption("t", "to", true, "Phone number to call")
            .addOption("h", "webhook", true, "URL to call for instructions");
    CommandLineParser parser = new DefaultParser();

    CommandLine cli;/* ww  w  .  j  a  va2  s .  c o  m*/
    try {
        cli = parser.parse(options, argv);
    } catch (ParseException exc) {
        System.err.println("Parsing failed: " + exc.getMessage());
        System.exit(128);
        return;
    }

    Queue<String> args = new LinkedList<String>(cli.getArgList());
    String from = cli.getOptionValue("f");
    String to = cli.getOptionValue("t");
    System.out.println("From: " + from);
    System.out.println("To: " + to);

    NexmoClient client = new NexmoClient(new JWTAuthMethod("951614e0-eec4-4087-a6b1-3f4c2f169cb0",
            FileSystems.getDefault().getPath("valid_application_key.pem")));
    client.getVoiceClient().createCall(
            new Call(to, from, "https://nexmo-community.github.io/ncco-examples/first_call_talk.json"));
}