-
Notifications
You must be signed in to change notification settings - Fork 2
/
GzipTestHelper.java
100 lines (91 loc) · 3.72 KB
/
GzipTestHelper.java
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Java Web Archive Toolkit - Software to read and validate ARC, WARC
* and GZip files. (http://jwat.org/)
* Copyright 2011-2012 Netarkivet.dk (http://netarkivet.dk/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jwat.gzip;
import java.util.Iterator;
import java.util.List;
import org.junit.Assert;
import org.jwat.common.Diagnosis;
import org.jwat.common.DiagnosisType;
import org.jwat.common.Diagnostics;
public class GzipTestHelper {
public static boolean containsError(Diagnostics diagnostics, DiagnosisType type, String entity, int infos) {
Iterator<Diagnosis> iter = diagnostics.getErrors().iterator();
Diagnosis diagnosis;
while (iter.hasNext()) {
diagnosis = iter.next();
if (diagnosis.type == type && diagnosis.entity.equals(entity) && diagnosis.information.length == infos) {
return true;
}
}
return false;
}
public static boolean containsWarning(Diagnostics diagnostics, DiagnosisType type, String entity, int infos) {
Iterator<Diagnosis> iter = diagnostics.getWarnings().iterator();
Diagnosis diagnosis;
while (iter.hasNext()) {
diagnosis = iter.next();
if (diagnosis.type == type && diagnosis.entity.equals(entity) && diagnosis.information.length == infos) {
return true;
}
}
return false;
}
public static void compareDiagnoses(Object[][] expectedDiagnoses, List<Diagnosis> diagnosisList) {
Diagnosis diagnosis;
// debug
/*
System.out.println(diagnosisList.size());
for (int i=0; i<diagnosisList.size(); ++i) {
diagnosis = diagnosisList.get(i);
System.out.println(diagnosis.type);
System.out.println(diagnosis.entity);
System.out.println(diagnosis.information.length);
}
*/
Assert.assertEquals(expectedDiagnoses.length, diagnosisList.size());
for (int i=0; i<expectedDiagnoses.length; ++i) {
diagnosis = diagnosisList.get(i);
Assert.assertEquals(expectedDiagnoses[i][0], diagnosis.type);
Assert.assertEquals(expectedDiagnoses[i][1], diagnosis.entity);
Assert.assertEquals(expectedDiagnoses[i][2], diagnosis.information.length);
}
}
public static void printDiagnoses(List<Diagnosis> diagnosisList) {
Diagnosis diagnosis;
for (int i=0; i<diagnosisList.size(); ++i) {
diagnosis = diagnosisList.get(i);
System.out.println("[" + i + "]: " + diagnosis.type + " - " + diagnosis.entity + " - " + diagnosis.information.length);
}
}
/*
// TODO To be continued...
public static void storeStream(String filename, byte[] bytes) {
try {
RandomAccessFile raf = new RandomAccessFile("gzip_" + filename + ".gz", "rw");
raf.seek(0);
raf.setLength(0);
raf.write(bytes);
raf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
*/
}