##### Coverage Report - org.apache.commons.configuration.plist.SimpleCharStream

Classes in this File | Line Coverage | Branch Coverage | Complexity

SimpleCharStream

49% | 68/139

61% | 11/18

2.380952380952381;2,381

1

     /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 3.0 */

2

     package org.apache.commons.configuration.plist;

3

4

     /**

5

      * An implementation of interface CharStream, where the stream is assumed to

6

      * contain only ASCII characters (without unicode processing).

7

      */

8

9

     class SimpleCharStream

10

     {

11

       public static final boolean staticFlag = false;

12

       int bufsize;

13

       int available;

14

       int tokenBegin;

15

18

       public int bufpos = -1;

16

       protected int bufline[];

17

       protected int bufcolumn[];

18

19

18

       protected int column = 0;

20

18

       protected int line = 1;

21

22

18

       protected boolean prevCharIsCR = false;

23

18

       protected boolean prevCharIsLF = false;

24

25

       protected java.io.Reader inputStream;

26

27

       protected char[] buffer;

28

18

       protected int maxNextCharInd = 0;

29

18

       protected int inBuf = 0;

30

31

       protected void ExpandBuff(boolean wrapAround)

32

       {

33

0

          char[] newbuffer = new char[bufsize + 2048];

34

0

          int newbufline[] = new int[bufsize + 2048];

35

0

          int newbufcolumn[] = new int[bufsize + 2048];

36

37

          try

38

          {

39

0

             if (wrapAround)

40

             {

41

0

                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);

42

0

                System.arraycopy(buffer, 0, newbuffer,

43

                                                  bufsize - tokenBegin, bufpos);

44

0

                buffer = newbuffer;

45

46

0

                System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);

47

0

                System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);

48

0

                bufline = newbufline;

49

50

0

                System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);

51

0

                System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);

52

0

                bufcolumn = newbufcolumn;

53

54

0

                maxNextCharInd = (bufpos += (bufsize - tokenBegin));

55

             }

56

             else

57

             {

58

0

                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);

59

0

                buffer = newbuffer;

60

61

0

                System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);

62

0

                bufline = newbufline;

63

64

0

                System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);

65

0

                bufcolumn = newbufcolumn;

66

67

0

                maxNextCharInd = (bufpos -= tokenBegin);

68

             }

69

0

          }

70

          catch (Throwable t)

71

          {

72

0

             throw new Error(t.getMessage());

73

          }

74

75

76

0

          bufsize += 2048;

77

0

          available = bufsize;

78

0

          tokenBegin = 0;

79

0

       }

80

81

       protected void FillBuff() throws java.io.IOException

82

       {

83

42

          if (maxNextCharInd == available)

84

          {

85

0

             if (available == bufsize)

86

             {

87

0

                if (tokenBegin > 2048)

88

                {

89

0

                   bufpos = maxNextCharInd = 0;

90

0

                   available = tokenBegin;

91

                }

92

0

                else if (tokenBegin < 0)

93

0

                   bufpos = maxNextCharInd = 0;

94

                else

95

0

                   ExpandBuff(false);

96

             }

97

0

             else if (available > tokenBegin)

98

0

                available = bufsize;

99

0

             else if ((tokenBegin - available) < 2048)

100

0

                ExpandBuff(true);

101

             else

102

0

                available = tokenBegin;

103

          }

104

105

          int i;

106

          try {

107

42

             if ((i = inputStream.read(buffer, maxNextCharInd,

108

                                         available - maxNextCharInd)) == -1)

109

             {

110

15

                inputStream.close();

111

15

                throw new java.io.IOException();

112

             }

113

             else

114

14

                maxNextCharInd += i;

115

14

             return;

116

          }

117

          catch(java.io.IOException e) {

118

28

             --bufpos;

119

28

             backup(0);

120

28

             if (tokenBegin == -1)

121

28

                tokenBegin = bufpos;

122

28

             throw e;

123

          }

124

       }

125

126

       public char BeginToken() throws java.io.IOException

127

       {

128

5961

          tokenBegin = -1;

129

5961

          char c = readChar();

130

5933

          tokenBegin = bufpos;

131

132

5933

          return c;

133

       }

134

135

       protected void UpdateLineColumn(char c)

