Ejemplo n.º 1
0
  static {
    try {
      // 判断是否是生产环境的开关,1:加载生产环境的配置,0:加在测试环境的配置
      InputStream in =
          MySQLHelper.class.getClassLoader().getResourceAsStream("/config/switch.properties");
      properties.load(in);
      isProduction = properties.getProperty("isProduction");
      properties.clear();

      if ("1".equals(isProduction)) {
        in = MySQLHelper.class.getResourceAsStream("/config/db/jdbc_prod.properties");
      } else {
        in = MySQLHelper.class.getResourceAsStream("/config/db/jdbc_test.properties");
      }
      // InputStream  in=MySQLHelper.class.getResourceAsStream("/system_test.properties");
      properties.load(in);
      driver = properties.getProperty("mydb.driverClass");
      url = properties.getProperty("mydb.url");
      user = properties.getProperty("mydb.username");
      password = properties.getProperty("mydb.password");
      properties.clear();

      Class.forName(driver);

    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("failed to connect to MySQL");
    }
  }
  private static String load(String currentLanguage) {

    defaultMappings.clear();
    mappings.clear();

    try {
      InputStream langStream =
          InvTweaksLocalization.class.getResourceAsStream(
              "lang/" + currentLanguage + ".properties");
      InputStream defaultLangStream =
          InvTweaksLocalization.class.getResourceAsStream(
              "lang/" + DEFAULT_LANGUAGE + ".properties");

      mappings.load((langStream == null) ? defaultLangStream : langStream);
      defaultMappings.load(defaultLangStream);

      if (langStream != null) {
        langStream.close();
      }
      defaultLangStream.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return currentLanguage;
  }
Ejemplo n.º 3
0
  @Test
  public void testNestedProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("hello", p.getBaseValue("key1"));
    assertEquals("hello", p.getValue("key1"));
    assertEquals("Hi!", p.getValue("key1", "one"));
    assertEquals("Hola!", p.getValue("key1", "one.two"));
    assertEquals("world", p.getValue("key2", "one.two"));
    assertNull(p.getValue("key2", "one"));
    assertEquals("Grazias", p.getValue("key3", "one.two"));
    assertEquals("Grazias", p.getValue("key3", "one"));

    Properties prop = new Properties();
    p.extractProps(prop);
    assertEquals(3, prop.size());
    assertEquals("hello", prop.getProperty("key1"));

    prop.clear();
    p.extractProps(prop, "one");
    assertEquals(3 + 1, prop.size());
    assertEquals("Hi!", prop.getProperty("key1"));
    assertEquals("Grazias", prop.getProperty("key3"));

    prop.clear();
    p.extractProps(prop, "one.two");
    assertEquals(3 + 2, prop.size());
    assertEquals("Hola!", prop.getProperty("key1"));
    assertEquals("world", prop.getProperty("key2"));
    assertEquals("Grazias", prop.getProperty("key3"));
  }
Ejemplo n.º 4
0
 public static String identFromRecognition() {
   Enumeration<Object> e = Devices.listDevices(true);
   if (!e.hasMoreElements()) {
     MyLogger.getLogger().error("No device is registered in Flashtool.");
     MyLogger.getLogger().error("You can only flash devices.");
     return "";
   }
   boolean found = false;
   Properties founditems = new Properties();
   founditems.clear();
   Properties buildprop = new Properties();
   buildprop.clear();
   while (e.hasMoreElements()) {
     DeviceEntry current = Devices.getDevice((String) e.nextElement());
     String prop = current.getBuildProp();
     if (!buildprop.containsKey(prop)) {
       String readprop = DeviceProperties.getProperty(prop);
       buildprop.setProperty(prop, readprop);
     }
     Iterator<String> i = current.getRecognitionList().iterator();
     String localdev = buildprop.getProperty(prop);
     while (i.hasNext()) {
       String pattern = i.next().toUpperCase();
       if (localdev.toUpperCase().equals(pattern)) {
         founditems.put(current.getId(), current.getName());
       }
     }
   }
   if (founditems.size() == 1) {
     return (String) founditems.keys().nextElement();
   } else return "";
 }
