@Override public ClassSpec getClassSpec(final String fileName) throws IOException { final Path file; try { file = root.resolve(fileName); } catch (InvalidPathException ignored) { return null; } return doPrivilegedIfNeeded(context, IOException.class, () -> { if (!Files.exists(file)) { return null; } final ClassSpec spec = new ClassSpec(); spec.setCodeSource(codeSource); spec.setBytes(Files.readAllBytes(file)); return spec; }); }
private ClassSpec doGetClassSpec(final String fileName) throws IOException { final File file = new File(getRoot(), fileName); if (! file.exists()) { return null; } final long size = file.length(); final ClassSpec spec = new ClassSpec(); spec.setCodeSource(codeSource); final InputStream is = new FileInputStream(file); try { if (size <= (long) Integer.MAX_VALUE) { final int castSize = (int) size; byte[] bytes = new byte[castSize]; int a = 0, res; while ((res = is.read(bytes, a, castSize - a)) > 0) { a += res; } // done is.close(); spec.setBytes(bytes); return spec; } else { throw new IOException("Resource is too large to be a valid class file"); } } finally { StreamUtil.safeClose(is); } }
public synchronized ClassSpec getClassSpec(final String fileName) throws IOException { final ClassSpec spec = new ClassSpec(); final JarEntry entry = getJarEntry(fileName); if (entry == null) {
/** {@inheritDoc} */ public ClassSpec getClassSpec(final String name) throws IOException { final String fileName = name.replace('.', '/') + ".class"; final VirtualFile file = root.getChild(fileName); if (!file.exists()) { return null; } final long size = file.getSize(); final ClassSpec spec = new ClassSpec(); final InputStream is = file.openStream(); try { if (size <= (long) Integer.MAX_VALUE) { final int castSize = (int) size; byte[] bytes = new byte[castSize]; int a = 0, res; while ((res = is.read(bytes, a, castSize - a)) > 0) { a += res; } // done is.close(); spec.setBytes(bytes); return spec; } else { throw new IOException("Resource is too large to be a valid class file"); } } finally { VFSUtils.safeClose(is); } }
public synchronized ClassSpec getClassSpec(final String fileName) throws IOException { final ClassSpec spec = new ClassSpec(); final JarEntry entry = getJarEntry(fileName); if (entry == null) {
if (file == null) return null; final long size = file.getSize(); final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream();
final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream();
final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream();
/** {@inheritDoc} */ public ClassSpec getClassSpec(final String name) throws IOException { final VirtualFile file = root.getChild(name); if (!file.exists()) { return null; } final long size = file.getSize(); final ClassSpec spec = new ClassSpec(); final InputStream is = file.openStream(); try { if (size <= (long) Integer.MAX_VALUE) { final int castSize = (int) size; byte[] bytes = new byte[castSize]; int a = 0, res; while ((res = is.read(bytes, a, castSize - a)) > 0) { a += res; } // done is.close(); spec.setBytes(bytes); spec.setCodeSource(new CodeSource(rootUrl, file.getCodeSigners())); return spec; } else { throw ServerMessages.MESSAGES.resourceTooLarge(); } } finally { VFSUtils.safeClose(is); } }