-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d426dc
commit 8031bc3
Showing
7 changed files
with
55 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
...ensor-collector/src/main/java/io/pravega/sensor/collector/rawfile/FileNameWithOffset.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/util/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.pravega.sensor.collector.util; | ||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
public class FileUtils { | ||
|
||
final static String separator = ","; | ||
|
||
/** | ||
* @return list of file name and file size in bytes | ||
*/ | ||
static public List<FileNameWithOffset> getDirectoryListing(String fileSpec, String fileExtension) throws IOException { | ||
String[] directories= fileSpec.split(separator); | ||
List<FileNameWithOffset> directoryListing = new ArrayList<>(); | ||
for (String directory : directories) { | ||
final Path pathSpec = Paths.get(directory); | ||
getDirectoryFiles(pathSpec, fileExtension, directoryListing); | ||
} | ||
return directoryListing; | ||
} | ||
|
||
/** | ||
* @return get all files in directory(including subdirectories) and their respective file size in bytes | ||
*/ | ||
static protected void getDirectoryFiles(Path dirPath, String fileExtension, List<FileNameWithOffset> directoryListing) throws IOException{ | ||
try(DirectoryStream<Path> dirStream=Files.newDirectoryStream(dirPath)){ | ||
for(Path path: dirStream){ | ||
if(Files.isDirectory(path)) | ||
getDirectoryFiles(path, fileExtension, directoryListing); | ||
else { | ||
FileNameWithOffset fileEntry = new FileNameWithOffset(path.toAbsolutePath().toString(), path.toFile().length()); | ||
// If extension is null, ingest all files | ||
if(fileExtension.isEmpty() || fileExtension.equals(fileEntry.fileName.substring(fileEntry.fileName.lastIndexOf(".")+1))) | ||
directoryListing.add(fileEntry); | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
|
||
} |