Package: DocStreamReader

DocStreamReader

nameinstructionbranchcomplexitylinemethod
DocStreamReader(InputStream, String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
read(char[])
M: 52 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2011 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.parser.lex;
25:
26: import java.io.BufferedReader;
27: import java.io.IOException;
28: import java.io.InputStream;
29: import java.io.InputStreamReader;
30: import java.io.UnsupportedEncodingException;
31:
32: /**
33: * A class to read .doc encoded VDM files.
34: */
35:
36: public class DocStreamReader extends InputStreamReader
37: {
38:         public DocStreamReader(InputStream in, String charsetName)
39:                         throws UnsupportedEncodingException
40:         {
41:                 super(in, charsetName);
42:         }
43:
44:         private final static String MARKER = "%%VDM%%";
45:
46:         @Override
47:         public int read(char[] array) throws IOException
48:         {
49:                 BufferedReader br = new BufferedReader(this);
50:                 boolean capturing = false;
51:                 int pos = 0;
52:                 String line = br.readLine();
53:
54:•                while (line != null)
55:                 {
56:•                        if (line.endsWith(MARKER))
57:                         {
58:•                                capturing = !capturing;
59:                         } else
60:                         {
61:•                                if (capturing)
62:                                 {
63:                                         line.getChars(0, line.length(), array, pos);
64:                                         pos += line.length();
65:                                         array[pos++] = '\n';
66:                                 }
67:                         }
68:
69:                         line = br.readLine();
70:                 }
71:
72:                 br.close();
73:                 return pos;
74:         }
75: }