View Javadoc
1   /* Generated by: ParserGeneratorCC: Do not edit this line. StreamProvider.java Version 1.1 */
2   /* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */
3   package org.apache.commons.jexl3.parser;
4   
5   
6   import java.io.BufferedReader;
7   import java.io.IOException;
8   import java.io.InputStream;
9   import java.io.InputStreamReader;
10  import java.io.Reader;
11  
12  /**
13   * NOTE : This generated class can be safely deleted if installing in a GWT installation (use StringProvider instead)
14   */
15  public class StreamProvider implements Provider
16  {
17  	private Reader m_aReader;
18  	
19    public StreamProvider(final InputStream stream, final String charsetName) throws IOException
20    {
21      this (new BufferedReader (new InputStreamReader (stream, charsetName)));
22    }
23    
24    public StreamProvider(final InputStream stream, final java.nio.charset.Charset charset)
25    {
26      this (new BufferedReader (new InputStreamReader (stream, charset)));
27    }
28  
29    public StreamProvider (final Reader reader)
30    {
31      m_aReader = reader;
32    }
33  
34    public int read (final char[] aDest, final int nOfs, final int nLen) throws IOException
35    {
36      int result = m_aReader.read(aDest, nOfs, nLen);
37  
38      /* CBA -- Added 2014/03/29 -- 
39         This logic allows the generated Java code to be easily translated to C# (via sharpen) -
40         as in C# 0 represents end of file, and in Java, -1 represents end of file
41         See : http://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx
42         ** Technically, this is not required for java but the overhead is extremely low compared to the code generation benefits.
43  	   */
44      if (result == 0)
45        if (nOfs < aDest.length && nLen > 0)
46          result = -1;
47  	   
48      return result;
49  	}
50  
51  	public void close () throws IOException
52  	{
53  	  if (m_aReader != null)
54        m_aReader.close();
55  	}
56  }
57  /* ParserGeneratorCC - OriginalChecksum=f4cc4504a630d11129ad9cbe176ddd39 (do not edit this line) */