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:com.wondersgroup.cloud.deployment.file.FileServerHandler.java

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    HttpRequest request = (HttpRequest) e.getMessage();
    if (request.getMethod() != GET) {
        sendError(ctx, METHOD_NOT_ALLOWED);
        return;//from   w w w  . j a va  2 s.c  o  m
    }

    String srcPath = request.getHeader("srcPath");
    String ipList = request.getHeader("ipList");
    // ??app test: D:\cloud-deploy\DSC01575.JPG
    final String path = srcPath;// sanitizeUri(request.getUri()); "D:\\cloud-deploy\\AppTest.war";// 
    if (path == null) {
        sendError(ctx, FORBIDDEN);
        return;
    }

    File file = new File(path);
    if (file.isHidden() || !file.exists()) {
        sendError(ctx, NOT_FOUND);
        return;
    }
    if (!file.isFile()) {
        sendError(ctx, FORBIDDEN);
        return;
    }

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

    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    setContentLength(response, fileLength);

    response.setHeader("Content-disposition", "attachment;filename=" + file.getName());

    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", path, current, total, amount);
            }
        });
    }

    // Decide whether to close the connection or not.
    if (!isKeepAlive(request)) {
        // Close the connection when the whole content is written out.
        writeFuture.addListener(ChannelFutureListener.CLOSE);
    }
}

From source file:io.stallion.asyncTasks.AsyncTaskFilePersister.java

@Override
public void deleteOldTasks() {
    File dir = new File(getBucketFolderPath() + "/completed");
    Long before = DateUtils.utcNow().minusDays(40).toInstant().toEpochMilli();
    for (File f : dir.listFiles()) {
        if (!f.isFile() || f.isHidden()) {
            continue;
        }//w  ww  .  j  a v a2 s . co  m
        if (f.getName().startsWith(".") || f.getName().startsWith("~") || f.getName().startsWith("#")) {
            continue;
        }
        if (f.getName().endsWith(".json")) {
            continue;
        }
        if (f.lastModified() < before) {
            f.delete();
        }
    }

}

From source file:hu.bme.mit.sette.common.validator.FileValidator.java

/**
 * Sets whether the file should be hidden or not.
 *
 * @param isHidden//from  ww  w. j  a v a 2s. c  o  m
 *            true if the file should be hidden, false if it should not be
 * @return this object
 */
public FileValidator hidden(final boolean isHidden) {
    if (getSubject() != null) {
        File file = getSubject();

        if (isHidden ^ file.isHidden()) {
            String must;

            if (isHidden) {
                must = "must";
            } else {
                must = "must not";
            }

            this.addException(String.format("The file %s be hidden", must));
        }
    }

    return this;
}

From source file:org.isatools.isacreator.formatmappingutility.loader.ExcelFileLoader.java

public Map<String, String[]> processFile(File f) {
    Map<String, String[]> columnHeaders = new ListOrderedMap<String, String[]>();
    Workbook w;/*from  w w w . j a v a 2  s. c om*/
    try {
        if (!f.isHidden()) {
            w = Workbook.getWorkbook(f);
            // Get the first sheet
            for (Sheet s : w.getSheets()) {

                int rowStart;
                try {
                    rowStart = Integer.parseInt(ISAcreatorProperties.getProperty("isacreator.rowOffset")) - 1;
                    System.out.println("Row offset is: " + rowStart);
                } catch (NumberFormatException nfe) {
                    System.out.println(nfe.getMessage());
                    rowStart = 0;
                }

                if (s.getRows() > 0) {

                    List<String> headersForSheet = new ArrayList<String>();
                    for (int j = 0; j < s.getColumns(); j++) {

                        String cellContents = s.getCell(j, rowStart).getContents();
                        if (!cellContents.trim().equals("")) {
                            headersForSheet.add(cellContents);
                        }
                    }

                    columnHeaders.put(s.getName(), headersForSheet.toArray(new String[headersForSheet.size()]));
                }
            }
        }

    } catch (BiffException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return columnHeaders;
}

From source file:org.saiku.adhoc.server.datasource.ClassPathResourceCDAManager.java

public void load() {
    datasources.clear();//from   w w w.  j a v a 2 s . c  o m
    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:com.thoughtworks.go.util.FileUtilTest.java

@Test
void shouldBeHiddenIfFileIsHidden() {
    File mockFile = Mockito.mock(File.class);
    Mockito.when(mockFile.isHidden()).thenReturn(true);
    assertThat(FileUtil.isHidden(mockFile)).isTrue();
}

From source file:org.nuxeo.labs.automation.helpers.FileUtils.java

/**
 * Returns an array of the full paths of all the non-hidden/non folder elements found at inFolderPath
 * /* w  ww. j ava  2s .c  o  m*/
 * @param inFolderPath
 * @return
 * @since 7.4
 */
public ArrayList<String> getFiles(String inFolderPath) {

    File folder = new File(inFolderPath);
    ArrayList<String> files = new ArrayList<String>();
    if (folder.exists() && folder.isDirectory()) {
        for (File f : folder.listFiles()) {
            if (f.isFile() && !f.isHidden()) {
                files.add(f.getAbsolutePath());
            }
        }
    }

    return files;
}

From source file:com.khubla.cbean.kvservice.fskv.FSKVService.java

@Override
public String[] list(CBeanKey cBeanKey) throws KVServiceException {
    File fileSystem = null;//from  w w w.  j  av  a2 s.  co  m
    try {
        /*
         * get a pooled connection
         */
        fileSystem = fileClientPool.borrowObject();
        /*
         * list
         */
        String[] ret = null;
        if (true == fileSystem.isDirectory()) {
            final File[] lst = fileSystem.listFiles();
            final List<String> l = new ArrayList<String>();
            for (final File file : lst) {
                if (false == file.isHidden()) {
                    if (file.isDirectory()) {
                        l.add(file.getName() + "/");
                    } else {
                        l.add(file.getName());
                    }
                }
            }
            ret = new String[lst.length];
            l.toArray(ret);
        }
        return ret;
    } catch (final Exception e) {
        throw new KVServiceException(e);
    } finally {
        try {
            if (null != fileSystem) {
                fileClientPool.returnObject(fileSystem);
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:appmain.AppMain.java

private List<File> getXMLFiles(File folder) {
    File[] xmlFiles = folder.listFiles((File pathname) -> {
        return pathname.isFile() && !pathname.isHidden()
                && (pathname.getName().endsWith(".xml") || pathname.getName().endsWith(".XML"));
    });/*from  w ww .j a va2s  .  c o m*/
    return Arrays.asList(xmlFiles);
}

From source file:org.nuxeo.labs.automation.helpers.FileUtils.java

/**
 * Returns an array of the full paths of all the non-hidden folder elements found at inFolderPath
 * /*w  w  w .j a v  a 2 s . c o m*/
 * @param inFolderPath
 * @return
 * @since 7.4
 */
public ArrayList<String> getFolders(String inFolderPath) {

    File folder = new File(inFolderPath);
    ArrayList<String> files = new ArrayList<String>();
    if (folder.exists() && folder.isDirectory()) {
        for (File f : folder.listFiles()) {
            if (f.isDirectory() && !f.isHidden()) {
                files.add(f.getAbsolutePath());
            }
        }
    }

    return files;
}