Java 8 Reader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Reader class.

This code example shows how to use the following methods:close
    protected void parseOneInputStreamAsReader( 
            TreeImportingParserBase parser, InputStream inputStream, JSONObject options) {
        ImportColumnGroup rootColumnGroup = new ImportColumnGroup();
        List<Exception> exceptions = new ArrayList<Exception>();
         
        Reader reader = new InputStreamReader(inputStream);
        parser.parseOneFile(
            project,
            metadata,
            job,
            "file-source", 
            reader,
            rootColumnGroup,
            -1, 
            options,
            exceptions
        ); 
        postProcessProject(project, rootColumnGroup, exceptions);
         
        try { 

9
CodeRank
This code example shows how to use the following methods:close, mark, markSupported, read, ready
  } 
   
  @Test
  public void testMarkReset() throws IOException {
    Reader reader = new ReusableStringReader();
    if (reader.markSupported()) {
      ((ReusableStringReader)reader).set(fox);
      assertTrue(reader.ready());
       
      char[] cc = new char[6];
      int read;
      read = reader.read(cc);
      assertEquals(6, read);
      assertEquals("Quick ", new String(cc));
       
      reader.mark(100);
       
      read = reader.read(cc);
      assertEquals(6, read);
      assertEquals("brown ", new String(cc));

8
CodeRank
This code example shows how to use the following methods:close, read, ready
            if (f.length() > sizeLimit) {
                throw new IOException("File " + fileName + " length " + f.length() +
                        " exceeds limit " + sizeLimit);
            } 
            char[] buffer = new char[(int) f.length()];
            reader = new InputStreamReader(new FileInputStream(f), "UTF-8");
            int charsRead = reader.read(buffer);
            // Debug check that we've exhausted the input stream (will fail e.g. if the 
            // file grew after we inspected its length). 
            assert !reader.ready();
            return charsRead < buffer.length ? Arrays.copyOfRange(buffer, 0, charsRead) : buffer;
        } finally { 
            if (reader != null) reader.close();
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:close
        String basedir = System.getProperty( "basedir", System.getProperty( "user.dir" ) );
 
        File globalSettingsFile = new File( basedir, "src/conf/settings.xml" );
        assertTrue( globalSettingsFile.getAbsolutePath(), globalSettingsFile.isFile() );
 
        Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), "UTF-8" );
        try 
        { 
            new SettingsXpp3Reader().read( reader );
        } 
        finally 
        { 
            reader.close();
        } 
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:close
public class CssValidator implements IValidator<String> {
    @Override 
    public void validate(IValidatable<String> text) {
        if (text.getValue() != null) {
            try { 
                Reader in = new StringReader(text.getValue());
                CSS2SLD.convert(in);
                in.close();
            } catch (Exception e) {
                ValidationError error = new ValidationError();
                error.setMessage(e.getMessage());
                text.error(error);
            } 
        } else { 
            ValidationError error = new ValidationError();
            error.setMessage("CSS text must not be empty");
            text.error(error);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:close
                throw e;
            } 
            in = new FileInputStream(file);
        } 
 
        Reader reader = new InputStreamReader(in, encoding);
        Properties props = new Properties();
        props.load(reader);
        in.close();
        reader.close();
 
        return props;
 
    } 
 
 
    public static File getResourceAsFile(String resource) throws IOException {
        try { 
            return new File(ResourceUtils.getResourceURL(resource).getFile());
        } 
7
CodeRank
This code example shows how to use the following methods:close
   * @throws IOException 
   */ 
  public String readOutputFile(Configuration conf) throws IOException {
    FileSystem localFs = FileSystem.getLocal(conf);
    Path file = new Path(outputDir, "part-00000");
    Reader reader = new InputStreamReader(localFs.open(file));
    String r = FileUtils.readFully(reader);
    reader.close();
    return r;
  } 
 
  /** 
   * Creates and runs an MR job 
   *  
   * @param conf 
   * @throws IOException 
   * @throws InterruptedException 
   * @throws ClassNotFoundException 
   */ 
  public void createAndRunJob(Configuration conf) throws IOException,
7
CodeRank
This code example shows how to use the following methods:close
    public void testParseFileWithEscapes() { 
        String file = "[then]TEST=System.out.println(\"DO_SOMETHING\");" + NL + "" +
                      "[when]code {code1} occurs and sum of all digit not equal \\( {code2} \\+ {code3} \\)=AAAA( cd1 == {code1}, cd2 != ( {code2} + {code3} ))" + NL + "" +
                      "[when]code {code1} occurs=BBBB" + NL + "";
        try { 
            final Reader reader = new StringReader( file );
            this.file = new DSLTokenizedMappingFile();
 
            final boolean parsingResult = this.file.parseAndLoad( reader );
            reader.close();
 
            assertTrue( this.file.getErrors().toString(),
                        parsingResult );
            assertTrue( this.file.getErrors().isEmpty() );
             
            final String LHS = "code 1041 occurs and sum of all digit not equal ( 1034 + 1035 )";
            final String rule = "rule \"x\"" + NL + "when" + NL + "" + LHS + "" + NL + "then" + NL + "TEST" + NL + "end";
 
            DefaultExpander de = new DefaultExpander();
            de.addDSLMapping(this.file.getMapping());
7
CodeRank
This code example shows how to use the following methods:close
   * @throws IOException 
   */ 
  public String readOutputFile(Configuration conf) throws IOException {
    FileSystem localFs = FileSystem.getLocal(conf);
    Path file = new Path(outputDir, "part-r-00000");
    Reader reader = new InputStreamReader(localFs.open(file));
    String r = FileUtils.readFully(reader);
    reader.close();
    return r;
  } 
 
  /** 
   * Creates and runs an MR job 
   * 
   * @param conf 
   * @throws IOException 
   * @throws InterruptedException 
   * @throws ClassNotFoundException 
   */ 
  public void createAndRunJob(Configuration conf) throws IOException,
7
CodeRank
This code example shows how to use the following methods:mark, read, reset
	 * isTypeDefinition = true; 
	 */ 
	void parseTypeInformation(Reader reader) {
		try { 
			typeNumber = new TypeNumber(reader);
			reader.mark(1);
			int c = reader.read();
			if (c == '=') {
				isTypeDefinition = true;
				reader.mark(1);
				c = reader.read();
				if (isTypeDescriptor((char)c)) {
					typeDescriptor = (char)c;
				} else { 
					reader.reset();
				} 
			} else { 
				reader.reset();
			} 
		} catch (IOException e) {

7
CodeRank

Related Java 8 Reader Questions & Answers:

See Code Examples for Java 8 Reader Methods: