├── .gitignore ├── .idea ├── .gitignore ├── encodings.xml ├── misc.xml └── vcs.xml ├── 1.png ├── 2.png ├── README.md ├── out └── artifacts │ └── Decomp_comp_jar │ └── Decomp_comp.jar ├── pom.xml └── src └── main └── java ├── GUI ├── AppFrame.java └── Main.java └── comp_decomp ├── comp.java └── decomp.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sandy177000/Compressor_Decompressor/9ed60e721a672e5cc9131d341d576e82f348bb15/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sandy177000/Compressor_Decompressor/9ed60e721a672e5cc9131d341d576e82f348bb15/2.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Introducing a new minor project in Java: a compressor and decompressor application. 2 | The primary objective of this project is to employ compression techniques to reduce the required number of bits for data representation. 3 | It strictly focuses on lossless conversion methods to ensure data integrity throughout the compression process. 4 | By implementing this project, users can benefit from various advantages of compression, including efficient storage utilization, accelerated file transfers, and decreased storage hardware and network bandwidth expenses. 5 | The emphasis on lossless compression techniques guarantees that no data is lost during the compression process, safeguarding the integrity of the compressed data. 6 | 7 | Tech Stack 8 | 9 | -Java 10 | -AWT 11 | -Swing 12 | 13 | Project UI 14 | 15 | ![Untitled205_20230616230921](https://github.com/Sandy177000/Comp_Decomp/assets/112424645/e4244163-72c9-42b4-a227-c65dc08f755f) 16 | 17 | ![Untitled205_20230616230925](https://github.com/Sandy177000/Comp_Decomp/assets/112424645/e6bbe10b-bd7e-44bf-98ff-30132f5d86d1) 18 | -------------------------------------------------------------------------------- /out/artifacts/Decomp_comp_jar/Decomp_comp.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sandy177000/Compressor_Decompressor/9ed60e721a672e5cc9131d341d576e82f348bb15/out/artifacts/Decomp_comp_jar/Decomp_comp.jar -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | Decomp_comp 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 20 13 | 20 14 | UTF-8 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/GUI/AppFrame.java: -------------------------------------------------------------------------------- 1 | package GUI; 2 | 3 | import comp_decomp.comp; 4 | import comp_decomp.decomp; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | import java.io.File; 11 | 12 | public class AppFrame extends JFrame implements ActionListener { 13 | 14 | JButton compressButton; 15 | JButton decompressButton; 16 | AppFrame(String name){ 17 | //set the window title 18 | this.setTitle(name); 19 | 20 | Container c = this.getContentPane(); 21 | c.setLayout(new BorderLayout()); 22 | 23 | // panel for the heading inside the window 24 | JPanel headingPanel = new JPanel(); 25 | headingPanel.setBackground(new Color(56, 119, 217)); // Set background color 135, 206, 235 sky-blue 26 | headingPanel.setPreferredSize(new Dimension(getWidth(),40)); 27 | // label for the heading 28 | JLabel headingLabel = new JLabel("Compressor-Decompressor"); 29 | headingLabel.setFont(new Font("Arial", Font.BOLD, 20)); 30 | headingLabel.setForeground(Color.white); // Set text color 31 | headingPanel.add(headingLabel); // Add the heading label to the heading panel 32 | 33 | JPanel buttonPanel = new JPanel(); // Create a panel for the buttons 34 | buttonPanel.setBackground(new Color(150,150,255)); // Set background color 35 | buttonPanel.setPreferredSize(new Dimension(getWidth(),270)); // Set preferred size 36 | 37 | compressButton = new JButton("Select file to compress"); 38 | decompressButton = new JButton("Select file to decompress"); 39 | compressButton.setBackground(new Color(203, 214, 255)); // Set button background color 40 | decompressButton.setBackground(new Color(203, 214, 255)); // Set button background color 41 | compressButton.setForeground(new Color(50,50,100)); // Set button text color 42 | decompressButton.setForeground(new Color(50,50,100)); // Set button text color 43 | 44 | 45 | buttonPanel.add(compressButton); 46 | buttonPanel.add(decompressButton); 47 | 48 | c.add(headingPanel, BorderLayout.NORTH); // Add the heading panel to the top 49 | c.add(buttonPanel, BorderLayout.CENTER); // Add the button panel to the center 50 | 51 | compressButton.addActionListener(this); 52 | decompressButton.addActionListener(this); 53 | 54 | this.setSize(500, 300); 55 | this.setResizable(false); 56 | 57 | this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); 58 | this.getContentPane().setBackground(Color.white); // Set background color for the frame 59 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 60 | this.setLocationRelativeTo(null); // Center the frame on the screen 61 | this.setVisible(true); 62 | 63 | 64 | 65 | } 66 | 67 | 68 | //Overiding the actionPerformed method from the ActionListener interface 69 | public void actionPerformed(ActionEvent e){ 70 | if(e.getSource() == compressButton){ 71 | JFileChooser fileChooser = new JFileChooser(); 72 | int response = fileChooser.showSaveDialog(null); 73 | if(response==JFileChooser.APPROVE_OPTION){ 74 | File file = new File(fileChooser.getSelectedFile().getAbsolutePath()); 75 | try{ 76 | comp.method(file); 77 | } 78 | catch(Exception ee){ 79 | JOptionPane.showMessageDialog(null,ee.toString()); 80 | } 81 | } 82 | } 83 | 84 | if(e.getSource() == decompressButton){ 85 | JFileChooser fileChooser = new JFileChooser(); 86 | int response = fileChooser.showSaveDialog(null); 87 | if(response == JFileChooser.APPROVE_OPTION){ 88 | File file = new File(fileChooser.getSelectedFile().getAbsolutePath()); 89 | try{ 90 | decomp.method(file); 91 | } 92 | catch (Exception ee){ 93 | JOptionPane.showMessageDialog(null, ee.toString()); 94 | } 95 | } 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/GUI/Main.java: -------------------------------------------------------------------------------- 1 | package GUI; 2 | 3 | public class 4 | Main { 5 | public static void main(String[] args) { 6 | AppFrame frame = new AppFrame("Compressor-Decompressor"); 7 | 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/comp_decomp/comp.java: -------------------------------------------------------------------------------- 1 | package comp_decomp; 2 | 3 | import java.io.*; 4 | import java.util.zip.GZIPOutputStream; 5 | 6 | public class comp { 7 | public static void method(File file) throws IOException{ 8 | String fileDirectory = file.getParent(); 9 | 10 | // Reads the input bytes in the file 11 | FileInputStream fis = new FileInputStream(file); 12 | 13 | // Writes in the given file 14 | FileOutputStream fos = new FileOutputStream(fileDirectory+"/Compressedfile.gz"); 15 | 16 | // Writes compressed file 17 | GZIPOutputStream gzip = new GZIPOutputStream(fos); 18 | 19 | byte[] buffer = new byte[1024]; 20 | int len; 21 | 22 | while((len = fis.read(buffer))!=-1){ 23 | gzip.write(buffer,0,len); 24 | } 25 | gzip.close(); 26 | fos.close(); 27 | fis.close(); 28 | } 29 | 30 | public static void main(String[] args) throws IOException { 31 | File path = new File(""); 32 | method(path); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/comp_decomp/decomp.java: -------------------------------------------------------------------------------- 1 | package comp_decomp; 2 | import java.io.*; 3 | import java.util.zip.GZIPInputStream; 4 | 5 | public class decomp { 6 | public static void method(File file) throws IOException { 7 | 8 | String fileDirectory = file.getParent(); 9 | 10 | FileInputStream fis = new FileInputStream(file); 11 | GZIPInputStream gzip = new GZIPInputStream(fis); 12 | FileOutputStream fos = new FileOutputStream(fileDirectory+"/decompressedFile"); 13 | 14 | byte[] buffer = new byte[1024]; 15 | int len; 16 | 17 | while((len = gzip.read(buffer))!=-1){ 18 | fos.write(buffer, 0, len); 19 | } 20 | gzip.close(); 21 | fos.close(); 22 | fis.close(); 23 | 24 | 25 | } 26 | 27 | public static void main(String[] args) throws IOException{ 28 | File path = new File(""); 29 | method(path); 30 | } 31 | } 32 | --------------------------------------------------------------------------------