1 7 8 package javax.tools; 9 10 import java.io.*; 11 import java.net.URI ; 12 import java.net.URISyntaxException ; 13 import java.nio.CharBuffer ; 14 import javax.lang.model.element.Modifier; 15 import javax.lang.model.element.NestingKind; 16 import javax.tools.JavaFileObject.Kind; 17 18 28 public class SimpleJavaFileObject implements JavaFileObject { 29 32 protected final URI uri; 33 34 37 protected final Kind kind; 38 39 46 protected SimpleJavaFileObject(URI uri, Kind kind) { 47 uri.getClass(); 49 kind.getClass(); 50 if (uri.getPath() == null) 51 throw new IllegalArgumentException ("URI must have a path: " + uri); 52 this.uri = uri; 53 this.kind = kind; 54 } 55 56 public URI toUri() { 57 return uri; 58 } 59 60 public String getName() { 61 return toUri().getPath(); 62 } 63 64 70 public InputStream openInputStream() throws IOException { 71 throw new UnsupportedOperationException (); 72 } 73 74 80 public OutputStream openOutputStream() throws IOException { 81 throw new UnsupportedOperationException (); 82 } 83 84 95 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { 96 CharSequence charContent = getCharContent(ignoreEncodingErrors); 97 if (charContent == null) 98 throw new UnsupportedOperationException (); 99 if (charContent instanceof CharBuffer ) { 100 CharBuffer buffer = (CharBuffer )charContent; 101 if (buffer.hasArray()) 102 return new CharArrayReader(buffer.array()); 103 } 104 return new StringReader(charContent.toString()); 105 } 106 107 113 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 114 throw new UnsupportedOperationException (); 115 } 116 117 127 public Writer openWriter() throws IOException { 128 return new OutputStreamWriter(openOutputStream()); 129 } 130 131 138 public long getLastModified() { 139 return 0L; 140 } 141 142 149 public boolean delete() { 150 return false; 151 } 152 153 156 public Kind getKind() { 157 return kind; 158 } 159 160 174 public boolean isNameCompatible(String simpleName, Kind kind) { 175 String baseName = simpleName + kind.extension; 176 return kind.equals(getKind()) 177 && (baseName.equals(toUri().getPath()) 178 || toUri().getPath().endsWith("/" + baseName)); 179 } 180 181 186 public NestingKind getNestingKind() { return null; } 187 188 193 public Modifier getAccessLevel() { return null; } 194 195 @Override 196 public String toString() { 197 return uri + " from " + getClass().getSimpleName(); 198 } 199 } 200 | Popular Tags |