示例#1
0
  @Override
  public void engineLoad(KeyStore.LoadStoreParameter param)
      throws IOException, NoSuchAlgorithmException, CertificateException {
    if (param instanceof DomainLoadStoreParameter) {
      DomainLoadStoreParameter domainParameter = (DomainLoadStoreParameter) param;
      List<KeyStoreBuilderComponents> builders =
          getBuilders(domainParameter.getConfiguration(), domainParameter.getProtectionParams());

      for (KeyStoreBuilderComponents builder : builders) {

        try {
          // Load the keystores (file-based and non-file-based)
          if (builder.file != null) {
            keystores.put(
                builder.name,
                KeyStore.Builder.newInstance(
                        builder.type, builder.provider, builder.file, builder.protection)
                    .getKeyStore());
          } else {
            keystores.put(
                builder.name,
                KeyStore.Builder.newInstance(builder.type, builder.provider, builder.protection)
                    .getKeyStore());
          }
        } catch (KeyStoreException e) {
          throw new IOException(e);
        }
      }
    } else {
      throw new UnsupportedOperationException(
          "This keystore must be loaded using a " + "DomainLoadStoreParameter");
    }
  }
示例#2
0
  /**
   * Loads the keystore from the given input stream.
   *
   * <p>If a password is given, it is used to check the integrity of the keystore data. Otherwise,
   * the integrity of the keystore is not checked.
   *
   * @param stream the input stream from which the keystore is loaded
   * @param password the (optional) password used to check the integrity of the keystore.
   * @exception IOException if there is an I/O or format problem with the keystore data
   * @exception NoSuchAlgorithmException if the algorithm used to check the integrity of the
   *     keystore cannot be found
   * @exception CertificateException if any of the certificates in the keystore could not be loaded
   */
  public void engineLoad(InputStream stream, char[] password)
      throws IOException, NoSuchAlgorithmException, CertificateException {
    // Support loading from a stream only for a JKS or default type keystore
    try {
      KeyStore keystore = null;

      try {
        keystore = KeyStore.getInstance("JKS");
        keystore.load(stream, password);

      } catch (Exception e) {
        // Retry
        if (!"JKS".equalsIgnoreCase(DEFAULT_KEYSTORE_TYPE)) {
          keystore = KeyStore.getInstance(DEFAULT_KEYSTORE_TYPE);
          keystore.load(stream, password);
        } else {
          throw e;
        }
      }
      String keystoreName = DEFAULT_STREAM_PREFIX + streamCounter++;
      keystores.put(keystoreName, keystore);

    } catch (Exception e) {
      throw new UnsupportedOperationException(
          "This keystore must be loaded using a " + "DomainLoadStoreParameter");
    }
  }
示例#3
0
  MemoryUsage getPeakMemoryUsage() {
    try {
      final Map<Object, Object> m = JvmContextFactory.getUserData();

      if (m != null) {
        final MemoryUsage cached = (MemoryUsage) m.get(entryPeakMemoryTag);
        if (cached != null) {
          if (log.isDebugOn())
            log.debug("getPeakMemoryUsage", entryPeakMemoryTag + " found in cache.");
          return cached;
        }

        MemoryUsage u = pool.getPeakUsage();
        if (u == null) u = ZEROS;

        m.put(entryPeakMemoryTag, u);
        return u;
      }
      // Should never come here.
      // Log error!
      log.trace("getPeakMemoryUsage", "ERROR: should never come here!");
      return ZEROS;
    } catch (RuntimeException x) {
      log.trace("getPeakMemoryUsage", "Failed to get MemoryUsage: " + x);
      log.debug("getPeakMemoryUsage", x);
      throw x;
    }
  }
示例#4
0
 /** Get an image ref. */
 static Ref getCachedImageRef(URL url) {
   synchronized (imageRefs) {
     AppletImageRef ref = (AppletImageRef) imageRefs.get(url);
     if (ref == null) {
       ref = new AppletImageRef(url);
       imageRefs.put(url, ref);
     }
     return ref;
   }
 }
示例#5
0
 /** Get an audio clip. */
 public AudioClip getAudioClip(URL url) {
   checkConnect(url);
   synchronized (audioClips) {
     AudioClip clip = (AudioClip) audioClips.get(url);
     if (clip == null) {
       audioClips.put(url, clip = new AppletAudioClip(url));
     }
     return clip;
   }
 }
