01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.resultio.text;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10: import java.io.InputStreamReader;
11: import java.io.Reader;
12: import java.nio.charset.Charset;
13:
14: import info.aduna.io.IOUtil;
15:
16: import org.openrdf.query.resultio.BooleanQueryResultFormat;
17: import org.openrdf.query.resultio.BooleanQueryResultParser;
18: import org.openrdf.query.resultio.QueryResultParseException;
19:
20: /**
21: * Reader for the plain text boolean result format.
22: */
23: public class BooleanTextParser implements BooleanQueryResultParser {
24:
25: /*--------------*
26: * Constructors *
27: *--------------*/
28:
29: /**
30: * Creates a new parser for the plain text boolean query result format.
31: */
32: public BooleanTextParser() {
33: super ();
34: }
35:
36: /*---------*
37: * Methods *
38: *---------*/
39:
40: public final BooleanQueryResultFormat getBooleanQueryResultFormat() {
41: return BooleanQueryResultFormat.TEXT;
42: }
43:
44: public synchronized boolean parse(InputStream in)
45: throws IOException, QueryResultParseException {
46: Reader reader = new InputStreamReader(in, Charset
47: .forName("US-ASCII"));
48: String value = IOUtil.readString(reader, 16);
49: value = value.trim();
50:
51: if (value.equalsIgnoreCase("true")) {
52: return true;
53: } else if (value.equalsIgnoreCase("false")) {
54: return false;
55: } else {
56: throw new QueryResultParseException("Invalid value: "
57: + value);
58: }
59: }
60: }
|