author | tzezula |
Wed, 02 Oct 2013 21:00:24 +0200 | |
changeset 1324 | 263482b074e9 |
child 1325 | f7f25ea1bbec |
permissions | -rw-r--r-- |
tzezula@1324 | 1 |
/* |
tzezula@1324 | 2 |
* To change this license header, choose License Headers in Project Properties. |
tzezula@1324 | 3 |
* To change this template file, choose Tools | Templates |
tzezula@1324 | 4 |
* and open the template in the editor. |
tzezula@1324 | 5 |
*/ |
tzezula@1324 | 6 |
|
tzezula@1324 | 7 |
package org.apidesign.bck2brwsr.dew; |
tzezula@1324 | 8 |
|
tzezula@1324 | 9 |
import java.io.BufferedReader; |
tzezula@1324 | 10 |
import java.io.FileNotFoundException; |
tzezula@1324 | 11 |
import java.io.IOException; |
tzezula@1324 | 12 |
import java.io.InputStream; |
tzezula@1324 | 13 |
import java.io.InputStreamReader; |
tzezula@1324 | 14 |
import java.io.OutputStream; |
tzezula@1324 | 15 |
import java.io.OutputStreamWriter; |
tzezula@1324 | 16 |
import java.io.Reader; |
tzezula@1324 | 17 |
import java.io.Writer; |
tzezula@1324 | 18 |
|
tzezula@1324 | 19 |
/** |
tzezula@1324 | 20 |
* |
tzezula@1324 | 21 |
* @author Tomas Zezula |
tzezula@1324 | 22 |
*/ |
tzezula@1324 | 23 |
class ClassLoaderJavaFileObject extends BaseFileObject { |
tzezula@1324 | 24 |
|
tzezula@1324 | 25 |
ClassLoaderJavaFileObject(final String path) { |
tzezula@1324 | 26 |
super(path, getKind(path)); |
tzezula@1324 | 27 |
} |
tzezula@1324 | 28 |
|
tzezula@1324 | 29 |
@Override |
tzezula@1324 | 30 |
public InputStream openInputStream() throws IOException { |
tzezula@1324 | 31 |
final InputStream in = getClass().getClassLoader().getResourceAsStream(path.substring(1)); |
tzezula@1324 | 32 |
if (in == null) { |
tzezula@1324 | 33 |
getClass().getClassLoader().getResourceAsStream(path.substring(1)); |
tzezula@1324 | 34 |
throw new FileNotFoundException(path); |
tzezula@1324 | 35 |
|
tzezula@1324 | 36 |
} |
tzezula@1324 | 37 |
return in; |
tzezula@1324 | 38 |
} |
tzezula@1324 | 39 |
|
tzezula@1324 | 40 |
@Override |
tzezula@1324 | 41 |
public OutputStream openOutputStream() throws IOException { |
tzezula@1324 | 42 |
throw new UnsupportedOperationException("Read Only FileObject"); //NOI18N |
tzezula@1324 | 43 |
} |
tzezula@1324 | 44 |
|
tzezula@1324 | 45 |
@Override |
tzezula@1324 | 46 |
public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
tzezula@1324 | 47 |
return new InputStreamReader(openInputStream()); |
tzezula@1324 | 48 |
} |
tzezula@1324 | 49 |
|
tzezula@1324 | 50 |
@Override |
tzezula@1324 | 51 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
tzezula@1324 | 52 |
final BufferedReader in = new BufferedReader(openReader(ignoreEncodingErrors)); |
tzezula@1324 | 53 |
try { |
tzezula@1324 | 54 |
final StringBuilder sb = new StringBuilder(); |
tzezula@1324 | 55 |
String line; |
tzezula@1324 | 56 |
while ((line = in.readLine()) != null) { |
tzezula@1324 | 57 |
sb.append(line); |
tzezula@1324 | 58 |
sb.append('\n'); //NOI18N |
tzezula@1324 | 59 |
} |
tzezula@1324 | 60 |
return sb.toString(); |
tzezula@1324 | 61 |
} finally { |
tzezula@1324 | 62 |
in.close(); |
tzezula@1324 | 63 |
} |
tzezula@1324 | 64 |
} |
tzezula@1324 | 65 |
|
tzezula@1324 | 66 |
@Override |
tzezula@1324 | 67 |
public Writer openWriter() throws IOException { |
tzezula@1324 | 68 |
return new OutputStreamWriter(openOutputStream()); |
tzezula@1324 | 69 |
} |
tzezula@1324 | 70 |
|
tzezula@1324 | 71 |
@Override |
tzezula@1324 | 72 |
public long getLastModified() { |
tzezula@1324 | 73 |
return System.currentTimeMillis(); |
tzezula@1324 | 74 |
} |
tzezula@1324 | 75 |
|
tzezula@1324 | 76 |
@Override |
tzezula@1324 | 77 |
public boolean delete() { |
tzezula@1324 | 78 |
return false; |
tzezula@1324 | 79 |
} |
tzezula@1324 | 80 |
|
tzezula@1324 | 81 |
} |