• Tidak ada hasil yang ditemukan

Implementasi Metode Punctured Elias Codes Pada Kompresi File Text

N/A
N/A
Protected

Academic year: 2019

Membagikan "Implementasi Metode Punctured Elias Codes Pada Kompresi File Text"

Copied!
19
0
0

Teks penuh

(1)

LAMPIRAN A: LISTING PROGRAM

Main Program

package skripsi; /**

*

* @author REZA */

public class Skripsi { /**

* @param args the command line arguments */

public static void main(String[] args) { try {

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName()); break;

} }

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(kompresi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(kompresi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(kompresi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(kompresi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);

}

java.awt.EventQueue.invokeLater(new Runnable() { public void run() {

new home().setVisible(true); }

}); }

(2)

Class Compression

String reverse = new StringBuffer(x).reverse().toString(); for(int j=0;j<x.length();j++)

compression punctured = new compression(); String[] P1 = punctured.p1(n+1);

String P2 = new StringBuffer(x).deleteCharAt(0).toString(); result[i]=P2;

@SuppressWarnings("unchecked")

public static void countandsortfreqchar(String txt,List karakter,List frekuensi){

(3)

int r = 0;

public static String flagging(int n){

public static String Encode(String bitstring){

(4)

char c = (char) (Integer.parseInt(s, 2)); str.append(c);

}

return str.toString(); }

public static String Decode(String encodestr){

StringBuffer str = new StringBuffer(); for(int i=0;i<encodestr.length();i++){ char c = encodestr.charAt(i);

StringBuffer x = new

StringBuffer(Integer.toBinaryString((int)c)); if(x.length()<8){

int y = 8 - (x.length()%8); for(int j=0;j<y;j++){

x.insert(0,"0"); }

}

str.append(x); }

return str.toString(); }

}

Form Compression

import java.io.BufferedReader; import java.io.File;

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader;

import java.io.FileWriter; import java.io.IOException;

import java.io.ObjectOutputStream; import java.util.ArrayList;

import java.util.List;

import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane;

import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.poi.extractor.ExtractorFactory;

import org.apache.poi.hwpf.extractor.WordExtractor;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import org.apache.xmlbeans.XmlException;

/** *

* @author REZA */

public class kompresi extends javax.swing.JFrame {

(5)

File file; File file1;

JFileChooser openfile = new JFileChooser(); JFileChooser savefile = new JFileChooser(); StringBuffer content = new StringBuffer(); String[] code ;

openfile.setFileSelectionMode(JFileChooser.FILES_ONLY); openfile.setAcceptAllFileFilterUsed(false);

openfile.addChoosableFileFilter(new

FileNameExtensionFilter("TXT Document (*.txt)", "txt")); openfile.addChoosableFileFilter(new

FileNameExtensionFilter("WORD Document (*.doc)","doc")); openfile.addChoosableFileFilter(new

FileNameExtensionFilter("All Files (*.txt,*.doc)","doc", "txt"));

int returnVal = openfile.showOpenDialog(this); if (returnVal == openfile.APPROVE_OPTION) { file = openfile.getSelectedFile();

jTextField1.setText(file.getAbsolutePath().toString());

(6)
(7)

} private void

jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1.setSelected(false);

pilihkode="P2";

// TODO add your handling code here:

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

//---Menentukan Direktori File Outout---

savefile.setFileSelectionMode(JFileChooser.FILES_ONLY); savefile.setAcceptAllFileFilterUsed(false);

savefile.addChoosableFileFilter(new

FileNameExtensionFilter("pec File (*.pec)", "pec"));

int returnVal = savefile.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file1 = savefile.getSelectedFile();

jTextField2.setText(file1.getPath()); }

//---

} private void

jTextField2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

