⌛⌛ Text search inside a 7z file¶
The submission consists of a Maven project. Place your answer into the file pom.xml and into
Java files named as you wish in the subdirectory src. Both the
pom.xml file and the
subdirectory must in turn be located in the directory Round7/sevenzipsearch. Remember to pull task
In this task you will try handling files compressed with 7z compression by using by using the Apache Commons Compress library. You will actually need the following two libraries as dependencies:
Apache Commons Compress
Info page from Maven Central: https://search.maven.org/artifact/org.apache.commons/commons-compress/1.21/jar
Info page from Maven Central: https://search.maven.org/artifact/org.tukaani/xz/1.9/jar
Note! This dependency is needed only indirectly: Apache Commons Compress library uses it internally. Your code does not need to refer to this library anywhere. It is enough that you add the dependency definition into the
7z files (Wikipedia article) are as such similar to zip files but they use a more efficient compression algorithm.
Your task is to implement a program that searches for occurrences of a given search word in the text files contained in a given 7z file. To be more precise, the program must work as follows:
The program takes two command line parameters: a name of the file and a search word.
The program assumes that the first command line parameter corresponds to a 7z file. The program scans the files in the given 7z file and performs a word search in each found text file.
A file is recognized as a text file based on its ending: the search is performed if and only if the file ending is
At the beginning of each search the name of the file is printed out.
At the end of each search one extra new line is printed.
Performing the word search:
The file is read one line at a time and all occurrences of the search word are searched from each line, ignoring character case.
If at least one occurrence is found, the line in question is printed out in the form “
line number: line”, where
line numberis the number of the line in question (the first line in the file has number 1), and
lineis the line in question formatted in such a way that all occurrences of the search word have been changed to use upper case letters.
The example outputs clarify the format.
The automatic tests (and the ones given below) assume that you make the following definitions
pom.xml project file:
The value of
The value of
A onejar plugin definition where the value of
mainClasselement refers to the main class of your program (which you can name freely in this task).
You can test your program with the test input files
Dracula.7z, and the example
When implementing the task, it might be a good idea to inspect the contents of the 7z files
Dracula.7z. Many operating systems (e.g. Ubuntu Linux) know how to open 7z
files without a separate program. Otherwise you can use some compression program that supports the
7z format. A suitable choice might be 7-zip (https://www.7-zip.org/),
which is installed on the university computers.
Compile your program with
mvn package and run the tests as
java -jar target/sevenzipsearch-1.0.one-jar.jar java.7z oracle,
java -jar target/sevenzipsearch-1.0.one-jar.jar Dracula.7z under and
java -jar target/sevenzipsearch-1.0.one-jar.jar Dracula.7z press. The expected outputs of these
three tests are depicted in the files
A+ presents the exercise submission form here.