Example usage for java.nio.file Files isReadable

List of usage examples for java.nio.file Files isReadable

Introduction

In this page you can find the example usage for java.nio.file Files isReadable.

Prototype

public static boolean isReadable(Path path) 

Source Link

Document

Tests whether a file is readable.

Usage

From source file:ddf.security.samlp.MetadataConfigurationParser.java

private void parseEntityDescriptions(List<String> entityDescriptions) throws IOException {
    String ddfHome = System.getProperty("ddf.home");
    for (String entityDescription : entityDescriptions) {
        buildEntityDescriptor(entityDescription);
    }/*from  w ww  .j  av a2  s.  co m*/
    Path metadataFolder = Paths.get(ddfHome, ETC_FOLDER, METADATA_ROOT_FOLDER);
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(metadataFolder)) {
        for (Path path : directoryStream) {
            if (Files.isReadable(path)) {
                try (InputStream fileInputStream = Files.newInputStream(path)) {
                    EntityDescriptor entityDescriptor = readEntityDescriptor(
                            new InputStreamReader(fileInputStream, "UTF-8"));

                    LOGGER.error("parseEntityDescriptions:91 entityId = {}", entityDescriptor.getEntityID());
                    entityDescriptorMap.put(entityDescriptor.getEntityID(), entityDescriptor);
                    if (updateCallback != null) {
                        updateCallback.accept(entityDescriptor);
                    }
                }
            }
        }
    } catch (NoSuchFileException e) {
        LOGGER.debug("IDP metadata directory is not configured.", e);
    }
}

From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceConfig.java

private void checkOrientDBRootDir() {
    checkArgument(Files.exists(orientDBRootDir), PATH_DOES_NOT_EXIST, "orientDBRootDir", orientDBRootDir);
    checkArgument(Files.isDirectory(orientDBRootDir), PATH_IS_NOT_A_DIRECTORY, "orientDBRootDir",
            orientDBRootDir);//  w  w  w.  j a  va  2s.  c o m
    checkArgument(Files.isReadable(orientDBRootDir), PATH_IS_NOT_READABLE, "orientDBRootDir", orientDBRootDir);
    checkArgument(Files.isWritable(orientDBRootDir), PATH_IS_NOT_WRITEABLE, "orientDBRootDir", orientDBRootDir);
}

From source file:com.fpuna.preproceso.PreprocesoTS.java

/**
 * Metodo estatico que lee el archivo y lo carga en una estructura de hash
 *
 * @param Archivo path del archivo//from w  w w.j  ava2  s.c  om
 * @return Hash con las sessiones leida del archivo de TrainigSet
 */
