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 package org.sat4j.reader;
27
28 import java.io.FileInputStream;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
33 import java.io.PrintWriter;
34 import java.net.URL;
35 import java.util.zip.GZIPInputStream;
36
37 import org.sat4j.specs.ContradictionException;
38 import org.sat4j.specs.IProblem;
39
40
41
42
43
44
45
46 public abstract class Reader {
47
48 public IProblem parseInstance(final String filename)
49 throws FileNotFoundException, ParseFormatException, IOException,
50 ContradictionException {
51 InputStream in;
52 if (filename.startsWith("http://")) {
53 in = (new URL(filename)).openStream();
54 } else {
55 in = new FileInputStream(filename);
56 }
57 if (filename.endsWith(".gz")) {
58 in = new GZIPInputStream(in);
59 }
60 return parseInstance(in);
61 }
62
63 public IProblem parseInstance(final InputStream in)
64 throws ParseFormatException, ContradictionException, IOException {
65 return parseInstance(new InputStreamReader(in));
66 }
67
68 public abstract IProblem parseInstance(final java.io.Reader in)
69 throws ParseFormatException, ContradictionException, IOException;
70
71
72
73
74
75
76
77
78 @Deprecated
79 public abstract String decode(int[] model);
80
81
82
83
84
85
86
87
88
89 public abstract void decode(int[] model, PrintWriter out);
90
91 public boolean isVerbose() {
92 return verbose;
93 }
94
95 public void setVerbosity(boolean b) {
96 verbose = b;
97 }
98
99 private boolean verbose = false;
100 }