jtulach@1326: /** jtulach@1326: * Back 2 Browser Bytecode Translator jtulach@1326: * Copyright (C) 2012 Jaroslav Tulach jtulach@1326: * jtulach@1326: * This program is free software: you can redistribute it and/or modify jtulach@1326: * it under the terms of the GNU General Public License as published by jtulach@1326: * the Free Software Foundation, version 2 of the License. jtulach@1326: * jtulach@1326: * This program is distributed in the hope that it will be useful, jtulach@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of jtulach@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jtulach@1326: * GNU General Public License for more details. jtulach@1326: * jtulach@1326: * You should have received a copy of the GNU General Public License jtulach@1326: * along with this program. Look for COPYING file in the top folder. jtulach@1326: * If not, see http://opensource.org/licenses/GPL-2.0. tzezula@1324: */ tzezula@1324: tzezula@1324: package org.apidesign.bck2brwsr.dew; tzezula@1324: tzezula@1324: import java.io.BufferedReader; tzezula@1324: import java.io.FileNotFoundException; tzezula@1324: import java.io.IOException; tzezula@1324: import java.io.InputStream; tzezula@1324: import java.io.InputStreamReader; tzezula@1324: import java.io.OutputStream; tzezula@1324: import java.io.OutputStreamWriter; tzezula@1324: import java.io.Reader; tzezula@1324: import java.io.Writer; tzezula@1324: tzezula@1324: /** tzezula@1324: * tzezula@1324: * @author Tomas Zezula tzezula@1324: */ tzezula@1324: class ClassLoaderJavaFileObject extends BaseFileObject { tzezula@1324: tzezula@1324: ClassLoaderJavaFileObject(final String path) { tzezula@1324: super(path, getKind(path)); tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public InputStream openInputStream() throws IOException { tzezula@1324: final InputStream in = getClass().getClassLoader().getResourceAsStream(path.substring(1)); tzezula@1324: if (in == null) { tzezula@1324: throw new FileNotFoundException(path); tzezula@1324: } tzezula@1324: return in; tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public OutputStream openOutputStream() throws IOException { tzezula@1324: throw new UnsupportedOperationException("Read Only FileObject"); //NOI18N tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public Reader openReader(boolean ignoreEncodingErrors) throws IOException { tzezula@1324: return new InputStreamReader(openInputStream()); tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { tzezula@1324: final BufferedReader in = new BufferedReader(openReader(ignoreEncodingErrors)); tzezula@1324: try { tzezula@1324: final StringBuilder sb = new StringBuilder(); tzezula@1324: String line; tzezula@1324: while ((line = in.readLine()) != null) { tzezula@1324: sb.append(line); tzezula@1324: sb.append('\n'); //NOI18N tzezula@1324: } tzezula@1324: return sb.toString(); tzezula@1324: } finally { tzezula@1324: in.close(); tzezula@1324: } tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public Writer openWriter() throws IOException { tzezula@1324: return new OutputStreamWriter(openOutputStream()); tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public long getLastModified() { tzezula@1324: return System.currentTimeMillis(); tzezula@1324: } tzezula@1324: tzezula@1324: @Override tzezula@1324: public boolean delete() { tzezula@1324: return false; tzezula@1324: } tzezula@1324: tzezula@1324: }