Skip to content

Commit

Permalink
Working on the documentation for the extracor package files. Related to
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Alves Vieira committed May 3, 2013
1 parent f7479b3 commit b44a402
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ public static DefaultExtractor getInstance() {
}

private DefaultExtractor() {

}

/**
* Recursively extract files within a root file to a specified destination folder
* @param root the main file containing all the files to be extracted
* @param next
* @param destinationFolder the destination folder to which the extracted files will be moved to
*/
private void recursiveExtract(final File root, File next, final File destinationFolder) {
ExecutorService executor = Executors.newFixedThreadPool(Config.MAX_NUMBER_OF_THREADS);
File[] subFiles = next.listFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ public static DefaultUncompressor getInstance() {
}

private DefaultUncompressor() {

}

/**
* The compressed file extractor method that takes a compressed file and a destination folder
* and extracts the given file according to its compression format. The supported formats are declared
* in the formats class.
* @param file the compressed file to be extracted
* @param destinationFolder the folder to which the extracted file will be moved to
*/
public void uncompress(File file, File destinationFolder) {
String name = file.getName();
try {
Expand Down
2 changes: 1 addition & 1 deletion src/java/main/br/ufpe/cin/groundhog/extractor/Formats.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* This class verifies if a given file format is supported to extraction
*
* @author ghlp
* @author gustavopinto
*/
public class Formats {
private static Formats instance;
Expand Down
44 changes: 36 additions & 8 deletions src/java/main/br/ufpe/cin/groundhog/extractor/RarUncompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
import com.github.junrar.rarfile.FileHeader;

/**
*
* @author gustavopinto, rodrigoalvesvieira
* @author fjsj, gustavopinto, rodrigoalvesvieira
* Adapted from: https://github.com/edmund-wagner/junrar/blob/6f32323c983015d96c64084418793853f514b519/testutil/src/main/java/de/innosystec/unrar/testutil/ExtractArchive.java
* Original author: Edmund Wagner
*
*/
public class RarUncompressor {
private static Log logger = LogFactory.getLog(RarUncompressor.class
.getName());

/**
* Extracts an archive file to a specified destination directory
* @param archive the archive file to be extracted
* @param destination the directory to which the extracted file will be moved to
*/
public static void extract(File archive, File destination) {
destination.mkdirs();
Archive arch = null;
Expand All @@ -35,7 +38,7 @@ public static void extract(File archive, File destination) {
}
if (arch != null) {
if (arch.isEncrypted()) {
logger.warn("archive is encrypted cannot extreact");
logger.warn("archive is encrypted, cannot perform extraction");
return;
}
FileHeader fh = null;
Expand All @@ -45,7 +48,7 @@ public static void extract(File archive, File destination) {
break;
}
if (fh.isEncrypted()) {
logger.warn("file is encrypted cannot extract: "
logger.warn("file is encrypted cannot be extracted: "
+ fh.getFileNameString());
continue;
}
Expand All @@ -68,6 +71,12 @@ public static void extract(File archive, File destination) {
}
}

/**
* Creates a file in a specified destination directory
* @param fh the file to be created
* @param destination the destination to which the newly created file will be moved to
* @return
*/
private static File createFile(FileHeader fh, File destination) {
File f = null;
String name = null;
Expand All @@ -87,6 +96,13 @@ private static File createFile(FileHeader fh, File destination) {
return f;
}

/**
* Creates a file in a specified destination folder
* @param destination the destination folder
* @param name a String indicating the name of the file to be created
* @return
* @throws IOException thrown when file creation cannot be performed
*/
private static File makeFile(File destination, String name)
throws IOException {
String[] dirs = name.split("\\\\");
Expand All @@ -111,6 +127,11 @@ private static File makeFile(File destination, String name)
}
}

/**
* Creates a directory within another specified directory
* @param fh
* @param destination the directory where the new directory will be placed
*/
private static void createDirectory(FileHeader fh, File destination) {
File f = null;
if (fh.isDirectory() && fh.isUnicode()) {
Expand All @@ -126,16 +147,23 @@ private static void createDirectory(FileHeader fh, File destination) {
}
}

/**
* Creates a directory in an specified destination for every directory within the fileName parameter.
* This is done in order to the uncompressed directory to preserve its original file/directory hierarchy.
* @param destination the directory that will become the root directory containing the newly created directory.
* @param fileName the name of the directory to be created.
*/
private static void makeDirectory(File destination, String fileName) {
String[] dirs = fileName.split("\\\\");
String path = "";

if (dirs == null) {
return;
}
String path = "";
for (String dir : dirs) {

for (String dir: dirs) {
path = path + File.separator + dir;
new File(destination, path).mkdir();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import br.ufpe.cin.groundhog.GroundhogException;

/**
* Exception thrown when an extraction operation is attempted to be performed on an unsupported format
* @author fjsj, gustavopinto, rodrigoalvesvieira
*
*/
public class UncompressNotSupportedException extends GroundhogException {
private static final long serialVersionUID = -5221460516926877262L;

public UncompressNotSupportedException(String msg) {
super(msg);
}
}
}
4 changes: 2 additions & 2 deletions src/java/main/br/ufpe/cin/groundhog/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.google.common.io.Files;

/**
*
* General utilities class for file operations
* @author fjsj, gustavopinto, rodrigoalvesvieira
*/
public class FileUtil {
Expand Down Expand Up @@ -78,6 +78,6 @@ public void writeStringToFile(File file, String data) throws IOException {
*/
public void copyDirectory(File srcDir, File destDir) throws IOException {
FileUtils.copyDirectory(srcDir, destDir);
// TODO: add tests
// TODO: add tests
}
}

0 comments on commit b44a402

Please sign in to comment.