136

       {

137

9975

          column++;

138

139

9975

          if (prevCharIsLF)

140

          {

141

558

             prevCharIsLF = false;

142

558

             line += (column = 1);

143

          }

144

9417

          else if (prevCharIsCR)

145

          {

146

571

             prevCharIsCR = false;

147

571

             if (c == '\n')

148

             {

149

571

                prevCharIsLF = true;

150

             }

151

             else

152

0

                line += (column = 1);

153

          }

154

155

9975

          switch (c)

156

          {

157

             case '\r' :

158

571

                prevCharIsCR = true;

159

571

                break;

160

             case '\n' :

161

571

                prevCharIsLF = true;

162

571

                break;

163

             case '\t' :

164

0

                column--;

165

0

                column += (8 - (column & 07));

166

0

                break;

167

             default :

168

                break;

169

          }

170

171

9975

          bufline[bufpos] = line;

172

9975

          bufcolumn[bufpos] = column;

173

9975

       }

174

175

       public char readChar() throws java.io.IOException

176

       {

177

10389

          if (inBuf > 0)

178

          {

179

386

             --inBuf;

180

181

386

             if (++bufpos == bufsize)

182

0

                bufpos = 0;

183

184

386

             return buffer[bufpos];

185

          }

186

187

10003

          if (++bufpos >= maxNextCharInd)

188

42

             FillBuff();

189

190

9975

          char c = buffer[bufpos];

191

192

9975

          UpdateLineColumn(c);

193

9975

          return (c);

194

       }

195

196

       /**

197

        * @deprecated

198

        * @see #getEndColumn

199

        */

200

201

       public int getColumn() {

202

0

          return bufcolumn[bufpos];

203

       }

204

205

       /**

206

        * @deprecated

207

        * @see #getEndLine

208

        */

209

210

       public int getLine() {

211

0

          return bufline[bufpos];

212

       }

213

214

       public int getEndColumn() {

215

1483

          return bufcolumn[bufpos];

216

       }

217

218

       public int getEndLine() {

219

1483

          return bufline[bufpos];

220

       }

221

222

       public int getBeginColumn() {

223

1483

          return bufcolumn[tokenBegin];

224

       }

225

226

       public int getBeginLine() {

227

1483

          return bufline[tokenBegin];

228

       }

229

230

       public void backup(int amount) {

231

232

1895

         inBuf += amount;

233

1895

         if ((bufpos -= amount) < 0)

234

1

            bufpos += bufsize;

235

1895

       }

236

237

       public SimpleCharStream(java.io.Reader dstream, int startline,

238

       int startcolumn, int buffersize)

239

18

       {

240

18

         inputStream = dstream;

241

18

         line = startline;

242

18

         column = startcolumn - 1;

243

244

18

         available = bufsize = buffersize;

245

18

         buffer = new char[buffersize];

246

18

         bufline = new int[buffersize];

247

18

         bufcolumn = new int[buffersize];

248

18

       }

249

250

       public SimpleCharStream(java.io.Reader dstream, int startline,

251

                                                                int startcolumn)

252

       {

253

18

          this(dstream, startline, startcolumn, 4096);

254

18

       }

255

256

       public SimpleCharStream(java.io.Reader dstream)

257

       {

258

0

          this(dstream, 1, 1, 4096);

259

0

       }

260

       public void ReInit(java.io.Reader dstream, int startline,

261

       int startcolumn, int buffersize)

262

       {

263

0

         inputStream = dstream;

264

0

         line = startline;

265

0

         column = startcolumn - 1;

266

267

0

         if (buffer == null || buffersize != buffer.length)

268

         {

269

0

           available = bufsize = buffersize;

270

0

           buffer = new char[buffersize];

271

0

           bufline = new int[buffersize];

272

0

           bufcolumn = new int[buffersize];

273

         }

274

0

         prevCharIsLF = prevCharIsCR = false;

275

0

         tokenBegin = inBuf = maxNextCharInd = 0;

276

0

         bufpos = -1;

277

0

       }

278

279

       public SimpleCharStream(java.io.InputStream dstream, int startline,

280

       int startcolumn, int buffersize)

281

       {

282

0

          this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);

283

0

       }

284

285

       public SimpleCharStream(java.io.InputStream dstream, int startline,

286

                                                                int startcolumn)

287

       {

288

0

          this(dstream, startline, startcolumn, 4096);

289

0

       }

290

291

       public SimpleCharStream(java.io.InputStream dstream)

292

       {

293

0

          this(dstream, 1, 1, 4096);

294

0

       }

295

296

       public String GetImage()

297

       {

298

531

          if (bufpos >= tokenBegin)

299

531

             return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);

300

          else

301

0

             return new String(buffer, tokenBegin, bufsize - tokenBegin) +

302

                                   new String(buffer, 0, bufpos + 1);

303

       }

304

305

       public void Done()

306

       {

307

0

          buffer = null;

308

0

          bufline = null;

309

0

          bufcolumn = null;

310

0

       }

311

312

     }