-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompression.java
More file actions
70 lines (60 loc) · 1.82 KB
/
Compression.java
File metadata and controls
70 lines (60 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
import java.io.*;
public abstract class Compression {
protected String _depart;
public abstract void compresser(String fin, boolean v);
public abstract void decompresser(String fin, boolean v);
public double estimationComp(){
System.out.println("Aucune estimation disponible");
return 0.;
}
public abstract void raz();
// convertir un entier en une chaîne de 0 et de 1
public String int2bin(int i,int t){
StringBuffer str=new StringBuffer(Integer.toBinaryString(i));
while(str.length()<t)
str.insert(0,"0");
return str.toString();
}
// convertit une chaîne binaire en octet
public static byte string2Byte(String str){// avec str en convention unsigned
if(str.charAt(0)=='0')return Byte.parseByte(str,2);
else{
if(str.length()>=2)
return (byte) (Byte.parseByte(str.substring(1),2)-Byte.MAX_VALUE-1);
else
return Byte.MIN_VALUE;
}
}
// convertit une chaîne binaire en entier
public static int string2Int(String str){// avec str en convention unsigned
if(str.charAt(0)=='0')return Integer.parseInt(str,2);
else{
return (int) (Integer.parseInt( str.substring(1),2)-Integer.MAX_VALUE-1);
}
}
public void tester(String dep,String arr, boolean v){
raz();
_depart=dep;
compresser(dep+"c", v);
raz();
_depart=dep+"c";
decompresser(arr,v);
CSP.estLeMeme(dep,arr);
}
public void testerTout(boolean v){
String rep="test/";
String fich[]={"c.pak","e.m4a","h.html","j.jpg","p.pptx","s.so","x.xcf","k.html"};
for(String s :fich)
tester(rep+s,rep+"2"+s,v);
}
public void testerToutTexte(boolean v){
String rep="test/";
String fich[]={"c.pak","e.m4a","h.html","j.jpg","p.pptx","s.so","x.xcf","k.html"};
for(String s :fich)
if(CSP.typeDe(rep+s)==TypeFichier.TEXTE)tester(rep+s,rep+"2"+s,v);
}
public String getDepart(){
return _depart;
}
}