Example usage for java.io File isHidden

List of usage examples for java.io File isHidden

Introduction

In this page you can find the example usage for java.io File isHidden.

Prototype

public boolean isHidden() 

Source Link

Document

Tests whether the file named by this abstract pathname is a hidden file.

Usage

From source file:org.sonatype.flexmojos.plugin.source.SourceViewMojo.java

/**
 * Loop through source files in the directory and syntax highlight and/or copy them to the target directory.
 * //  w  w  w . j  a  v  a  2  s.  c  o  m
 * @param directory The source directory to process.
 * @param targetDirectory The directory where to store the output.
 */
protected void processDirectory(File directory, File targetDirectory) {
    getLog().debug("Processing directory " + directory.getName());

    // Loop through files in the directory
    for (File file : directory.listFiles((FileFilter) filter)) {
        // Skip hidden files
        if (!file.isHidden() && !file.getName().startsWith(".")) {
            if (file.isDirectory()) {
                File newTargetDirectory = new File(targetDirectory, file.getName());
                newTargetDirectory.mkdir();
                processDirectory(file, newTargetDirectory);
            } else {
                try {
                    processFile(file, targetDirectory);
                } catch (IOException e) {
                    getLog().warn("Error while processing " + file.getName(), e);
                }
            }
        }
    }
}

From source file:org.pensco.CreateChecksOp.java

@OperationMethod
public void run() throws IOException {

    log.warn("Creating checks...");

    if (howMany < 1) {
        throw new RuntimeException("Less than 1 check, really?");
    }//from   w ww . j  av a 2  s.  c  o m

    parentPath = checksFolderDoc.getPathAsString();

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    if (deletePrevious) {
        log.warn("Deleting previous checks...");
        MiscUtils.deleteWithQuery(session, "SELECT * FROM Document WHERE ac:kind = 'Check'", "checks");
    }

    firstLastNames = RandomFirstLastNames.getInstance();

    File parentFolder = new File(pathToBaseChecks);
    File[] allFiles = parentFolder.listFiles();
    ArrayList<File> bases = new ArrayList<File>();
    for (File oneFile : allFiles) {
        if (!oneFile.isHidden()) {
            bases.add(oneFile);
        }
    }
    int maxBases = bases.size() - 1;

    for (int i = 1; i <= howMany; ++i) {

        createOneCheck(bases.get(ToolsMisc.randomInt(0, maxBases)));

        if ((i % MODULO_FOR_COMMIT) == 0) {
            log.warn("Created: " + i + "/" + howMany);
            TransactionHelper.commitOrRollbackTransaction();
            TransactionHelper.startTransaction();
        }
    }

    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();

    log.warn("Creating checks: Done");

    RandomFirstLastNames.release();

}

From source file:org.saiku.adhoc.providers.impl.standalone.StandaloneCdaProvider.java

