Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Martin Skurla
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
   * the License. You may obtain a copy of the License at
   *
   *   http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
 package org.crazyjavahacking.astvisualizer.util;
 
 
 import java.io.Reader;
 import java.net.URI;
 
 
JavaFileObject utility class.

Author(s):
Martin
 
 public final class JavaFileObjectUtils {
 
     //-----------------------------------------------------------------------------------------------------------------
     // Constructors.
     //-----------------------------------------------------------------------------------------------------------------
     private JavaFileObjectUtils() {}
 
 
     //-----------------------------------------------------------------------------------------------------------------
     // Public Methods.
     //-----------------------------------------------------------------------------------------------------------------
     
Creates JavaFileObject from input stream. Default charset will be used.

Parameters:
javaSourceInputStream source code input stream
Returns:
JavaFileObject
See also:
javax.tools.JavaFileObject
 
     public static JavaFileObject fromInputStream(InputStream javaSourceInputStream) {
         return fromReader(new InputStreamReader(javaSourceInputStream));
     }

    
Creates JavaFileObject from reader.

Parameters:
javaSourceReader java source reader
Returns:
JavaFileObject
See also:
javax.tools.JavaFileObject
 
     public static JavaFileObject fromReader(Reader javaSourceReader) {
         return new JavaFileObjectFromReader(javaSourceReader);
     }

    
Creates JavaFileObject from classpath resource.

Parameters:
classpathResource classpath resource
Returns:
JavaFileObject
See also:
javax.tools.JavaFileObject
 
     public static JavaFileObject fromClasspathResource(String classpathResource) {
         InputStream resourceInputStream =
                 JavaFileObjectUtils.class.getClassLoader().getResourceAsStream(classpathResource);
 
         return fromInputStream(resourceInputStream);
     }
 
 
     //-----------------------------------------------------------------------------------------------------------------
     // Inner classes.
     //-----------------------------------------------------------------------------------------------------------------
 	
Represents JavaFileObject constructed from Reader.
 
     private static final class JavaFileObjectFromReader extends SimpleJavaFileObject {
 
         private final String fileObjectContent;
 
         private JavaFileObjectFromReader(Reader javaSourceReader) {
             super(URI.create(
                    "inputStream:///fakePath"), // URL has to be valid, but can be fake
                    .);
            try {
                this. = CharStreams.toString(javaSourceReader);
            }
            catch (IOException e) {
                throw new IllegalStateException("IOException during reading JavaFileObject content...");
            }
        }
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X