public static HashMap<String, SessionTS> leerArchivo(String Archivo, String sensor) {

    HashMap<String, SessionTS> SessionsTotal = new HashMap<String, SessionTS>();
    HashMap<String, String> actividades = new HashMap<String, String>();
    Path file = Paths.get(Archivo);

    if (Files.exists(file) && Files.isReadable(file)) {

        try {
            BufferedReader reader = Files.newBufferedReader(file, Charset.defaultCharset());

            String line;
            int cabecera = 0;

            while ((line = reader.readLine()) != null) {
                if (line.contentEquals("statusId | label")) {

                    //Leo todos las actividades  
                    while ((line = reader.readLine()) != null
                            && !line.contentEquals("statusId|sensorName|value|timestamp")) {
                        String part[] = line.split("\\|");
                        actividades.put(part[0], part[1]);
                        SessionTS s = new SessionTS();
                        s.setActividad(part[1]);
                        SessionsTotal.put(part[0], s);
                    }
                    line = reader.readLine();
                }

                String lecturas[] = line.split("\\|");

                if (lecturas[1].contentEquals(sensor)) {
                    Registro reg = new Registro();
                    reg.setSensor(lecturas[1]);
                    String[] values = lecturas[2].split("\\,");

                    if (values.length == 3) {
                        reg.setValor_x(Double.parseDouble(values[0].substring(1)));
                        reg.setValor_y(Double.parseDouble(values[1]));
                        reg.setValor_z(Double.parseDouble(values[2].substring(0, values[2].length() - 1)));
                    } else if (values.length == 5) {
                        reg.setValor_x(Double.parseDouble(values[0].substring(1)));
                        reg.setValor_y(Double.parseDouble(values[1]));
                        reg.setValor_z(Double.parseDouble(values[2]));
                        reg.setM_1(Double.parseDouble(values[3]));
                        reg.setM_2(Double.parseDouble(values[4].substring(0, values[4].length() - 1)));
                    }

                    reg.setTiempo(new Timestamp(Long.parseLong(lecturas[3])));

                    SessionTS s = SessionsTotal.get(lecturas[0]);
                    s.addRegistro(reg);
                    SessionsTotal.replace(lecturas[0], s);
                }
            }
        } catch (IOException ex) {
            System.err.println("Okapu");
            Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    return SessionsTotal;
}

From source file:org.alfresco.repo.bulkimport.metadataloaders.AbstractMapBasedMetadataLoader.java

@Override
public final void loadMetadata(final ContentAndMetadata contentAndMetadata, Metadata metadata) {
    if (contentAndMetadata.metadataFileExists()) {
        final Path metadataFile = contentAndMetadata.getMetadataFile();

        if (Files.isReadable(metadataFile)) {
            Map<String, Serializable> metadataProperties = loadMetadataFromFile(metadataFile);

            for (String key : metadataProperties.keySet()) {
                if (PROPERTY_NAME_TYPE.equals(key)) {
                    String typeName = (String) metadataProperties.get(key);
                    QName type = QName.createQName(typeName, namespaceService);

                    metadata.setType(type);
                } else if (PROPERTY_NAME_ASPECTS.equals(key)) {
                    String[] aspectNames = ((String) metadataProperties.get(key)).split(",");

                    for (final String aspectName : aspectNames) {
                        QName aspect = QName.createQName(aspectName.trim(), namespaceService);
                        metadata.addAspect(aspect);
                    }//from   w w  w  .j av  a2 s.c o m
                } else // Any other key => property
                {
                    //####TODO: figure out how to handle properties of type cm:content - they need to be streamed in via a Writer 
                    QName name = QName.createQName(key, namespaceService);
                    PropertyDefinition propertyDefinition = dictionaryService.getProperty(name); // TODO: measure performance impact of this API call!!

                    if (propertyDefinition != null) {
                        if (propertyDefinition.isMultiValued()) {
                            // Multi-valued property
                            ArrayList<Serializable> values = new ArrayList<Serializable>(Arrays.asList(
                                    ((String) metadataProperties.get(key)).split(multiValuedSeparator)));
                            metadata.addProperty(name, values);
                        } else {
                            // Single value property
                            metadata.addProperty(name, metadataProperties.get(key));
                        }
                    } else {
                        if (log.isWarnEnabled())
                            log.warn("Property " + String.valueOf(name)
                                    + " doesn't exist in the Data Dictionary.  Ignoring it.");
                    }
                }
            }
        } else {
            if (log.isWarnEnabled())
                log.warn("Metadata file '" + FileUtils.getFileName(metadataFile) + "' is not readable.");
        }
    }
}

From source file:com.spotify.docker.client.CompressedDirectory.java

static ImmutableSet<PathMatcher> parseDockerIgnore(Path dockerIgnorePath) throws IOException {
    final ImmutableSet.Builder<PathMatcher> matchersBuilder = ImmutableSet.builder();

    if (Files.isReadable(dockerIgnorePath) && Files.isRegularFile(dockerIgnorePath)) {
        for (final String line : Files.readAllLines(dockerIgnorePath, StandardCharsets.UTF_8)) {
            final String pattern = line.trim();
            if (pattern.isEmpty()) {
                log.debug("Will skip '{}' - cause it's empty after trimming", line);
                continue;
            }//w w w.jav  a2 s.c o  m
            matchersBuilder.add(goPathMatcher(dockerIgnorePath.getFileSystem(), pattern));
        }
    }

    return matchersBuilder.build();
}

From source file:com.codealot.textstore.FileStore.java

private Path idToPath(final String id) throws IOException {
    final Path textPath = Paths.get(this.storeRoot, id);
    if (!Files.isReadable(textPath)) {
        throw new IOException("Id " + id + " has no readable content.");
    }/*w  ww. j a va 2  s.c  om*/
    return textPath;
}

From source file:org.cryptomator.cli.Args.java

public String getVaultPassword(String vaultName) {
    if (vaultPasswords.getProperty(vaultName) == null) {
        Path vaultPasswordPath = Paths.get(vaultPasswordFiles.getProperty(vaultName));
        if (Files.isReadable(vaultPasswordPath) && Files.isRegularFile(vaultPasswordPath)) {
            try (Stream<String> lines = Files.lines(vaultPasswordPath)) {
                return lines.findFirst().get().toString();
            } catch (IOException e) {
                return null;
            }//from ww w  . j  av a2 s .co  m
        }
        return null;
    }
    return vaultPasswords.getProperty(vaultName);
}

From source file:org.apache.pulsar.io.file.FileSourceConfig.java

public void validate() {
    if (StringUtils.isBlank(inputDirectory)) {
        throw new IllegalArgumentException("Required property not set.");
    } else if (Files.notExists(Paths.get(inputDirectory), LinkOption.NOFOLLOW_LINKS)) {
        throw new IllegalArgumentException("Specified input directory does not exist");
    } else if (!Files.isReadable(Paths.get(inputDirectory))) {
        throw new IllegalArgumentException("Specified input directory is not readable");
    } else if (Optional.ofNullable(keepFile).orElse(false) && !Files.isWritable(Paths.get(inputDirectory))) {
        throw new IllegalArgumentException("You have requested the consumed files to be deleted, but the "
                + "source directory is not writeable.");
    }/*from  w  w  w  .ja v  a 2  s .c o  m*/

    if (StringUtils.isNotBlank(fileFilter)) {
        try {
            Pattern.compile(fileFilter);
        } catch (final PatternSyntaxException psEx) {
            throw new IllegalArgumentException("Invalid Regex pattern provided for fileFilter");
        }
    }

    if (minimumFileAge != null && Math.signum(minimumFileAge) < 0) {
        throw new IllegalArgumentException("The property minimumFileAge must be non-negative");
    }

    if (maximumFileAge != null && Math.signum(maximumFileAge) < 0) {
        throw new IllegalArgumentException("The property maximumFileAge must be non-negative");
    }

    if (minimumSize != null && Math.signum(minimumSize) < 0) {
        throw new IllegalArgumentException("The property minimumSize must be non-negative");
    }

    if (maximumSize != null && Math.signum(maximumSize) < 0) {
        throw new IllegalArgumentException("The property maximumSize must be non-negative");
    }

    if (pollingInterval != null && pollingInterval <= 0) {
        throw new IllegalArgumentException("The property pollingInterval must be greater than zero");
    }

    if (numWorkers != null && numWorkers <= 0) {
        throw new IllegalArgumentException("The property numWorkers must be greater than zero");
    }
}

From source file:at.tfr.securefs.ws.FileServiceBean.java

/**
 * Delete file if it exists.// w  w w.  j  ava2 s.  c  o m
 * @param relPath
 * @return
 * @throws IOException
 * @see Files#deleteIfExists(java.nio.file.Path) 
 */
@WebMethod
@Override
public boolean delete(String relPath) throws IOException {
    try {
        Path path = SecureFileSystemBean.resolvePath(relPath, configuration.getBasePath(),
                configuration.isRestrictedToBasePath());
        if (!Files.isRegularFile(path) || !Files.isReadable(path)) {
            throw new IOException("invalid path: " + relPath);
        }
        log.debug("delete File: " + relPath + " as " + path);
        boolean deleted = Files.deleteIfExists(path);
        logInfo("deleted File: " + path + " : " + deleted, null);
        return deleted;
    } catch (Exception e) {
        logInfo("read File failed: " + relPath, e);
        log.warn("read File failed: " + relPath + e);
        throw e;
    }
}

From source file:org.roda.core.storage.fs.FileStorageService.java

private void initialize(Path path) throws GenericException {
    if (!FSUtils.exists(path)) {
        try {/* www  . j  a va  2  s  .co  m*/
            Files.createDirectories(path);
        } catch (IOException e) {
            throw new GenericException("Could not create path " + path, e);

        }
    } else if (!FSUtils.isDirectory(path)) {
        throw new GenericException("Path is not a directory " + path);
    } else if (!Files.isReadable(path)) {
        throw new GenericException("Cannot read from path " + path);
    } else if (!Files.isWritable(path)) {
        throw new GenericException("Cannot write to path " + path);
    } else {
        // do nothing
    }
}