public void load() {
    datasources.clear();/*from   ww  w  . j  ava2  s .  c om*/
    try {
        if (repoURL != null) {
            File[] files = new File(repoURL.getFile()).listFiles();

            for (File file : files) {
                if (!file.isHidden()) {
                    if (getFileExtension(file.getAbsolutePath()) != null
                            && getFileExtension(file.getAbsolutePath()).equalsIgnoreCase("cda")) {

                        InputStream is = new FileInputStream(file);

                        long length = file.length();
                        if (length > Integer.MAX_VALUE) {
                            // File is too large
                        }

                        byte[] bytes = new byte[(int) length];

                        int offset = 0;
                        int numRead = 0;
                        while (offset < bytes.length
                                && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
                            offset += numRead;
                        }
                        if (offset < bytes.length) {
                            throw new IOException("Could not completely read file " + file.getName());
                        }
                        is.close();

                        SaikuCda ds = new SaikuCda(file.getCanonicalPath(), file.getName(), bytes);
                        datasources.put(file.getName(), ds);
                        //}
                    }
                }
            }
        } else {
            throw new Exception("repo URL is null");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:webhooks.core.services.impl.DocumentServiceImp.java

private Document convertToDocument(File fileEntry) {
    Document doc = null;/*from   ww  w .  j  a  v  a2  s. c om*/
    if (!fileEntry.isHidden()) {
        doc = new Document();
        doc.setName(fileEntry.getName());
        //doc.setLocation(fileEntry.getPath());
        String now = String.valueOf(new Date().getTime());
        // fullpath + # + timestamp(long)
        doc.setId(CipherUtil.encrypt(fileEntry.getPath() + "#" + now));
        // get mime type of a document
        if (fileEntry.isFile()) {
            try {
                String mimeType = getMimeType(fileEntry.toPath());
                doc.setMimeType(mimeType);
            } catch (IOException e) {
                e.printStackTrace();
            }

            doc.setSize(fileEntry.length());
            doc.setKind(Document.TYPE_FILE);
        } else {
            doc.setKind(Document.TYPE_FOLDER);
        }
        doc.setLastModified(fileEntry.lastModified());
    }

    return doc;
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

public static boolean isPathAccessible(String dir, SharedPreferences pref) {
    File f = new File(dir);
    boolean showIfHidden = pref.getBoolean(PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES, false),
            isDirSelfOrParent = dir.endsWith("/.") || dir.endsWith("/.."),
            showIfRoot = pref.getBoolean(PreferencesConstants.PREFERENCE_ROOTMODE, false);

    return f.exists() && f.isDirectory() && (!f.isHidden() || (showIfHidden && !isDirSelfOrParent))
            && (!isRoot(dir) || showIfRoot);

    // TODO: 2/5/2017 use another system that doesn't create new object
}

From source file:com.eincs.decanter.handler.StaticFileHandler.java

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {

    if (!(e.getMessage() instanceof DecanterRequest)) {
        super.messageReceived(ctx, e);
        return;/* w w w .  j a va  2  s  .  c  o m*/
    }

    final DecanterRequest request = (DecanterRequest) e.getMessage();
    final String path = request.getPath();
    if (!path.startsWith(this.path)) {
        super.messageReceived(ctx, e);
        return;
    }

    if (request.getMethod() != GET) {
        DecanterChannels.writeError(ctx, request, METHOD_NOT_ALLOWED);
        return;
    }

    final String subPath = path.substring(this.path.length());
    final String filePath = sanitizeUri(directory, subPath);
    if (filePath == null) {
        DecanterChannels.writeError(ctx, request, FORBIDDEN);
        return;
    }

    final File file = new File(filePath);
    if (file.isHidden() || !file.exists()) {
        DecanterChannels.writeError(ctx, request, NOT_FOUND);
        return;
    }

    if (!file.isFile()) {
        DecanterChannels.writeError(ctx, request, FORBIDDEN);
        return;
    }

    // Cache Validation
    String ifModifiedSince = request.getHeaders().get(IF_MODIFIED_SINCE);
    if (ifModifiedSince != null && ifModifiedSince.length() != 0) {
        Date ifModifiedSinceDate = HttpHeaderValues.parseDate(ifModifiedSince);

        // Only compare up to the second because the datetime format we send
        // to the client does
        // not have milliseconds
        long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000;
        long fileLastModifiedSeconds = file.lastModified() / 1000;
        if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
            DecanterChannels.writeNotModified(ctx, request);
            return;
        }
    }

    RandomAccessFile raf;
    try {
        raf = new RandomAccessFile(file, "r");
    } catch (FileNotFoundException fnfe) {
        DecanterChannels.writeError(ctx, request, NOT_FOUND);
        return;
    }
    long fileLength = raf.length();

    // Add cache headers
    long timeMillis = System.currentTimeMillis();
    long expireMillis = timeMillis + HTTP_CACHE_SECONDS * 1000;
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.setHeader(CONTENT_TYPE, DecanterContentType.create(file));
    response.setHeader(CONTENT_LENGTH, String.valueOf(fileLength));
    response.setHeader(DATE, HttpHeaderValues.getCurrentDate());
    response.setHeader(EXPIRES, HttpHeaderValues.getDateString(expireMillis));
    response.setHeader(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
    response.setHeader(LAST_MODIFIED, HttpHeaderValues.getDateString(file.lastModified()));

    Channel ch = e.getChannel();

    // Write the initial line and the header.
    ch.write(response);

    // Write the content.
    ChannelFuture writeFuture;
    if (ch.getPipeline().get(SslHandler.class) != null) {
        // Cannot use zero-copy with HTTPS.
        writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192));
    } else {
        // No encryption - use zero-copy.
        final FileRegion region = new DefaultFileRegion(raf.getChannel(), 0, fileLength);
        writeFuture = ch.write(region);
        writeFuture.addListener(new ChannelFutureProgressListener() {
            public void operationComplete(ChannelFuture future) {
                region.releaseExternalResources();
            }

            public void operationProgressed(ChannelFuture future, long amount, long current, long total) {
                System.out.printf("%s: %d / %d (+%d)%n", filePath, current, total, amount);
            }
        });
    }
}

From source file:cn.tycoon.lighttrans.fileManager.FilePickerFragment.java

/**
 * Used by the list to determine whether a file should be displayed or not.
 * Default behavior is to always display folders. If files can be selected,
 * then files are also displayed. Set the showHiddenFiles property to show
 * hidden file. Default behaviour is to hide hidden files. Override this method to enable other
 * filtering behaviour, like only displaying files with specific extensions (.zip, .txt, etc).
 *
 * @param file to maybe add. Can be either a directory or file.
 * @return True if item should be added to the list, false otherwise
 */// www. ja v a  2s  .  c  om
protected boolean isItemVisible(final File file) {
    if (!showHiddenItems && file.isHidden()) {
        return false;
    }
    return (isDir(file) || (mode == MODE_FILE || mode == MODE_FILE_AND_DIR));
}

From source file:com.dotcms.publisher.myTest.PushPublisher.java

/**
 * Does the work of compression and going recursive for nested directories
 * <p/>/* w w  w.  j ava 2  s .  co m*/
 *
 *
 * @param taos The archive
 * @param file The file to add to the archive
   * @param dir The directory that should serve as the parent directory in the archivew
 * @throws IOException
 */
private void addFilesToCompression(TarArchiveOutputStream taos, File file, String dir, String bundleRoot)
        throws IOException {
    if (!file.isHidden()) {
        // Create an entry for the file
        if (!dir.equals("."))
            taos.putArchiveEntry(new TarArchiveEntry(file, dir + File.separator + file.getName()));
        if (file.isFile()) {
            // Add the file to the archive
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
            IOUtils.copy(new FileInputStream(file), taos);
            taos.closeArchiveEntry();
            bis.close();
        } else if (file.isDirectory()) {
            //Logger.info(this.getClass(),file.getPath().substring(bundleRoot.length()));
            // close the archive entry
            if (!dir.equals("."))
                taos.closeArchiveEntry();
            // go through all the files in the directory and using recursion, add them to the archive
            for (File childFile : file.listFiles()) {
                addFilesToCompression(taos, childFile, file.getPath().substring(bundleRoot.length()),
                        bundleRoot);
            }
        }
    }

}

From source file:org.geotools.gce.imagemosaic.Utils.java

/**
 * @param testingDirectory//from  w  w w  . j ava2s .  co  m
 * @return
 * @throws IllegalArgumentException
 * @throws IOException
 */
public static String checkDirectory(String testingDirectory, boolean writable) throws IllegalArgumentException {

    File inDir = new File(testingDirectory);
    boolean failure = !inDir.exists() || !inDir.isDirectory() || inDir.isHidden() || !inDir.canRead();
    if (writable) {
        failure |= !inDir.canWrite();
    }
    if (failure) {
        String message = "Unable to create the mosaic\n" + "location is:" + testingDirectory + "\n"
                + "location exists:" + inDir.exists() + "\n" + "location is a directory:" + inDir.isDirectory()
                + "\n" + "location is writable:" + inDir.canWrite() + "\n" + "location is readable:"
                + inDir.canRead() + "\n" + "location is hidden:" + inDir.isHidden() + "\n";
        LOGGER.severe(message);
        throw new IllegalArgumentException(message);
    }
    try {
        testingDirectory = inDir.getCanonicalPath();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    testingDirectory = FilenameUtils.normalize(testingDirectory);
    if (!testingDirectory.endsWith(File.separator))
        testingDirectory = testingDirectory + File.separator;
    // test to see if things are still good
    inDir = new File(testingDirectory);
    failure = !inDir.exists() || !inDir.isDirectory() || inDir.isHidden() || !inDir.canRead();
    if (writable) {
        failure |= !inDir.canWrite();
    }
    if (failure) {
        String message = "Unable to create the mosaic\n" + "location is:" + testingDirectory + "\n"
                + "location exists:" + inDir.exists() + "\n" + "location is a directory:" + inDir.isDirectory()
                + "\n" + "location is writable:" + inDir.canWrite() + "\n" + "location is readable:"
                + inDir.canRead() + "\n" + "location is hidden:" + inDir.isHidden() + "\n";
        LOGGER.severe(message);
        throw new IllegalArgumentException(message);
    }
    return testingDirectory;
}

From source file:nicta.com.au.patent.document.CreateUnifiedDocuments.java

public boolean index(File dataDir, FileFilter filter) throws Exception {
    File[] listFiles = dataDir.listFiles();
    for (File file : listFiles) {
        if (file.isDirectory()) {
            if (index(file, filter) == true) {
                this.writeUnifiedPatentDocument(this.analyze(file), file);
            }/*from  www . ja va 2s .c o m*/
        } else {
            if (!file.isHidden() && file.exists() && file.canRead()
                    && (filter == null || filter.accept(file))) {
                return true;
            }
        }
    }
    return false;
}