/* * Copyright (C) 2015, 2016 higherfrequencytrading.com * Copyright (C) 2016 Roman Leventov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.openhft.chronicle.values; import javax.lang.model.element.Modifier; import javax.lang.model.element.NestingKind; import javax.tools.JavaFileObject; import java.io.*; import java.net.URI; import java.nio.CharBuffer; class SimpleURIClassObject implements JavaFileObject { final URI uri; final Class<?> c; protected SimpleURIClassObject(URI uri, Class<?> c) { this.uri = uri; this.c = c; } @Override public URI toUri() { return uri; } @Override public String getName() { return this.toUri().toString(); } @Override public InputStream openInputStream() throws IOException { return uri.toURL().openStream(); } @Override public OutputStream openOutputStream() throws IOException { throw new UnsupportedOperationException(); } @Override public Reader openReader(boolean ignoreEncodingErrors) throws IOException { CharSequence charContent = this.getCharContent(ignoreEncodingErrors); if (charContent == null) throw new UnsupportedOperationException(); if (charContent instanceof CharBuffer) { CharBuffer buffer = (CharBuffer)charContent; if (buffer.hasArray()) return new CharArrayReader(buffer.array()); } return new StringReader(charContent.toString()); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { throw new UnsupportedOperationException(); } @Override public Writer openWriter() throws IOException { return new OutputStreamWriter(this.openOutputStream()); } @Override public long getLastModified() { return 0L; } @Override public boolean delete() { return false; } @Override public Kind getKind() { return Kind.CLASS; } @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; return kind.equals(this.getKind()) && toUri().toString().endsWith(baseName); } @Override public NestingKind getNestingKind() { return null; } @Override public Modifier getAccessLevel() { return null; } @Override public String toString() { return getClass().getName() + "[" + this.toUri() + "]"; } }