private final FileFilter filterDirs = new FileFilter() {
public boolean accept(File path) { return path.isDirectory(); }
};
- private byte[] bytes(File bfile) {
- byte[] bytes = new byte[2 * 1024];
- int pos = 0, in = 0;
- try {
- InputStream bin = new FileInputStream(bfile);
- while ((in = bin.read(bytes, pos, bytes.length - pos)) != -1) {
- pos += in;
- if (pos == bytes.length) {
- byte[] newbytes= new byte[pos * 2];
- System.arraycopy(bytes, 0, newbytes, 0, pos);
- bytes = newbytes;
- }
- }
- bin.close();
- } catch (IOException e) {
- System.out.println("Error reading class file"); // FIXME
- e.printStackTrace(); return null;
- }
- if (pos != bytes.length) {
- byte[] newbytes= new byte[pos * 2];
- System.arraycopy(bytes, 0, newbytes, 0, pos);
- bytes = newbytes;
- }
-
- return bytes;
- }
private void filterSources(List s, File dir, char[][] pack, String srcdir) {
List bclasses = new ArrayList();
File bdir = new File(builddir, str(pack, File.separatorChar));
if (veryverbose) System.out.println(" found in classloader: "+ c);
IBinaryType b = (IBinaryType)loaded.get(c);
if (b == null) loaded.put(c, b = new ClassFileReader(
- read(c.getResourceAsStream(classname)),
- (str(p, '/') + '/' + classname).toCharArray()));
+ bytes(c), (str(p, '/') + '/' + classname).toCharArray()));
return new NameEnvironmentAnswer(b, access);
} catch (ClassNotFoundException e) {
} catch (ClassFormatException e) {
e.printStackTrace();
throw new Error("ClassFormatException reading system class: " +
str(p, '.')+new String(n));
- } catch (IOException e) {
- e.printStackTrace();
- throw new Error("IOException reading system class: "+str(p, '.')+new String(n));
}
// cut out searches for java.* packages in sources list
return sb.toString().toCharArray();
}
- private static byte[] read(InputStream in) throws IOException {
- byte[] bytes = new byte[16];
- int off = 0, ret;
- while ((ret = in.read(bytes, off, bytes.length - off)) != -1) {
- off += ret;
- if (off == bytes.length) {
- byte[] nb = new byte[bytes.length * 2];
- System.arraycopy(bytes, 0, nb, 0, bytes.length);
- bytes = nb;
+ private static byte[] bytes(Class c) {
+ return bytes(c.getResourceAsStream('/' + c.getName().replace('.', '/') + ".class"));
+ }
+ private static byte[] bytes(File bfile) {
+ try { return bytes(new FileInputStream(bfile)); }
+ catch (FileNotFoundException e) { throw new Error("FileNotFoundException reading bytes: "+e); }
+ }
+ private static byte[] bytes(InputStream bin) {
+ byte[] bytes = new byte[2 * 1024];
+ int pos = 0, in = 0;
+ try {
+ while ((in = bin.read(bytes, pos, bytes.length - pos)) != -1) {
+ pos += in;
+ if (pos == bytes.length) {
+ byte[] newbytes= new byte[pos * 2];
+ System.arraycopy(bytes, 0, newbytes, 0, pos);
+ bytes = newbytes;
+ }
}
+ bin.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new Error("IOException reading class file: "+e);
}
- if (off != bytes.length) {
- byte[] nb = new byte[off];
- System.arraycopy(bytes, 0, nb, 0, off);
- bytes = nb;
+
+ if (pos != bytes.length) {
+ byte[] newbytes= new byte[pos * 2];
+ System.arraycopy(bytes, 0, newbytes, 0, pos);
+ bytes = newbytes;
}
+
return bytes;
}
-
}