replace assert with an if in case js tries to load a non-existent resource

Reviewed-by: kinsleyw
This commit is contained in:
akhil 2013-12-06 12:01:37 -08:00
parent 346e0d0d13
commit c6a314129e
1 changed files with 8 additions and 5 deletions

View File

@ -201,11 +201,14 @@ public abstract class Loader {
final byte[] data = new byte[BUFFERSIZE];
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(BUFFERSIZE);
try (final InputStream is = this.getClass().getResourceAsStream(id)) {
assert is != null;
int bytesRead = is.read(data, 0, data.length);
while (bytesRead != -1) {
buffer.write(data, 0, bytesRead);
bytesRead = is.read(data, 0, data.length);
if (is == null) {
return null;
} else {
for (int bytesRead = is.read(data, 0, data.length);
bytesRead != -1;
bytesRead = is.read(data, 0, data.length)) {
buffer.write(data, 0, bytesRead);
}
}
}
return new String(buffer.toByteArray(), "utf-8");