public final char[] getTextBuffer() {
if (textBuffer == null) {
try {
InputStream in = file.openInputStream();
Reader r = null;
AlbiteStreamReader asr = null;
final boolean auto =
AUTO_ENCODING.equalsIgnoreCase(currentEncoding);
if (auto) {
currentEncoding = Encodings.DEFAULT;
}
if (processHtmlEntities) {
if (!in.markSupported()) {
in = new BufferedInputStream(in);
}
/*
* Warning: if the XhtmlStreamReader is not used,
* then the HtmlParser won't work, as
* it relies on modified versions of '<' and '>'
*/
asr = new AlbiteStreamReader(in, currentEncoding);
r = new XhtmlStreamReader(asr, auto, true);
} else {
asr = new AlbiteStreamReader(in, currentEncoding);
r = asr;
}
try {
textBuffer = new char[fileSize];
int read = r.read(textBuffer);
if (read == -1) {
return new char[0];
}
if (read < fileSize) {
char[] res = new char[read];
System.arraycopy(textBuffer, 0, res, 0, read);
textBuffer = res;
}
currentEncoding = asr.getEncoding();
} catch (IOException e) {
//#debug
AlbiteMIDlet.LOGGER.log(e);
textBuffer = new char[0];