summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/output/ResponseWriter.java
blob: 85bf79a260a1f9f67cc81ffb3ce4f961d21743db (plain)
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
package cz.crcs.ectester.reader.output;

import cz.crcs.ectester.common.util.CardUtil;
import cz.crcs.ectester.reader.response.Response;

import java.io.PrintStream;

/**
 * @author Jan Jancar johny@neuromancer.sk
 */
public class ResponseWriter {
    private PrintStream output;

    public ResponseWriter(PrintStream output) {
        this.output = output;
    }

    public String responseSuffix(Response r) {
        StringBuilder suffix = new StringBuilder();
        for (int j = 0; j < r.getNumSW(); ++j) {
            short sw = r.getSW(j);
            if (sw != 0) {
                suffix.append(" ").append(CardUtil.getSWString(sw));
            }
        }
        if (suffix.length() == 0) {
            suffix.append(" [").append(CardUtil.getSW(r.getNaturalSW())).append(String.format(" 0x%04x", r.getNaturalSW())).append("]");
        }
        return String.format("%4d ms ┃ %s", r.getDuration() / 1000000, suffix);
    }

    public String responseString(Response r) {
        String out = "";
        out += String.format("%-70s", r.getDescription()) + " ┃ ";
        out += responseSuffix(r);
        return out;
    }

    public void outputResponse(Response r) {
        output.println(responseString(r));
        output.flush();
    }
}