if(pilihkode==null){

JOptionPane.showMessageDialog(rootPane,"No Punctured Elias Code \n Please Choose One First

!!!","Error",JOptionPane.WARNING_MESSAGE); }

else

if(jTextField1.getText().equals("")){

JOptionPane.showMessageDialog(rootPane,"No Input File \n Please Open a File !!!","Error",JOptionPane.WARNING_MESSAGE);

} else

if(jTextField2.getText().equals("")){

JOptionPane.showMessageDialog(rootPane,"Please Set Directory For Output File !!!","Error",JOptionPane.WARNING_MESSAGE); }

else{

// Date starttime =null, endtime = null; Long starttime = System.currentTimeMillis(); //===Proses

Kompresi========================================================= compression punctured = new compression();

(8)

//Membuat Tabel Kode Punctured Elias Codes berdasarkan jumlah karakter--

//---Membuat bit string berdasarkan tabel kode---

for(int i=0;i<content.toString().length();i++){

BitStr += code[karakter.indexOf(content.toString().charAt(i))]; }

System.out.println("\n bitstring:\n"+BitStr);

System.out.println("Panjang Bit String Sebelum Encode "+BitStr.length()+" bit");

System.out.println("panjang bit string Setelah encode "+WriteStr.length()+" Byte");

(9)

//---Menulis Header double RC = (double)uncompressed_bits/compressed_bits;

double CR = (double)compressed_bits/uncompressed_bits *100; double RD = (double)100-CR;

//--- //---Menampilkan Ratio Hasil Kompresi---

content.delete(0, content.length()); BitStr= "";

pilihkode=null;

jRadioButton1.setSelected(false); jRadioButton2.setSelected(false); jTextField1.setText(null);

jTextField2.setText(null);

totaltime=null;

//--- JOptionPane.showMessageDialog(rootPane, "File Compressed

Successfully...", "Compression", JOptionPane.INFORMATION_MESSAGE); }

(10)

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.setText("");

// TODO add your handling code here: }

Form Decompression

import java.io.BufferedReader; import java.io.File;

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader;

import java.io.FileWriter; import java.io.IOException; import java.io.InputStream;

import java.io.ObjectInputStream; import java.util.ArrayList;

import java.util.List;

import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane;

import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.poi.extractor.ExtractorFactory;

import org.apache.poi.hwpf.HWPFDocument;

import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.usermodel.Range;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import org.apache.xmlbeans.XmlException; /**

*

* @author REZA */

public class dekompresi extends javax.swing.JFrame { JFileChooser openfile = new JFileChooser(); JFileChooser openfile1 = new JFileChooser(); JFileChooser savefile = new JFileChooser(); File file;

File file1; File file2;

StringBuffer content = new StringBuffer(); StringBuffer content1 = new StringBuffer(); int text_bits;

int uncompressed_bits;

List karakter = new ArrayList(); List frekuensi = new ArrayList(); String[] code;

String[] paragraph; String BitStr;

(11)

* Creates new form dekompresi

openfile.setFileSelectionMode(JFileChooser.FILES_ONLY); openfile.setAcceptAllFileFilterUsed(false);

openfile.addChoosableFileFilter(new

FileNameExtensionFilter("pec File (*.pec)", "pec"));

int returnVal = openfile.showOpenDialog(this); if (returnVal == openfile.APPROVE_OPTION) { file = openfile.getSelectedFile();

jTextField1.setText(file.getAbsolutePath().toString()); BufferedReader bufferedReader = null;

(12)

while ((r = bufferedReader1.read())!= -1) { @SuppressWarnings("unchecked")

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

(13)

openfile1.setFileSelectionMode(JFileChooser.FILES_ONLY); openfile1.setAcceptAllFileFilterUsed(false);

openfile1.addChoosableFileFilter(new

FileNameExtensionFilter("Header File (*.header)", "header"));

int returnVal = openfile1.showOpenDialog(this); if (returnVal == openfile1.APPROVE_OPTION) { file2 = openfile1.getSelectedFile();

jTextField3.setText(file2.getAbsolutePath().toString()); try {

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

//---Menentukan Direktori File Output---

savefile.setFileSelectionMode(JFileChooser.FILES_ONLY); savefile.setAcceptAllFileFilterUsed(false);

savefile.addChoosableFileFilter(new

FileNameExtensionFilter("TEXT Document", "txt")); savefile.addChoosableFileFilter(new

FileNameExtensionFilter("WORD Document" ,"doc"));

jTextField2.setText(file1.getPath()); }

//---

}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

(14)

JOptionPane.showMessageDialog(rootPane,"No Input File *.pec \n Please Open a File !!!","Error",JOptionPane.WARNING_MESSAGE); }else

if(jTextField2.getText().equals("")){

JOptionPane.showMessageDialog(rootPane,"Please Set

Directory For Output File !!!","Error",JOptionPane.WARNING_MESSAGE); }else

if(jTextField3.getText().equals("")) {

JOptionPane.showMessageDialog(rootPane,"No Input File *.header \n Please Open a File

!!!","Error",JOptionPane.WARNING_MESSAGE);

BitStr = punctured.Decode(content.toString());

String namafile = jTextField1.getText().toLowerCase();

//---Menulis Hasil File Dekompresi ke txt atau doc---

(15)

File newTextFile = new

else if(namafile.substring(namafile.length()-8, namafile.length()-4).equals(".doc")){ POIFSFileSystem poi = new POIFSFileSystem(systemResource); HWPFDocument doc = new HWPFDocument(poi);

Range range = doc.getRange();

StringBuilder bucket = new StringBuilder(); bucket.append(UncompressedStr);

range.insertBefore(bucket.toString()); bucket = null;

uncompressed_bits = UncompressedStr.length()*8; double completeness =

(16)

System.out.print(namafile.substring(namafile.length()-8, namafile.length()-4));

}

} private void

jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:

}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.setText("");

// TODO add your handling code here: }

Hasil Kompresi Dengan Panjang Character Set 237 Karakter

File PEC Hasil Kompresi

(17)
(18)
(19)

LAMPIRAN C: CURRICULUM VITAE

DATA PRIBADI

Nama

: Reza Andika

Tempat / Tgl lahir

: Medan/ 14 April 1991

Jenis Kelamin

: Laki-laki

Umur

: 23 Tahun

Tinggi, Berat Badan : 170 cm, 60 Kg

Agama

: Islam

Alamat

: Jl. Bilal Ujung No. 139 A

Status

: Belum Menikah

No. Telepon

: 087869610103

Email

: [email protected]

PENDIDIKAN

Formal

- SD Negeri 060870 Medan

( 1997-2003 )

- SMP Negeri 7 Medan

( 2003-2006 )

- SMA Negeri 3 Medan

( 2006-2009 )

- D3 Teknik Informatika Fakultas MIPA

Universitas Sumatera Utara

( 2009-2012 )

Non Formal

- Training Network Administrator di Balai Besar Latihan Kerja Industri (BBLKI)

Medan

(19 Maret 2012 – 17 April 2012)

Hormat Saya

Referensi

Dokumen terkait

public class frmKomp extends javax.swing.JFrame { public String nama_file= &#34;&#34;;. public String

Kompresi dengan menggunakan metode algoritma Punctured Elias Code dapat memperkecilkan ukuran aplikasi yang besar menjadi lebih kecil setelah

Hasil akhir dari kompresi adalah file berekstensi *.header sebagai informasi kode dan karakter dari string dan *.pec yang merupakan String bit hasil kompresi

public class ContohJLabel extends JFrame{ public static void main(String[] args) {. ContohJLabel apl = new

Kompresi dengan menggunakan metode algoritma Punctured Elias Code dapat memperkecilkan ukuran file yang besar menjadi lebih kecil setelah mendapatkan hasil

Example import javax.swing.*; import java.awt.*; public class OnePrgLine extends JPanel{ public static void mainString[] args { int x1,y1,xn,yn; JFrame frame = new

Space Saving SS SS= ukuran data sebelum dikompresi – ukuran data setelah dikompresi SS=144 -112 SS= 32 3.2 Proses dekompresi berdasarkan algoritma punctured elias code p1 Pada

Contoh program untuk menampilkan JLabel adalah sebagai berikut : import javax.swing.*; public class TampilLabel extends JFrame{ private JPanel panelku = new JPanel; private