示例#6
0
 final EventDispatcher getEventDispatcher() {
   // create and start the global event thread
   // TODO  need a way to stop this thread when the engine is done
   final ThreadGroup tg = Thread.currentThread().getThreadGroup();
   synchronized (dispatchers) {
     EventDispatcher eventDispatcher = dispatchers.get(tg);
     if (eventDispatcher == null) {
       eventDispatcher = new EventDispatcher();
       dispatchers.put(tg, eventDispatcher);
       eventDispatcher.start();
     }
     return eventDispatcher;
   }
 }
示例#7
0
  private void addDefault(String key, Object value) {
    if (compiledDefaults == null) {
      return;
    }

    String prefix = parsePrefix(key);
    if (prefix != null) {
      Map<String, Object> keys = compiledDefaults.get(prefix);
      if (keys == null) {
        keys = new HashMap<String, Object>();
        compiledDefaults.put(prefix, keys);
      }
      keys.put(key, value);
    }
  }
示例#8
0
  /**
   * Loads and processes the Hijrah calendar properties file for this calendarType. The starting
   * Hijrah date and the corresponding ISO date are extracted and used to calculate the epochDate
   * offset. The version number is identified and ignored. Everything else is the data for a year
   * with containing the length of each of 12 months.
   *
   * @throws DateTimeException if initialization of the calendar data from the resource fails
   */
  private void loadCalendarData() {
    try {
      String resourceName = calendarProperties.getProperty(PROP_PREFIX + typeId);
      Objects.requireNonNull(
          resourceName, "Resource missing for calendar: " + PROP_PREFIX + typeId);
      Properties props = readConfigProperties(resourceName);

      Map<Integer, int[]> years = new HashMap<>();
      int minYear = Integer.MAX_VALUE;
      int maxYear = Integer.MIN_VALUE;
      String id = null;
      String type = null;
      String version = null;
      int isoStart = 0;
      for (Map.Entry<Object, Object> entry : props.entrySet()) {
        String key = (String) entry.getKey();
        switch (key) {
          case KEY_ID:
            id = (String) entry.getValue();
            break;
          case KEY_TYPE:
            type = (String) entry.getValue();
            break;
          case KEY_VERSION:
            version = (String) entry.getValue();
            break;
          case KEY_ISO_START:
            {
              int[] ymd = parseYMD((String) entry.getValue());
              isoStart = (int) LocalDate.of(ymd[0], ymd[1], ymd[2]).toEpochDay();
              break;
            }
          default:
            try {
              // Everything else is either a year or invalid
              int year = Integer.valueOf(key);
              int[] months = parseMonths((String) entry.getValue());
              years.put(year, months);
              maxYear = Math.max(maxYear, year);
              minYear = Math.min(minYear, year);
            } catch (NumberFormatException nfe) {
              throw new IllegalArgumentException("bad key: " + key);
            }
        }
      }

      if (!getId().equals(id)) {
        throw new IllegalArgumentException("Configuration is for a different calendar: " + id);
      }
      if (!getCalendarType().equals(type)) {
        throw new IllegalArgumentException(
            "Configuration is for a different calendar type: " + type);
      }
      if (version == null || version.isEmpty()) {
        throw new IllegalArgumentException("Configuration does not contain a version");
      }
      if (isoStart == 0) {
        throw new IllegalArgumentException("Configuration does not contain a ISO start date");
      }

      // Now create and validate the array of epochDays indexed by epochMonth
      hijrahStartEpochMonth = minYear * 12;
      minEpochDay = isoStart;
      hijrahEpochMonthStartDays = createEpochMonths(minEpochDay, minYear, maxYear, years);
      maxEpochDay = hijrahEpochMonthStartDays[hijrahEpochMonthStartDays.length - 1];

      // Compute the min and max year length in days.
      for (int year = minYear; year < maxYear; year++) {
        int length = getYearLength(year);
        minYearLength = Math.min(minYearLength, length);
        maxYearLength = Math.max(maxYearLength, length);
      }
    } catch (Exception ex) {
      // Log error and throw a DateTimeException
      PlatformLogger logger = PlatformLogger.getLogger("j86.java.time.chrono");
      logger.severe("Unable to initialize Hijrah calendar proxy: " + typeId, ex);
      throw new DateTimeException("Unable to initialize HijrahCalendar: " + typeId, ex);
    }
  }