Java 8 FileObject - 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 FileObject class.

This code example shows how to use the following methods:getCharContent, getLastModified, getName, openInputStream, openReader
	 * Check that the resource can be opened, examined, and its contents match 
	 * {@link #checkResourceContents01(FileObject)}getResource01FileContents 
	 */ 
	private void checkResourceContents01(FileObject resource, String expectedName, String expectedContents) throws Exception {
		 
		long modTime = resource.getLastModified();
		if (modTime <= 0) {
			ProcessorTestStatus.fail("resource had unexpected mod time: " + modTime);
		} 
		 
		String actualName = resource.getName();
		if (!expectedName.equals(actualName)) {
			System.out.println("Resource had unexpected name.  Expected " + expectedName +
					", actual was " + actualName);
			ProcessorTestStatus.fail("Resource had unexpected name"); 
		} 
		 
		InputStream stream = resource.openInputStream();
		if (stream.available() <= 0) {
			ProcessorTestStatus.fail("stream contained no data"); 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openOutputStream
	} 
 
	@Override 
	public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
		FileObject resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, pkg.name(), fileName);
		return resource.openOutputStream();
	} 
 
	@Override 
	public void close() throws IOException {
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openOutputStream
				LOGGER.info("Generating class with no originating element: {}", qualifiedClassName);
			} 
 
			sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements);
 
			return sourceFile.openOutputStream();
		} catch (FilerException e) {
			LOGGER.error("Could not generate source file for {}", qualifiedClassName, e.getMessage());
			/* 
			 * This exception is expected, when some files are created twice. We 
			 * cannot delete existing files, unless using a dirty hack. Files a 
			 * created twice when the same file is created from different 
			 * annotation rounds. Happens when renaming classes, and for 
			 * Background executor. It also probably means I didn't fully 
			 * understand how annotation processing works. If anyone can point 
			 * me out... 
			 */ 
			return VOID_OUTPUT_STREAM;
		} 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openOutputStream
    } 
 
    @Test
    public void testCreateResource() throws IOException {
 
        when(mockFiler.createResource(StandardLocation.SOURCE_OUTPUT, TEST_PACKAGE, TEST_FILENAME)).thenReturn(mockFile);
        when(mockFile.openOutputStream()).thenReturn(mockOutputStream);
 
        assertEquals(mockOutputStream, resourceWriter.openBinary(codeModel._package(TEST_PACKAGE), TEST_FILENAME));
 
        resourceWriter.close();
        verify(mockOutputStream).flush();
        verify(mockOutputStream).close();
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openOutputStream
    } 
 
    @Test
    public void testCreateSourceFile() throws IOException {
 
        when(mockFiler.createSourceFile(TEST_PACKAGE + "." + TEST_CLASS)).thenReturn(mockFile);
        when(mockFile.openOutputStream()).thenReturn(mockOutputStream);
 
        assertEquals(mockOutputStream, codeWriter.openBinary(codeModel._package(TEST_PACKAGE), TEST_CLASS));
 
        codeWriter.close();
        verify(mockOutputStream).flush();
        verify(mockOutputStream).close();
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openWriter
        Template template = null;
 
        PrintWriter w =  null;
        try { 
            template = Velocity.getTemplate(templatePath);
            w = new PrintWriter(jfo.openWriter());
            template.merge(context, w);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new IOException("Impossible to generate annotation database.", ex);
        } finally { 
            if( w != null ) {
                try { 
                    w.close();
                } catch( Exception ex ) {
                    ex.printStackTrace();
                    throw new IOException("Impossible to close annotation database.", ex);
                } 
            } 
        } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:openOutputStream, openWriter
		} 
		if (stringContent.isEmpty()) {
			// Binary content.  Open an OutputStream. 
			OutputStream os = null;
			try { 
				os = fo.openOutputStream();
				os.write(binaryContent);
			} 
			catch (Exception e) {
				_messager.printMessage(Kind.ERROR, e.getLocalizedMessage(), annotatedEl);
				return; 
			} 
			finally { 
				try { 
					os.close();
				} catch (IOException e) {
					_messager.printMessage(Kind.ERROR, e.getLocalizedMessage(), annotatedEl);
				} 
			} 
		} 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getName, openWriter
			_messager.printMessage(Diagnostic.Kind.WARNING, "Unable to open file for class " + qname, annotatedEl);
			return; 
		} 
		PrintWriter pw = null;
		try { 
			pw = new PrintWriter(jfo.openWriter());
		} catch (IOException e) {
			_messager.printMessage(Diagnostic.Kind.WARNING, "Unable to get writer for file " + jfo.getName());
			return; 
		} 
		 
		// Generate the class 
		if (summary) {
			_classesToSummarize.put(qname, annotatedEl);
		} 
		pw.println("// Generated by " + this.getClass().getName());
		pw.println("package " + pkg + ";");
		if (rounds > 1) {
			pw.println("import " + GenClass6.class.getCanonicalName() + ";");
			StringBuilder sb = new StringBuilder();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getName
    } 
 
    @Override 
    public String inferBinaryName(Location loc, JavaFileObject file) {
        if (file instanceof JavaFileObjectImpl) {
            return file.getName();
        } 
 
        return super.inferBinaryName(loc, file);
    } 
 
    @Override 
    public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
                                                                                                                 throws IOException {
        Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
 
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        List<URL> urlList = new ArrayList<URL>();
        Enumeration<URL> e = contextClassLoader.getResources("com");
        while (e.hasMoreElements()) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getName, openWriter
        public URI toUri() {
            return delegate.toUri();
        } 
 
        public String getName() {
            return delegate.getName();
        } 
 
        public InputStream openInputStream() throws IOException {
            checkRead(); 
            return delegate.openInputStream();
        } 
 
        public OutputStream openOutputStream() throws IOException {
            checkWrite(); 
            return delegate.openOutputStream();
        } 
 
        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
            checkRead(); 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 FileObject Methods: