Home | History | Annotate | Download | only in javaparser
      1 /* Generated By:JavaCC: Do not edit this line. StreamProvider.java Version 6.1 */
      2 /* JavaCCOptions:KEEP_LINE_COLUMN=true */
      3 /*
      4  *
      5  * This file is part of Java 1.8 parser and Abstract Syntax Tree.
      6  *
      7  * Java 1.8 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify
      8  * it under the terms of the GNU Lesser General Public License as published by
      9  * the Free Software Foundation, either version 3 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * You should have received a copy of the GNU Lesser General Public License
     13  * along with Java 1.8 parser and Abstract Syntax Tree.  If not, see <http://www.gnu.org/licenses/>.
     14  */
     15 package com.github.javaparser;
     16 
     17 
     18 import java.io.BufferedReader;
     19 import java.io.IOException;
     20 import java.io.InputStream;
     21 import java.io.InputStreamReader;
     22 import java.io.Reader;
     23 
     24 /**
     25  * NOTE : This generated class can be safely deleted if installing in a GWT installation (use StringProvider instead)
     26  */
     27 public class StreamProvider implements Provider {
     28 
     29 	Reader _reader;
     30 
     31 	public StreamProvider(Reader reader) {
     32 		_reader = reader;
     33 	}
     34 
     35 	public StreamProvider(InputStream stream) throws IOException {
     36 		_reader = new BufferedReader(new InputStreamReader(stream));
     37 	}
     38 
     39 	public StreamProvider(InputStream stream, String charsetName) throws IOException {
     40 		_reader = new BufferedReader(new InputStreamReader(stream, charsetName));
     41 	}
     42 
     43 	@Override
     44 	public int read(char[] buffer, int off, int len) throws IOException {
     45 	   int result = _reader.read(buffer, off, len);
     46 
     47 	   /* CBA -- Added 2014/03/29 --
     48 	             This logic allows the generated Java code to be easily translated to C# (via sharpen) -
     49 	             as in C# 0 represents end of file, and in Java, -1 represents end of file
     50 	             See : http://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx
     51 	             ** Technically, this is not required for java but the overhead is extremely low compared to the code generation benefits.
     52 	   */
     53 
     54 	   if (result == 0) {
     55 	      if (off < buffer.length && len > 0) {
     56 	        result = -1;
     57 	      }
     58 	   }
     59 
     60 		return result;
     61 	}
     62 
     63 	@Override
     64 	public void close() throws IOException {
     65 		_reader.close();
     66 	}
     67 
     68 }
     69 
     70 /* JavaCC - OriginalChecksum=b849e0746bbbf4528197ca9d130650d6 (do not edit this line) */
     71