コード例 #1
0
  /**
   * Gets the JAR URL of the suite. This is only for the installer.
   *
   * @return URL of the JAR, never null, even in development environments
   */
  public String getJarUrl() {
    RandomAccessStream storage = new RandomAccessStream(classSecurityToken);
    DataInputStream storageStream;

    try {
      storage.connect(getStorageRoot() + Installer.JAR_URL_FILENAME, Connector.READ);

      // convert the JAR URL to UTF8 and write it to storage
      storageStream = storage.openDataInputStream();
      return storageStream.readUTF();
    } catch (Exception e) {
      // old installations did not have JAR URL's
      return "unknown";
    } finally {
      try {
        storage.disconnect();
      } catch (IOException e) {
        // ignore
      }
    }
  }
コード例 #2
0
  /** Reads the suite settings from storage. */
  private void readSettings() {
    byte[] maximums = Permissions.getEmptySet();
    byte[] currentLevels = Permissions.getEmptySet();
    RandomAccessStream storage = new RandomAccessStream(classSecurityToken);
    DataInputStream storageStream;
    int version;
    int count;

    permissions = new byte[2][];
    permissions[Permissions.MAX_LEVELS] = maximums;
    permissions[Permissions.CUR_LEVELS] = currentLevels;

    try {
      storage.connect(getStorageRoot() + Installer.SETTINGS_FILENAME, Connector.READ);
      try {
        storageStream = storage.openDataInputStream();

        version = storageStream.readByte();
        /*
         * only version 1 are handled by the method
         * 0 means that this is a beta version that are not handled
         * by the method. Note that version number only has to
         * increase if data has been removed, not if new data has been
         * added to the end of the file.
         */
        if (version != 1) {
          System.out.println("Corrupt application settings file.");
          return;
        }

        trusted = storageStream.readBoolean();

        pushInterruptSetting = storageStream.readByte();

        count = storageStream.readByte();
        storageStream.readFully(currentLevels, 0, count);

        count = storageStream.readByte();
        storageStream.readFully(maximums, 0, count);
      } finally {
        storage.disconnect();
      }
    } catch (IOException e) {
      // ignore, old settings files are shorter
    }
  }
コード例 #3
0
  /**
   * Gets properites from a symbolically named installed package. The properties are the attributes
   * in the application descriptor and JAR Manifest.
   */
  private void getPropertiesFromStorage() {
    RandomAccessStream myStorage;
    int size;
    byte[] buffer;
    InputStream is;
    DataInputStream dis;
    String jadEncoding = null;

    myStorage = new RandomAccessStream(classSecurityToken);

    // Get the JAD encoding, if the server provided one
    try {
      myStorage.connect(storageRoot + Installer.JAD_ENCODING_FILENAME, Connector.READ);
      try {
        // convert the JAD encoding to UTF8 and write it to storage
        dis = myStorage.openDataInputStream();
        try {
          jadEncoding = dis.readUTF();
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // servers can choose the default encoding by not providing one
    }

    // Load .jad file
    bufferedJadProps = new JadProperties();
    try {
      myStorage.connect(storageRoot + Installer.JAD_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJadProps.load(is, jadEncoding);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // Jar only install
    }

    try {
      // Get Manifest file so we can buffer it
      myStorage.connect(storageRoot + Installer.MANIFEST_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJarProps = new ManifestProperties();
          bufferedJarProps.load(is);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // ignore
    }
  }