Ejemplo n.º 5
0
  private static void checkUpdate() {
    TexturePackBase selectedTexturePack =
        MCPatcherUtils.getMinecraft().texturePackList.getSelectedTexturePack();
    if (selectedTexturePack == lastTexturePack) {
      return;
    }
    MCPatcherUtils.info("refreshing connected textures");
    lastTexturePack = selectedTexturePack;
    terrainTexture = getTexture("/terrain.png");
    if (Tessellator.instance instanceof SuperTessellator) {
      ((SuperTessellator) Tessellator.instance).clearTessellators();
    }

    blockOverrides = loadOverrides("block", Block.blocksList.length, false);
    tileOverrides = loadOverrides("terrain", NUM_TILES, true);

    Properties properties = new Properties();

    if (enableGlass) {
      properties.clear();
      properties.setProperty("method", "glass");
      properties.setProperty("connect", "block");
      loadBasicOverride(properties, blockOverrides, BLOCK_ID_GLASS);
    }

    if (enableGlassPane) {
      properties.clear();
      properties.setProperty("method", "glass");
      properties.setProperty("connect", "block");
      loadBasicOverride(properties, blockOverrides, BLOCK_ID_GLASS_PANE);
    }

    if (enableBookshelf) {
      properties.clear();
      properties.setProperty("method", "bookshelf");
      properties.setProperty("connect", "block");
      loadBasicOverride(properties, blockOverrides, BLOCK_ID_BOOKSHELF);
    }

    if (enableSandstone) {
      properties.clear();
      properties.setProperty("method", "sandstone");
      properties.setProperty("connect", "tile");
      properties.setProperty("metadata", "0");
      loadBasicOverride(properties, tileOverrides, TERRAIN_ID_SANDSTONE_SIDE);
    }

    if (enableOutline) {
      setupOutline();
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, terrainTexture);
  }
Ejemplo n.º 6
0
 private static void load() {
   if (props == null) props = new Properties();
   else props.clear();
   File[] list = (new File(OS.getWorkDir() + OS.getFileSeparator() + "devices")).listFiles();
   if (list == null) return;
   for (int i = 0; i < list.length; i++) {
     if (list[i].isDirectory()) {
       PropertiesFile p = new PropertiesFile();
       String device =
           list[i].getPath().substring(list[i].getPath().lastIndexOf(OS.getFileSeparator()) + 1);
       try {
         if (!device.toLowerCase().equals("busybox")) {
           p.open(
               "",
               new File(list[i].getPath() + OS.getFileSeparator() + device + ".properties")
                   .getAbsolutePath());
           DeviceEntry entry = new DeviceEntry(p);
           if (device.equals(entry.getId())) props.put(device, entry);
           else MyLogger.getLogger().error(device + " : this bundle is not valid");
         }
       } catch (Exception fne) {
         MyLogger.getLogger().error(device + " : this bundle is not valid");
       }
     }
   }
 }
Ejemplo n.º 7
0
 private void parse(Properties properties, String prefix) {
   properties.clear();
   for (String found : found(prefix)) {
     Property property = new Property(StringUtils.removeStartIgnoreCase(found, prefix));
     properties.setProperty(property.getName(), property.getValue());
   }
 }
Ejemplo n.º 8
0
  public void writeAndRead(int count) {
    Properties properties = new Properties();
    properties.setProperty("counter", (new Integer(-1)).toString());

    try {
      for (int i = 0; i < count; i++) {
        FileOutputStream fout = new FileOutputStream(".tmp.properties");
        BufferedOutputStream out = new BufferedOutputStream(fout);
        properties.setProperty(
            "counter",
            (new Integer(Integer.valueOf(properties.getProperty("counter")).intValue() + 1)
                .toString()));
        properties.store(out, "Simple counter test");
        properties.clear();
        out.close();

        FileInputStream fin = new FileInputStream(".tmp.properties");
        BufferedInputStream in = new BufferedInputStream(fin);
        properties.load(in);
        in.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 9
0
 private static void load() {
   Properties prop = PropertyUtil.load("zoo.properties");
   address = prop.getProperty("address");
   kafkaPort = prop.getProperty("kafkaPort");
   prop.clear();
   prop = null;
 }
 public void loadProperties() throws IOException {
   log.debug("loadProperties()");
   File file = getPropertiesFile();
   FileInputStream in = new FileInputStream(file);
   properties.clear();
   properties.load(in);
 }
Ejemplo n.º 11
0
  private void loadFile(String path) throws FileNotFoundException, IOException {

    try {
      lock.lock();

      if (isReloadComplete) return;

      // Properties p = new
      // Properties();
      File file = new File(path);
      if (file.exists()) {
        lastModifyTime = file.lastModified();
        InputStream inStream = null;
        try {
          inStream = new FileInputStream(file);
          prop.clear();
          prop.load(inStream);
          isReloadComplete = true;
        } finally {
          if (null != inStream) {
            inStream.close();
            inStream = null;
          }
        }

      } else {
        throw new FileNotFoundException("文件没找到: " + file.getAbsolutePath());
      }
    } finally {
      lock.unlock();
    }
    // return p;
  }
Ejemplo n.º 12
0
  /**
   * Loads the configuration
   *
   * @throws ConfigurationException
   */
  public void load() throws ConfigurationException {
    System.out.println("Loading configuration..."); // $NON-NLS-1$
    properties.clear();
    fixedProperties.clear();

    System.out.println("-> loading default properties");
    loadDefaultCfg();
    System.out.println("-> loading fixed properties");
    loadFixedCfg();
    System.out.println("-> loading system properties");
    loadSystemCfgFile();
    System.out.println("-> loading local properties");
    loadLocalCfgFile();
    // Try to define userHome from the config file
    System.out.println("-> setting user home");
    userHome = new File(System.getProperty("user.home"));
    String confHome = getProperty(USER_HOME_P);
    if ((confHome != null) && !confHome.equals("")) userHome = new File(confHome);
    String myDocString = getProperty(USER_DIRNAME_P);
    if ((myDocString != null) && (!myDocString.equals(""))) {
      File myDocDir = new File(userHome, myDocString);
      if (myDocDir.exists()) userHome = myDocDir;
    }
    // Check if we are in execution mode
    System.out.println("-> checking execution mode");
    testExecutionMode();
    System.out.println("-> loading scripting languages");
    loadScriptingLanguages(fixedProperties);
    System.out.println("-> langage " + getLanguage() + " is used");
    defaultLanguage = (getLanguage().compareTo(getDefaultLanguage()) == 0);
    System.out.println("-> loading localized messages");
    // Load localized messages
    try {
      // loads the language
      Messages.loadLocalizedResource(getLanguage());
      org.colombbus.tangara.net.Messages.loadLocalizedResource(getLanguage());
    } catch (Throwable th) {
      System.err.println("error while loading language configuration: " + th);
    }
    System.out.println("-> loading package info");
    loadPackageInfo(fixedProperties);
    System.out.println("-> loading engine");
    loadEngine(defaultEngineName);
    System.out.println("-> loading objects");
    loadObjects();
    System.out.println("Configuration loaded"); // $NON-NLS-1$
  }
    /**
     * Tests fix for BUG#20685022 - SSL CONNECTION TO MYSQL 5.7.6 COMMUNITY SERVER FAILS
     * 
     * This test is duplicated in testuite.regression.ConnectionRegressionTest.testBug20685022().
     * 
     * @throws Exception
     *             if the test fails.
     */
    public void testBug20685022() throws Exception {
        if (!isCommunityEdition()) {
            return;
        }

        final Properties props = new Properties();

        /*
         * case 1: non verifying server certificate
         */
        props.clear();
        props.setProperty("useSSL", "true");
        props.setProperty("requireSSL", "true");
        props.setProperty("verifyServerCertificate", "false");

        getConnectionWithProps(props);

        /*
         * case 2: verifying server certificate using key store provided by connection properties
         */
        props.clear();
        props.setProperty("useSSL", "true");
        props.setProperty("requireSSL", "true");
        props.setProperty("verifyServerCertificate", "true");
        props.setProperty("trustCertificateKeyStoreUrl", "file:src/testsuite/ssl-test-certs/test-cert-store");
        props.setProperty("trustCertificateKeyStoreType", "JKS");
        props.setProperty("trustCertificateKeyStorePassword", "password");

        getConnectionWithProps(props);

        /*
         * case 3: verifying server certificate using key store provided by system properties
         */
        props.clear();
        props.setProperty("useSSL", "true");
        props.setProperty("requireSSL", "true");
        props.setProperty("verifyServerCertificate", "true");

        String trustStorePath = "src/testsuite/ssl-test-certs/test-cert-store";
        System.setProperty("javax.net.ssl.keyStore", trustStorePath);
        System.setProperty("javax.net.ssl.keyStorePassword", "password");
        System.setProperty("javax.net.ssl.trustStore", trustStorePath);
        System.setProperty("javax.net.ssl.trustStorePassword", "password");

        getConnectionWithProps(props);
    }
 /**
  * Sets the JNDI environment to be used when instantiating a JNDI InitialContext. This
  * InitialContext is used to locate the backend ConnectionPoolDataSource.
  *
  * @param properties the JNDI environment property to set which will overwrite any current
  *     settings
  */
 void setJndiEnvironment(Properties properties) {
   if (jndiEnvironment == null) {
     jndiEnvironment = new Properties();
   } else {
     jndiEnvironment.clear();
   }
   jndiEnvironment.putAll(properties);
 }
 @Override
 public void setEnvironment(Map<String, Object> environment) {
   ConfigurationMapFactoryBean factory = new ConfigurationMapFactoryBean();
   factory.setEnvironment(environment);
   factory.setPrefix("pool.plugins.meta.db");
   factory.buildMap();
   properties.clear();
   properties.putAll(factory.getObject());
 }
Ejemplo n.º 16
0
 @Override
 public void setState(InputStream input) throws Exception {
   if (iProperties == null) {
     iProperties = new Properties();
   } else {
     iProperties.clear();
   }
   iProperties.load(input);
 }
Ejemplo n.º 17
0
  public void load(boolean clearFirst) throws Exception {

    if (clearFirst) m_prefs.clear();

    File prefFile = _getPrefFile();
    if (!prefFile.exists()) return;

    m_prefs.loadFromXML(new FileInputStream(prefFile));
  }
Ejemplo n.º 18
0
 public void reloadProperties() {
   synchronized (properties) {
     properties.clear();
     try {
       properties.load(stringToStream(getValue()));
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 19
0
 /** @tests java.util.Properties#Properties() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "Properties",
     args = {})
 public void test_Constructor() {
   Properties p = new Properties();
   // do something to avoid getting a variable unused warning
   p.clear();
 }
Ejemplo n.º 20
0
 /**
  * Loads the configuration from the properties file.
  *
  * @throws IOException if an error occurs while loading the property file
  */
 public void loadConfig() throws IOException {
   InputStream propStream = getClass().getClassLoader().getResourceAsStream(propFile);
   if (propStream == null) {
     throw new IOException(
         "Config properties file " + propFile + " is missing from the classpath.");
   }
   properties.clear();
   properties.load(propStream);
   propStream.close();
 }
Ejemplo n.º 21
0
 protected void clearInstance() throws Persistence.PersistenceException {
   final Enumeration<?> propertyNames = properties.propertyNames();
   // We delete all the cached files
   while (propertyNames.hasMoreElements() == true) {
     final String uri = (String) propertyNames.nextElement();
     new File(properties.getProperty(uri)).delete();
   }
   getIndexFile().delete();
   properties.clear();
 }
Ejemplo n.º 22
0
  @Test
  public void testProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("one", p.getValue("foo"));
    assertEquals("one", p.getValue("foo", "non_existing_profile"));
    assertEquals("one", p.getValue("foo", "qwe"));
    assertEquals("ten", p.getValue("bar"));

    assertEquals("12345", p.getValue("vitamine", "aaa"));

    assertEquals(8, p.countTotalProperties());

    assertNull(p.getValue("db.url"));
    assertEquals("localhost", p.getValue("db.url", "develop"));
    assertEquals("localhost", p.getValue("db.url", "develop", "deploy"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy", "develop"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy"));

    Properties prop = new Properties();
    p.extractBaseProps(prop);
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "non_existing");
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "aaa");
    assertEquals("12345", prop.getProperty("vitamine"));

    prop.clear();
    p.extractProps(prop, "develop");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "develop", "deploy");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy", "develop");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.setActiveProfiles("deploy");
    p.extractSubProps(prop, "db.*");
    assertEquals(2, prop.size());
  }
Ejemplo n.º 23
0
  /*
   * Read multiple resource files from the classpaths given the file name.
   * This method is designed as package visibility to improve performance when
   * called by anonymous inner classes.
   *
   * @param name - the name of the resource file @param existingProps -
   * existing properties, cannot be null @param filter - to filter properties
   */
  static Hashtable<Object, Object> readMultipleResourceFiles(
      final String name, final Hashtable<Object, Object> existingProps, ClassLoader cl)
      throws NamingException {

    if (null == cl) {
      cl = ClassLoader.getSystemClassLoader();
    }

    Enumeration<URL> e = null;
    try {
      // Load all resource files
      e = cl.getResources(name);
    } catch (final IOException ex) {
      // Unexpected ClassLoader exception
      // jndi.23=Failed to load JNDI resource files.
      final ConfigurationException newEx =
          new ConfigurationException(Messages.getString("jndi.23")); // $NON-NLS-1$
      newEx.setRootCause(ex);
      throw newEx;
    }

    // Read all the loaded properties and merge
    URL url = null;
    InputStream is = null;
    final Properties p = new Properties();
    while (e.hasMoreElements()) {
      url = e.nextElement();
      try {
        if (null != (is = url.openStream())) {
          p.load(is);
          mergeEnvironment(p, existingProps, true);
          p.clear();
        }
      } catch (final IOException ex) {
        // Can't read this resource file
        // jndi.24=Failed to read JNDI resource files.
        final ConfigurationException newEx =
            new ConfigurationException(Messages.getString("jndi.24")); // $NON-NLS-1$
        newEx.setRootCause(ex);
        throw newEx;
      } finally {
        try {
          if (null != is) {
            is.close();
          }
        } catch (final IOException ex) {
          // Ignore closing exception
        } finally {
          is = null;
        }
      }
    }
    return existingProps;
  }
  /** Loads each value from the mod properties file into memory. */
  public void loadModProperties() {
    BashPackCore.instance.log("Loading mod properties...");

    try {
      // Clear the properties instance and get the mod's properties file.
      properties.clear();

      // Make sure the file exists.
      if (modPropertiesFile.exists()) {
        // Load its properties into the properties instance.
        inputStream = new FileInputStream(modPropertiesFile);
        properties.load(inputStream);
        inputStream.close();

        // Loop through each field and assign the value stored in the properties.
        for (Field f : ModPropertiesList.class.getFields()) {
          String fieldType = f.getType().toString();

          if (fieldType.contains("int")) {
            f.set(modProperties, Integer.parseInt(properties.getProperty(f.getName())));
          } else if (fieldType.contains("boolean")) {
            f.set(modProperties, Boolean.parseBoolean(properties.getProperty(f.getName())));
          } else if (fieldType.contains("String")) {
            f.set(modProperties, properties.getProperty(f.getName()));
          }
        }
      } else // The mod properties file does not exist. It was either deleted by the user or hasn't
             // been created yet.
      {
        BashPackCore.instance.log("Mod properties file was not found.");
        saveModProperties();
      }
    }

    // The user didn't edit the file correctly or assigned an invalid ID for an item or block. A new
    // property could have also been added.
    catch (NumberFormatException e) {
      BashPackCore.instance.log(
          "NumberFormatException while reading mod properties. You edited the file incorrectly or a new property has been added to BashPackCore.");
      resetModProperties();
      saveModProperties();
    } catch (FileNotFoundException e) {
      BashPackCore.instance.quitWithError(
          "BashPackBacon: FileNotFoundException occurred while loading the mod properties file.",
          e);
    } catch (IllegalAccessException e) {
      BashPackCore.instance.quitWithError(
          "BashPackBacon: IllegalAccessException occurred while loading the new mod properties file.",
          e);
    } catch (IOException e) {
      BashPackCore.instance.quitWithError(
          "BashPackBacon: IOException occurred while loading the new mod properties file.", e);
    }
  }
Ejemplo n.º 25
0
    public DefaultPropertiesStore(String filepath) throws IOException {
      if (filepath == null || filepath.length() < 1) throw new IllegalArgumentException();
      this.filepath = filepath;
      properties.clear();

      InputStream in = new BufferedInputStream(new FileInputStream(getConfigurationFile()));
      try {
        properties.load(in);
      } finally {
        in.close();
      }
    }
Ejemplo n.º 26
0
  public void testSystemProperties_getProperties_clear() {
    String userDir = System.getProperty("user.dir");
    assertNotNull(userDir);
    System.setProperty("p1", "v1");

    Properties properties = System.getProperties();
    assertEquals("v1", properties.getProperty("p1"));

    properties.clear();

    // Android-specific: The RI clears everything, Android resets to immutable defaults.
    assertEquals(userDir, System.getProperty("user.dir"));
    assertNull(System.getProperty("p1"));
  }
    public SimplePropertiesStore(File storeFile, final String password, boolean isImportFromKeySync)
        throws IOException {

      OtrDebugLogger.log("Loading store from encrypted file");
      mStoreFile = storeFile;
      mProperties.clear();

      if (password == null) throw new IOException("invalid password");

      mPassword = password;

      if (isImportFromKeySync) loadAES(mPassword);
      else loadOpenSSL(mPassword);
    }
Ejemplo n.º 28
0
 static void load(String path) {
   _Props.clear();
   try {
     File f = new File(path);
     InputStream is = new BufferedInputStream(new FileInputStream(f));
     _Props.load(is);
     is.close();
   } catch (FileNotFoundException e) {
     Utils.logToConsole("Properties file " + path + " not found");
   } catch (IOException e) {
     Utils.logToConsole("Exception accessing Properties file " + path);
     System.out.println(e);
   }
 }
  /** Returns to uninitialized state. */
  public void destroy() {
    m_contentTypeImages = null;

    m_contentTypeDisplayNames = null;

    m_contentTypeExtensions = null;

    m_contentTypes.clear();
    m_contentTypes = null;

    m_mimetypes.clear();
    m_mimetypes = null;

    M_log.info("destroy()");
  } // shutdown
  /**
   * Set the XADataSourceProperties value.
   *
   * @param xaDataSourceProperties The new XADataSourceProperties value.
   */
  public void setXADataSourceProperties(String xaDataSourceProperties) throws ResourceException {
    this.xaDataSourceProperties = xaDataSourceProperties;
    xaProps.clear();
    if (xaDataSourceProperties != null) {
      // Map any \ to \\
      xaDataSourceProperties = xaDataSourceProperties.replaceAll("\\\\", "\\\\\\\\");

      InputStream is = new ByteArrayInputStream(xaDataSourceProperties.getBytes());
      try {
        xaProps.load(is);
      } catch (IOException ioe) {
        throw new JBossResourceException("Could not load connection properties", ioe);
      }
    }
    initSelector();
  }