public int read(byte[] b, int st, int len) throws IOException { if (owner.chunkLength <= 0) if (!owner.getData()) return -1; if (owner.chunkLength < len) len = owner.chunkLength; System.arraycopy(owner.inbuf, owner.chunkStart, b, st, len); owner.chunkLength -= len; owner.chunkStart += len; return len; }
/** Print the HTML tag. */ public static void printTag(PrintStream out, Hashtable atts) { out.print("<applet"); String v = (String) atts.get("codebase"); if (v != null) { out.print(" codebase=\"" + v + "\""); } v = (String) atts.get("code"); if (v == null) { v = "applet.class"; } out.print(" code=\"" + v + "\""); v = (String) atts.get("width"); if (v == null) { v = "150"; } out.print(" width=" + v); v = (String) atts.get("height"); if (v == null) { v = "100"; } out.print(" height=" + v); v = (String) atts.get("name"); if (v != null) { out.print(" name=\"" + v + "\""); } out.println(">"); // A very slow sorting algorithm int len = atts.size(); String params[] = new String[len]; len = 0; for (Enumeration e = atts.keys(); e.hasMoreElements(); ) { String param = (String) e.nextElement(); int i = 0; for (; i < len; i++) { if (params[i].compareTo(param) >= 0) { break; } } System.arraycopy(params, i, params, i + 1, len - i); params[i] = param; len++; } for (int i = 0; i < len; i++) { String param = params[i]; if (systemParam.get(param) == null) { out.println("<param name=" + param + " value=\"" + atts.get(param) + "\">"); } } out.println("</applet>"); }
private static void checkConnect(URL url) { SecurityManager security = System.getSecurityManager(); if (security != null) { try { j86.java.security.Permission perm = url.openConnection().getPermission(); if (perm != null) security.checkPermission(perm); else security.checkConnect(url.getHost(), url.getPort()); } catch (j86.java.io.IOException ioe) { security.checkConnect(url.getHost(), url.getPort()); } } }
private boolean need(int n) throws IOException { if (limit - pos >= n) return true; fill(); if (limit - pos >= n) return true; if (seenEOF) return false; byte nin[] = new byte[n + 100]; System.arraycopy(inbuf, pos, nin, 0, limit - pos); limit = limit - pos; pos = 0; inbuf = nin; fill(); return limit - pos >= n; }
/** Return an enumeration of all the accessible applets on this page. */ public Enumeration getApplets() { AppletSecurity security = (AppletSecurity) System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) { AppletPanel p = (AppletPanel) e.nextElement(); if (p.getDocumentBase().equals(panel.getDocumentBase())) { SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect"); if (panelSp.implies(sp)) { v.addElement(p.applet); } } } return v.elements(); }
private void fill() throws IOException { if (!seenEOF) { if (pos > 0 && pos < limit) { System.arraycopy(inbuf, pos, inbuf, 0, limit - pos); limit = limit - pos; pos = 0; } else if (pos >= limit) { pos = 0; limit = 0; } int bsize = inbuf.length; while (limit < bsize) { int n = underlyingInputStream.read(inbuf, limit, bsize - limit); if (n <= 0) { seenEOF = true; break; } limit += n; } } }
/** Get an applet by name. */ public Applet getApplet(String name) { AppletSecurity security = (AppletSecurity) System.getSecurityManager(); name = name.toLowerCase(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) { AppletPanel p = (AppletPanel) e.nextElement(); String param = p.getParameter("name"); if (param != null) { param = param.toLowerCase(); } if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) { SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect"); if (panelSp.implies(sp)) { return p.applet; } } } return null; }
/** * Send the initial set of events to the appletviewer event queue. On start-up the current * behaviour is to load the applet and call Applet.init() and Applet.start(). */ private void initEventQueue() { // appletviewer.send.event is an undocumented and unsupported system // property which is used exclusively for testing purposes. String eventList = System.getProperty("appletviewer.send.event"); if (eventList == null) { // Add the standard events onto the event queue. panel.sendEvent(AppletPanel.APPLET_LOAD); panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } else { // We're testing AppletViewer. Force the specified set of events // onto the event queue, wait for the events to be processed, and // exit. // The list of events that will be executed is provided as a // ","-separated list. No error-checking will be done on the list. String[] events = splitSeparator(",", eventList); for (int i = 0; i < events.length; i++) { System.out.println("Adding event to queue: " + events[i]); if (events[i].equals("dispose")) panel.sendEvent(AppletPanel.APPLET_DISPOSE); else if (events[i].equals("load")) panel.sendEvent(AppletPanel.APPLET_LOAD); else if (events[i].equals("init")) panel.sendEvent(AppletPanel.APPLET_INIT); else if (events[i].equals("start")) panel.sendEvent(AppletPanel.APPLET_START); else if (events[i].equals("stop")) panel.sendEvent(AppletPanel.APPLET_STOP); else if (events[i].equals("destroy")) panel.sendEvent(AppletPanel.APPLET_DESTROY); else if (events[i].equals("quit")) panel.sendEvent(AppletPanel.APPLET_QUIT); else if (events[i].equals("error")) panel.sendEvent(AppletPanel.APPLET_ERROR); else // non-fatal error if we get an unrecognized event System.out.println("Unrecognized event name: " + events[i]); } while (!panel.emptyEventQueue()) ; appletSystemExit(); } }
/* * Parse a keystore domain configuration file and associated collection * of keystore passwords to create a collection of KeyStore.Builder. */ private List<KeyStoreBuilderComponents> getBuilders( URI configuration, Map<String, KeyStore.ProtectionParameter> passwords) throws IOException { PolicyParser parser = new PolicyParser(true); // expand properties Collection<PolicyParser.DomainEntry> domains = null; List<KeyStoreBuilderComponents> builders = new ArrayList<>(); String uriDomain = configuration.getFragment(); try (InputStreamReader configurationReader = new InputStreamReader(PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) { parser.read(configurationReader); domains = parser.getDomainEntries(); } catch (MalformedURLException mue) { throw new IOException(mue); } catch (PolicyParser.ParsingException pe) { throw new IOException(pe); } for (PolicyParser.DomainEntry domain : domains) { Map<String, String> domainProperties = domain.getProperties(); if (uriDomain != null && (!uriDomain.equalsIgnoreCase(domain.getName()))) { continue; // skip this domain } if (domainProperties.containsKey(ENTRY_NAME_SEPARATOR)) { this.entryNameSeparator = domainProperties.get(ENTRY_NAME_SEPARATOR); // escape any regex meta characters char ch = 0; StringBuilder s = new StringBuilder(); for (int i = 0; i < this.entryNameSeparator.length(); i++) { ch = this.entryNameSeparator.charAt(i); if (REGEX_META.indexOf(ch) != -1) { s.append('\\'); } s.append(ch); } this.entryNameSeparatorRegEx = s.toString(); } Collection<PolicyParser.KeyStoreEntry> keystores = domain.getEntries(); for (PolicyParser.KeyStoreEntry keystore : keystores) { String keystoreName = keystore.getName(); Map<String, String> properties = new HashMap<>(domainProperties); properties.putAll(keystore.getProperties()); String keystoreType = DEFAULT_KEYSTORE_TYPE; if (properties.containsKey(KEYSTORE_TYPE)) { keystoreType = properties.get(KEYSTORE_TYPE); } Provider keystoreProvider = null; if (properties.containsKey(KEYSTORE_PROVIDER_NAME)) { String keystoreProviderName = properties.get(KEYSTORE_PROVIDER_NAME); keystoreProvider = Security.getProvider(keystoreProviderName); if (keystoreProvider == null) { throw new IOException("Error locating JCE provider: " + keystoreProviderName); } } File keystoreFile = null; if (properties.containsKey(KEYSTORE_URI)) { String uri = properties.get(KEYSTORE_URI); try { if (uri.startsWith("file://")) { keystoreFile = new File(new URI(uri)); } else { keystoreFile = new File(uri); } } catch (URISyntaxException | IllegalArgumentException e) { throw new IOException( "Error processing keystore property: " + "keystoreURI=\"" + uri + "\"", e); } } KeyStore.ProtectionParameter keystoreProtection = null; if (passwords.containsKey(keystoreName)) { keystoreProtection = passwords.get(keystoreName); } else if (properties.containsKey(KEYSTORE_PASSWORD_ENV)) { String env = properties.get(KEYSTORE_PASSWORD_ENV); String pwd = System.getenv(env); if (pwd != null) { keystoreProtection = new KeyStore.PasswordProtection(pwd.toCharArray()); } else { throw new IOException( "Error processing keystore property: " + "keystorePasswordEnv=\"" + env + "\""); } } else { keystoreProtection = new KeyStore.PasswordProtection(null); } builders.add( new KeyStoreBuilderComponents( keystoreName, keystoreType, keystoreProvider, keystoreFile, keystoreProtection)); } break; // skip other domains } if (builders.isEmpty()) { throw new IOException("Error locating domain configuration data " + "for: " + configuration); } return builders; }
protected boolean handleChunk(int key, byte[] buf, int st, int len) throws IOException { switch (key) { case bKGDChunk: Color c = null; switch (colorType) { case COLOR: case COLOR | ALPHA: pngassert(len == 6); c = new Color(buf[st] & 0xff, buf[st + 2] & 0xff, buf[st + 4] & 0xff); break; case COLOR | PALETTE: case COLOR | PALETTE | ALPHA: pngassert(len == 1); int ix = buf[st] & 0xFF; pngassert(red_map != null && ix < red_map.length); c = new Color(red_map[ix] & 0xff, green_map[ix] & 0xff, blue_map[ix] & 0xff); break; case GRAY: case GRAY | ALPHA: pngassert(len == 2); int t = buf[st] & 0xFF; c = new Color(t, t, t); break; } if (c != null) property("background", c); break; case cHRMChunk: property( "chromaticities", new Chromaticities( getInt(st), getInt(st + 4), getInt(st + 8), getInt(st + 12), getInt(st + 16), getInt(st + 20), getInt(st + 24), getInt(st + 28))); break; case gAMAChunk: if (len != 4) throw new PNGException("bogus gAMA"); gamma = getInt(st); if (gamma != 100000) property("gamma", gamma / 100000.0f); break; case hISTChunk: break; case IDATChunk: return false; case IENDChunk: break; case IHDRChunk: if (len != 13 || (width = getInt(st)) == 0 || (height = getInt(st + 4)) == 0) throw new PNGException("bogus IHDR"); bitDepth = getByte(st + 8); colorType = getByte(st + 9); compressionMethod = getByte(st + 10); filterMethod = getByte(st + 11); interlaceMethod = getByte(st + 12); /* this is not needed if(target!=null) target.setDimensions(width,height); */ break; case PLTEChunk: { int tsize = len / 3; red_map = new byte[tsize]; green_map = new byte[tsize]; blue_map = new byte[tsize]; for (int i = 0, j = st; i < tsize; i++, j += 3) { red_map[i] = buf[j]; green_map[i] = buf[j + 1]; blue_map[i] = buf[j + 2]; } } break; case pHYsChunk: break; case sBITChunk: break; case tEXtChunk: int klen = 0; while (klen < len && buf[st + klen] != 0) klen++; if (klen < len) { String tkey = new String(buf, st, klen); String tvalue = new String(buf, st + klen + 1, len - klen - 1); property(tkey, tvalue); } break; case tIMEChunk: property( "modtime", new GregorianCalendar( getShort(st + 0), getByte(st + 2) - 1, getByte(st + 3), getByte(st + 4), getByte(st + 5), getByte(st + 6)) .getTime()); break; case tRNSChunk: switch (colorType) { case PALETTE | COLOR: case PALETTE | COLOR | ALPHA: int alen = len; if (red_map != null) alen = red_map.length; alpha_map = new byte[alen]; System.arraycopy(buf, st, alpha_map, 0, len < alen ? len : alen); while (--alen >= len) alpha_map[alen] = (byte) 0xFF; break; case COLOR: // doesn't deal with 16 bit colors properly case COLOR | ALPHA: // doesn't deal with 16 bit colors properly pngassert(len == 6); if (bitDepth == 16) { transparentPixel_16 = new byte[6]; for (int i = 0; i < 6; i++) { transparentPixel_16[i] = (byte) getByte(st + i); } } else { transparentPixel = ((getShort(st + 0) & 0xFF) << 16) | ((getShort(st + 2) & 0xFF) << 8) | ((getShort(st + 4) & 0xFF)); } break; case GRAY: // doesn't deal with 16 bit colors properly case GRAY | ALPHA: // doesn't deal with 16 bit colors properly pngassert(len == 2); /* REMIND: Discarding the LSB for 16 bit depth here * means that the all pixels which match the MSB * will be treated as transparent. */ int t = getShort(st); t = 0xFF & ((bitDepth == 16) ? (t >> 8) : t); transparentPixel = (t << 16) | (t << 8) | t; break; } break; case zTXtChunk: break; } return true; }
/** Exit the program. Exit from the program (if not stand alone) - do no clean-up */ private void appletSystemExit() { if (factory.isStandalone()) System.exit(0); }