All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gw.lang.javac.ClassJavaFileObject Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
package gw.lang.javac;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import javax.tools.SimpleJavaFileObject;

/**
*/
public class ClassJavaFileObject extends SimpleJavaFileObject
{
  private final ByteArrayOutputStream _outputStream;
  private final String _className;

  public ClassJavaFileObject( String className, Kind kind )
  {
    super( URI.create( "mem:///" + className.replace( '.', '/' ) + kind.extension ), kind );
    _className = className;
    _outputStream = new ByteArrayOutputStream();
  }

  @Override
  public OutputStream openOutputStream() throws IOException
  {
    return _outputStream;
  }

  @Override
  public InputStream openInputStream() throws IOException
  {
    if( _outputStream.size() > 0 )
    {
      return new ByteArrayInputStream( getBytes() );
    }
    return null;
  }

  public byte[] getBytes()
  {
    return _outputStream.toByteArray();
  }

  public String getClassName()
  {
    return _className;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy