@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; }); }
setBytes(bytes); setCodeSource(codeSource); setAssertionSetting(assertionSetting);
/** {@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); } }
if (pkg.isSealed() && ! pkg.isSealed(classSpec.getCodeSource().getLocation())) { log.trace("Detected a sealing violation (attempt to define class %s in sealed package %s in %s)", name, packageName, module); byte[] bytes = classSpec.getBytes(); ByteBuffer byteBuffer = classSpec.getByteBuffer(); try { final ProtectionDomain protectionDomain = getProtectionDomain(classSpec.getCodeSource()); if (transformer != null) { ByteBuffer buffer = byteBuffer; throw e; final AssertionSetting setting = classSpec.getAssertionSetting(); if (setting != AssertionSetting.INHERIT) { setClassAssertionStatus(name, setting == AssertionSetting.ENABLED);
if (pkg.isSealed() && ! pkg.isSealed(classSpec.getCodeSource().getLocation())) { log.trace("Detected a sealing violation (attempt to define class %s in sealed package %s in %s)", name, packageName, module); byte[] bytes = classSpec.getBytes(); try { final ProtectionDomain protectionDomain = getProtectionDomain(classSpec.getCodeSource()); if (transformer != null) { try { throw e; final AssertionSetting setting = classSpec.getAssertionSetting(); if (setting != AssertionSetting.INHERIT) { setClassAssertionStatus(name, setting == AssertionSetting.ENABLED);
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) { baos.close(); is.close(); spec.setBytes(baos.toByteArray()); spec.setCodeSource(codeSource); return spec; } else if (size <= (long) Integer.MAX_VALUE) { spec.setBytes(bytes); spec.setCodeSource(codeSource); return spec; } else {
public synchronized ClassSpec getClassSpec(final String fileName) throws IOException { final ClassSpec spec = new ClassSpec(); final JarEntry entry = getJarEntry(fileName); if (entry == null) { spec.setBytes(baos.toByteArray()); spec.setCodeSource(new CodeSource(rootUrl, entry.getCodeSigners())); return spec; } else if (size <= (long) Integer.MAX_VALUE) { spec.setBytes(bytes); spec.setCodeSource(new CodeSource(rootUrl, entry.getCodeSigners())); return spec; } else {
if (file == null) return null; final long size = file.getSize(); final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream(); spec.setBytes(bytes); final CodeSigner[] entryCodeSigners = file.getCodeSigners(); final CodeSigners codeSigners = entryCodeSigners == null || entryCodeSigners.length == 0 ? EMPTY_CODE_SIGNERS : new CodeSigners(entryCodeSigners); codeSources.put(codeSigners, codeSource = new CodeSource(rootUrl, entryCodeSigners)); spec.setCodeSource(codeSource); return spec; } else {
/** {@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); } }
final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream(); spec.setBytes(bytes); final CodeSigner[] entryCodeSigners = file.getCodeSigners(); final CodeSigners codeSigners = entryCodeSigners == null || entryCodeSigners.length == 0 ? EMPTY_CODE_SIGNERS : new CodeSigners(entryCodeSigners); codeSources.put(codeSigners, codeSource = new CodeSource(rootUrl, entryCodeSigners)); spec.setCodeSource(codeSource); return spec; } else {
final ClassSpec spec = new ClassSpec(); synchronized (VFSResourceLoader.this) { final InputStream is = file.openStream(); spec.setBytes(bytes); spec.setCodeSource(new CodeSource(rootUrl, file.getCodeSigners())); return spec; } else {