This course has already ended.

⌛⌛ 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 src subdirectory must in turn be located in the directory Round8/sevenzipsearch. Remember to pull task material from student_template_project.

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:

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 .txt”.

    • 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 number is the number of the line in question (the first line in the file has number 1), and line is 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 in your pom.xml project file:

  • The value of artifactId is sevenzipsearch.

  • The value of version element is 1.0.

  • A onejar plugin definition where the value of mainClass element refers to the main class of your program (which you can name freely in this task).

Testing

You can test your program with the test input files java.7z and Dracula.7z, and the example output files output1.txt, output2.txt and output3.txt.

When implementing the task, it might be a good idea to inspect the contents of the 7z files java.7z and 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 output1.txt, output2.txt and output3.txt.

A+ presents the exercise submission form here.

Posting submission...