Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
XRYFolder.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
20 
21 import java.io.IOException;
22 import java.io.UncheckedIOException;
23 import java.nio.file.Files;
24 import java.nio.file.LinkOption;
25 import java.nio.file.Path;
26 import java.nio.file.attribute.BasicFileAttributes;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.stream.Stream;
31 
35 final class XRYFolder {
36 
37  //Depth that will contain XRY files. All XRY files will be immediate
38  //children of their parent folder.
39  private static final int XRY_FILES_DEPTH = 1;
40 
41  //Raw path to the XRY folder.
42  private final Path xryFolderPath;
43 
44  public XRYFolder(Path folder) {
45  xryFolderPath = folder;
46  }
47 
56  public List<Path> getNonXRYFiles() throws IOException {
57  try (Stream<Path> allFiles = Files.walk(xryFolderPath, XRY_FILES_DEPTH)) {
58  List<Path> otherFiles = new ArrayList<>();
59  Iterator<Path> allFilesIterator = allFiles.iterator();
60  while (allFilesIterator.hasNext()) {
61  Path currentPath = allFilesIterator.next();
62  if (!currentPath.equals(xryFolderPath)
63  && !XRYFileReader.isXRYFile(currentPath)) {
64  otherFiles.add(currentPath);
65  }
66  }
67  return otherFiles;
68  } catch (UncheckedIOException ex) {
69  throw ex.getCause();
70  }
71  }
72 
80  public List<XRYFileReader> getXRYFileReaders() throws IOException {
81  try (Stream<Path> allFiles = Files.walk(xryFolderPath, XRY_FILES_DEPTH)) {
82  List<XRYFileReader> fileReaders = new ArrayList<>();
83 
84  Iterator<Path> allFilesIterator = allFiles.iterator();
85  while (allFilesIterator.hasNext()) {
86  Path currentFile = allFilesIterator.next();
87  if (XRYFileReader.isXRYFile(currentFile)) {
88  fileReaders.add(new XRYFileReader(currentFile));
89  }
90  }
91  return fileReaders;
92  } catch (UncheckedIOException ex) {
93  throw ex.getCause();
94  }
95  }
96 
112  public static boolean isXRYFolder(Path folder) throws IOException {
113  BasicFileAttributes attr = Files.readAttributes(folder,
114  BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
115 
116  if (!attr.isDirectory()) {
117  return false;
118  }
119 
120  //Files.walk by default will not follow symbolic links.
121  try (Stream<Path> allFiles = Files.walk(folder, XRY_FILES_DEPTH)) {
122  Iterator<Path> allFilesIterator = allFiles.iterator();
123  while (allFilesIterator.hasNext()) {
124  Path currentFile = allFilesIterator.next();
125  if (XRYFileReader.isXRYFile(currentFile)) {
126  return true;
127  }
128  }
129 
130  return false;
131  } catch (UncheckedIOException ex) {
132  throw ex.getCause();
133  }
134  }
135 }

Copyright © 2012-2022 Basis Technology. Generated on: Mon Sep 26 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.