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:com.netflix.spinnaker.halyard.config.config.v1.AtomicFileWriter.java

public AtomicFileWriter(Path path) throws IOException {
    FileSystem defaultFileSystem = FileSystems.getDefault();
    this.path = path;
    path.getParent().toFile().mkdir();//from   w w  w  .j av a 2 s .  c o  m
    String tmpDir = System.getProperty("java.io.tmpdir");
    this.tmpPath = defaultFileSystem.getPath(tmpDir, UUID.randomUUID().toString());
    this.writer = Files.newBufferedWriter(this.tmpPath, UTF_8, WRITE, APPEND, CREATE);
}

From source file:com.kamike.misc.FsUtils.java

public static void createDir(String dstPath) {
    Properties props = System.getProperties(); //    
    String osName = props.getProperty("os.name"); //???   
    Path newdir = FileSystems.getDefault().getPath(dstPath);

    boolean pathExists = Files.exists(newdir, new LinkOption[] { LinkOption.NOFOLLOW_LINKS });
    if (!pathExists) {
        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx");
        FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
        try {//from ww  w .  j ava 2 s. c  om
            if (!osName.contains("Windows")) {
                Files.createDirectories(newdir, attr);
            } else {
                Files.createDirectories(newdir);
            }
        } catch (Exception e) {
            System.err.println(e);

        }
    }
}

From source file:com.nsn.squirrel.tab.utils.PathUtils.java

/**
 * @param path/*w  w w  .  ja  va2 s. c  o m*/
 * @return
 */
public static String getAttributesString(Path path) {

    Set<String> views = FileSystems.getDefault().supportedFileAttributeViews();
    if (views.contains("posix")) { //$NON-NLS-1$
        return getPosixAttributesString(path);
    } else {
        return getDosAttributesString(path);
    }
}

From source file:org.cryptomator.webdav.jackrabbit.DavLocatorFactoryImpl.java

DavLocatorFactoryImpl(String fsRoot, Cryptor cryptor) {
    this.fsRoot = FileSystems.getDefault().getPath(fsRoot);
    this.cryptor = cryptor;
    cryptor.addSensitiveDataSwipeListener(this);
}

From source file:it.polimi.diceH2020.launcher.FileService.java

public Stream<Path> getBaseSolutionsPath() {
    String strDir = settings.getSolInstanceDir();
    Path dir = FileSystems.getDefault().getPath(strDir);
    if (Files.notExists(dir)) {
        Path currentRelativePath = Paths.get("");
        dir = FileSystems.getDefault()
                .getPath(currentRelativePath.toAbsolutePath().toString() + File.pathSeparator + strDir);
    }/*from www  .  j  a  v a  2 s.c  om*/
    DirectoryStream<Path> stream;
    try {
        stream = Files.newDirectoryStream(dir, "*.{json}");
        return StreamSupport.stream(stream.spliterator(), false);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

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

private static void generateBucketTestData() throws Exception {
    double meanTest = 10;
    double meanControl = 10.2;
    Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv");
    try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
        Random rand = new Random();
        for (int i = 0; i < 1000; i++) {
            writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest);
            writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl);
        }/* ww w .  j  av a  2  s .  co  m*/
    }
}

From source file:resources.AnalysisResource.java

@POST
@Produces(MediaType.APPLICATION_JSON)//w  ww  .j a  v  a  2s  .c  o m
public Response analyze(@FormParam("image") String image, @FormParam("filter") String filter,
        @FormParam("type") String type) {
    try {
        if (filter == null || filter.isEmpty()) {
            filter = "Default";
        }
        System.out.println(image);
        String fileName = UUID.randomUUID().toString();
        java.nio.file.Path path = FileSystems.getDefault().getPath("tmp", fileName);
        if (!path.toFile().getParentFile().exists()) {
            path.toFile().mkdirs();
        }
        path.toFile().createNewFile();

        BufferedImage bufferedImage = null;
        if (image.startsWith("data:image")) {
            String base64Image = image.split(",")[1];
            byte[] decoded = Base64.decodeBase64(base64Image.getBytes());
            bufferedImage = ImageIO.read(new ByteArrayInputStream(decoded));
        } else {
            URL website = new URL(image);
            Files.copy(website.openStream(), path, StandardCopyOption.REPLACE_EXISTING);
            bufferedImage = ImageIO.read(new FileInputStream(path.toFile()));
        }

        ImagePlus imagePlus = new ImagePlus("theTitle", bufferedImage);

        Measurement measurementModel = new Measurement();
        List<String> selectedMeasurements = measurementModel.getMeasurementList();
        ApplicationMain applicationMain = new ApplicationMain(
                selectedMeasurements.toArray(new String[selectedMeasurements.size()]), filter, imagePlus,
                fileName);

        Result result = null;
        if (type == null || type.isEmpty() || type.equals("Analyze")) {
            result = applicationMain.analyseImage();
        } else if (type.equals("Count")) {
            result = applicationMain.countParticles();
        } else {
            return Response.status(Response.Status.BAD_REQUEST).entity("bad type provided").build();
        }

        Logger.getLogger(AnalysisResource.class.getName()).log(Level.INFO, "Deleting tmp file:{0}", fileName);
        path.toFile().delete();
        System.out.println("Number of ParticleResults:" + result.getParticleResults().size());
        return Response.ok(result.getParticleResults()).build();
    } catch (MalformedURLException ex) {
        Logger.getLogger(AnalysisResource.class.getName()).log(Level.SEVERE, null, ex);
        return Response.status(Response.Status.BAD_REQUEST).entity("bad uri provided").build();
    } catch (IOException ex) {
        Logger.getLogger(AnalysisResource.class.getName()).log(Level.SEVERE, null, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:nl.uva.contextualsuggestion.Ranker.java

public Ranker() throws IOException {
    indexPathString = configFile.getProperty("INDEX_PATH");
    ipath = FileSystems.getDefault().getPath(indexPathString);
    ireader = DirectoryReader.open(FSDirectory.open(ipath));
    iInfo = new IndexInfo(ireader);
}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testGetFilePath() {
    FileSystem fileSystem = FileSystems.getDefault();

    Path filePath = FileUtil.getFilePath("test", "test");

    Assert.assertEquals("test" + fileSystem.getSeparator() + "test", filePath.toString());
}

From source file:org.apache.tika.eval.ComparerBatchTest.java

@BeforeClass
public static void setUp() throws Exception {

    File inputRoot = new File(ComparerBatchTest.class.getResource("/test-dirs").toURI());
    dbDir = Files.createTempDirectory(inputRoot.toPath(), "tika-test-db-dir-");
    Map<String, String> args = new HashMap<>();
    Path db = FileSystems.getDefault().getPath(dbDir.toString(), "comparisons_test");
    args.put("-db", db.toString());

    //for debugging, you can use this to select only one file pair to load
    //args.put("-includeFilePat", "file8.*");
    /*// w w  w.  j  a  va2 s.  c o  m
            BatchProcessTestExecutor ex = new BatchProcessTestExecutor(COMPARER_PROCESS_CLASS, args,
        "/tika-batch-comparison-eval-config.xml");
            StreamStrings streamStrings = ex.execute();
            System.out.println(streamStrings.getErrString());
            System.out.println(streamStrings.getOutString());
            H2Util dbUtil = new H2Util(db);
            conn = dbUtil.getConnection();*/
}