author | Jaroslav Tulach <jtulach@netbeans.org> |
Thu, 03 Oct 2013 10:02:13 +0200 | |
changeset 1326 | 8ae6a6c42b5f |
parent 1325 | f7f25ea1bbec |
permissions | -rw-r--r-- |
jtulach@1326 | 1 |
/** |
jtulach@1326 | 2 |
* Back 2 Browser Bytecode Translator |
jtulach@1326 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jtulach@1326 | 4 |
* |
jtulach@1326 | 5 |
* This program is free software: you can redistribute it and/or modify |
jtulach@1326 | 6 |
* it under the terms of the GNU General Public License as published by |
jtulach@1326 | 7 |
* the Free Software Foundation, version 2 of the License. |
jtulach@1326 | 8 |
* |
jtulach@1326 | 9 |
* This program is distributed in the hope that it will be useful, |
jtulach@1326 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jtulach@1326 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jtulach@1326 | 12 |
* GNU General Public License for more details. |
jtulach@1326 | 13 |
* |
jtulach@1326 | 14 |
* You should have received a copy of the GNU General Public License |
jtulach@1326 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jtulach@1326 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
tzezula@1324 | 17 |
*/ |
tzezula@1324 | 18 |
|
tzezula@1324 | 19 |
package org.apidesign.bck2brwsr.dew; |
tzezula@1324 | 20 |
|
tzezula@1324 | 21 |
import java.io.BufferedReader; |
tzezula@1324 | 22 |
import java.io.FileNotFoundException; |
tzezula@1324 | 23 |
import java.io.IOException; |
tzezula@1324 | 24 |
import java.io.InputStream; |
tzezula@1324 | 25 |
import java.io.InputStreamReader; |
tzezula@1324 | 26 |
import java.io.OutputStream; |
tzezula@1324 | 27 |
import java.io.OutputStreamWriter; |
tzezula@1324 | 28 |
import java.io.Reader; |
tzezula@1324 | 29 |
import java.io.Writer; |
tzezula@1324 | 30 |
|
tzezula@1324 | 31 |
/** |
tzezula@1324 | 32 |
* |
tzezula@1324 | 33 |
* @author Tomas Zezula |
tzezula@1324 | 34 |
*/ |
tzezula@1324 | 35 |
class ClassLoaderJavaFileObject extends BaseFileObject { |
tzezula@1324 | 36 |
|
tzezula@1324 | 37 |
ClassLoaderJavaFileObject(final String path) { |
tzezula@1324 | 38 |
super(path, getKind(path)); |
tzezula@1324 | 39 |
} |
tzezula@1324 | 40 |
|
tzezula@1324 | 41 |
@Override |
tzezula@1324 | 42 |
public InputStream openInputStream() throws IOException { |
tzezula@1324 | 43 |
final InputStream in = getClass().getClassLoader().getResourceAsStream(path.substring(1)); |
tzezula@1324 | 44 |
if (in == null) { |
tzezula@1324 | 45 |
throw new FileNotFoundException(path); |
tzezula@1324 | 46 |
} |
tzezula@1324 | 47 |
return in; |
tzezula@1324 | 48 |
} |
tzezula@1324 | 49 |
|
tzezula@1324 | 50 |
@Override |
tzezula@1324 | 51 |
public OutputStream openOutputStream() throws IOException { |
tzezula@1324 | 52 |
throw new UnsupportedOperationException("Read Only FileObject"); //NOI18N |
tzezula@1324 | 53 |
} |
tzezula@1324 | 54 |
|
tzezula@1324 | 55 |
@Override |
tzezula@1324 | 56 |
public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
tzezula@1324 | 57 |
return new InputStreamReader(openInputStream()); |
tzezula@1324 | 58 |
} |
tzezula@1324 | 59 |
|
tzezula@1324 | 60 |
@Override |
tzezula@1324 | 61 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
tzezula@1324 | 62 |
final BufferedReader in = new BufferedReader(openReader(ignoreEncodingErrors)); |
tzezula@1324 | 63 |
try { |
tzezula@1324 | 64 |
final StringBuilder sb = new StringBuilder(); |
tzezula@1324 | 65 |
String line; |
tzezula@1324 | 66 |
while ((line = in.readLine()) != null) { |
tzezula@1324 | 67 |
sb.append(line); |
tzezula@1324 | 68 |
sb.append('\n'); //NOI18N |
tzezula@1324 | 69 |
} |
tzezula@1324 | 70 |
return sb.toString(); |
tzezula@1324 | 71 |
} finally { |
tzezula@1324 | 72 |
in.close(); |
tzezula@1324 | 73 |
} |
tzezula@1324 | 74 |
} |
tzezula@1324 | 75 |
|
tzezula@1324 | 76 |
@Override |
tzezula@1324 | 77 |
public Writer openWriter() throws IOException { |
tzezula@1324 | 78 |
return new OutputStreamWriter(openOutputStream()); |
tzezula@1324 | 79 |
} |
tzezula@1324 | 80 |
|
tzezula@1324 | 81 |
@Override |
tzezula@1324 | 82 |
public long getLastModified() { |
tzezula@1324 | 83 |
return System.currentTimeMillis(); |
tzezula@1324 | 84 |
} |
tzezula@1324 | 85 |
|
tzezula@1324 | 86 |
@Override |
tzezula@1324 | 87 |
public boolean delete() { |
tzezula@1324 | 88 |
return false; |
tzezula@1324 | 89 |
} |
tzezula@1324 | 90 |
|
tzezula@1324 | 91 |
} |