示例#1
0
  public static void exportWithProperties(String propFile, String outFile) throws IOException {
    Properties props = new Properties();
    try {
      props.load(new FileInputStream(propFile));
    } catch (FileNotFoundException e) {
      System.err.println("Property file not found: " + propFile);
      System.exit(2);
    } catch (IOException e) {
      System.err.println("Unable to read properties: " + propFile);
      System.exit(2);
    }

    OutputStream out = null;

    try {
      out = new BufferedOutputStream(new FileOutputStream(outFile));
      WikiEngine engine = new WikiEngine(props);

      Exporter x = new Exporter(out, true);

      x.export(engine);
    } catch (WikiException e) {
      // TODO Auto-generated catch block
      e.printStackTrace(System.err);
      System.exit(3);
    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(3);
    } finally {
      if (out != null) out.close();

      // Make sure JSPWiki dies too
      System.exit(0);
    }
  }
示例#2
0
    /**
     * Reinitialize the logging properties and reread the logging configuration
     * from the given stream, which should be in java.util.Properties format.
     * A PropertyChangeEvent will be fired after the properties are read.
     * <p>
     * Any log level definitions in the new configuration file will be 
     * applied using Logger.setLevel(), if the target Logger exists.
     * 
     * @param ins	stream to read properties from
     * @exception  SecurityException  if a security manager exists and if
     *             the caller does not have LoggingPermission("control").
     * @exception  IOException if there are problems reading from the stream.
     */
    public void readConfiguration(InputStream ins) throws IOException, SecurityException {
	checkAccess();
	reset();

	// Load the properties
	props.load(ins);
	// Instantiate new configuration objects.
	String names[] = parseClassNames("config");

	for (int i = 0; i < names.length; i++) {
	    String word = names[i];
	    try {
		Class clz = ClassLoader.getSystemClassLoader().loadClass(word);
		clz.newInstance();
	    } catch (Exception ex) {
		System.err.println("Can't load config class \"" + word + "\"");
		System.err.println("" + ex);
		// ex.printStackTrace();
	    }
	}

	// Set levels on any pre-existing loggers, based on the new properties.
	setLevelsOnExistingLoggers();

	// Notify any interested parties that our properties have changed.
	changes.firePropertyChange(null, null, null);

	// Note that we need to reinitialize global handles when 
   	// they are first referenced.
	synchronized (this) {
	    initializedGlobalHandlers = false;
	}
    }
示例#3
0
  // Recovery the application parameters from the properties file.
  private void recoverParameters() {

    try {
      // Open the file
      InputStream is = new FileInputStream(PROPERTIES_FILE);
      Properties props = new Properties();
      props.load(is);

      // Obtain each property
      if (props.getProperty(PORT) != null) {
        port = Integer.parseInt(props.getProperty(PORT));
      }
      if (props.getProperty(TRANSPORT) != null) {
        transport = props.getProperty(TRANSPORT);
      }
      if (props.getProperty(PROXY_ADDRESS) != null) {
        proxyAddress = props.getProperty(PROXY_ADDRESS);
      }
      if (props.getProperty(PROXY_PORT) != null) {
        proxyPort = Integer.parseInt(props.getProperty(PROXY_PORT));
      }
      if (props.getProperty(PROXY_TRANSPORT) != null) {
        proxyTransport = props.getProperty(PROXY_TRANSPORT);
      }
      if (props.getProperty(SIP_URI) != null) {
        sip_uri = props.getProperty(SIP_URI);
      }
      // Close throws file
      is.close();
    } catch (IOException ex) {
      System.err.println("Error reading properties file: " + ex);
      ex.printStackTrace(System.err);
      // System.exit(-1);
    }
  }
 private static void loadPlatformZipPropertiesFromFile() {
   File installLocation = getInstallLocation();
   if (installLocation != null) {
     // parent will be "eclipse" and the parent's parent will be "eclipse-testing"
     File parent = installLocation.getParentFile();
     if (parent != null) {
       parent = parent.getParentFile();
       if (parent != null) {
         File propertiesFile = new File(parent, "equinoxp2tests.properties");
         if (!propertiesFile.exists()) return;
         archiveAndRepositoryProperties = new Properties();
         try {
           InputStream is = null;
           try {
             is = new BufferedInputStream(new FileInputStream(propertiesFile));
             archiveAndRepositoryProperties.load(is);
           } finally {
             is.close();
           }
         } catch (IOException e) {
           return;
         }
       }
     }
   }
 }
示例#5
0
  /**
   * Loads test configuration.
   *
   * @throws Exception if configuration is unawailable or broken.
   */
  private void loadTestConfiguration() throws Exception {
    assert TEST_CONFIGURATION_FILE.isFile();

    InputStream in = null;

    Properties p = new Properties();

    try {
      in = new FileInputStream(TEST_CONFIGURATION_FILE);

      p.load(in);
    } finally {
      U.closeQuiet(in);
    }

    clientNodes = Integer.parseInt(p.getProperty("client.nodes.count"));
    srvNodes = Integer.parseInt(p.getProperty("server.nodes.count"));
    threadsPerClient = Integer.parseInt(p.getProperty("threads.per.client"));
    cancelRate = Integer.parseInt(p.getProperty("cancel.rate"));
    submitDelay = Long.parseLong(p.getProperty("submit.delay"));

    taskParams =
        new GridJobLoadTestParams(
            Integer.parseInt(p.getProperty("jobs.count")),
            Integer.parseInt(p.getProperty("jobs.test.duration")),
            Integer.parseInt(p.getProperty("jobs.test.completion.delay")),
            Double.parseDouble(p.getProperty("jobs.failure.probability")));
  }
示例#6
0
  // -------------------------------- main -------------------------------
  public static void main(String[] args) {
    String fileName;
    if (args.length > 0) fileName = args[0];
    else fileName = Utils.getFileName("Choose a flow field metadata file");
    Properties metaData = new Properties();
    try {
      metaData.load(new FileInputStream(fileName));
    } catch (IOException fnf) {
      System.err.println("Can't find file: " + fileName);
      System.exit(-1);
    }
    // ----- get all the properties from the prpoerty file and
    //
    VectorField.xData = new File(metaData.getProperty("xfile"));
    VectorField.yData = new File(metaData.getProperty("yfile"));
    VectorField.width = Utils.toInt(metaData.getProperty("xsize"), 128);
    VectorField.height = Utils.toInt(metaData.getProperty("ysize"), 128);
    VectorField.displayScale = Utils.toInt(metaData.getProperty("displayScale"), 6);
    VectorField.vectorScale = Utils.toDouble(metaData.getProperty("vectorScale"), 10.75);

    VectorField.numParticles = Utils.toInt(metaData.getProperty("numParticles"), 200);
    VectorField.timerDelay = Utils.toInt(metaData.getProperty("delay"), 30);

    FlowQuad vectorField = new FlowQuad("Static Vector Field");
  }
 /**
  * Returns the dev.properties as a property store.
  *
  * @return properties
  */
 protected static Properties getDevProperties() {
   if (fgIsDev) {
     if (fgDevProperties == null) {
       fgDevProperties = new Properties();
       if (fgDevPropertiesURL != null) {
         try {
           URL url = new URL(fgDevPropertiesURL);
           String path = url.getFile();
           if (path != null && path.length() > 0) {
             File file = new File(path);
             if (file.exists()) {
               BufferedInputStream stream = null;
               try {
                 stream = new BufferedInputStream(new FileInputStream(file));
                 fgDevProperties.load(stream);
               } catch (FileNotFoundException e) {
                 PDECore.log(e);
               } catch (IOException e) {
                 PDECore.log(e);
               } finally {
                 if (stream != null) stream.close();
               }
             }
           }
         } catch (MalformedURLException e) {
           PDECore.log(e);
         } catch (IOException e) {
           PDECore.log(e);
         }
       }
     }
     return fgDevProperties;
   }
   return null;
 }
示例#8
0
 public Properties loadUpdateProperties() {
   File propertiesDirectory;
   Properties updateProperties = new Properties();
   // First we look at local configuration directory
   propertiesDirectory = new File(System.getProperty("user.home"), PROPERTIES_DIRECTORY_NAME);
   if (!propertiesDirectory.exists()) {
     // Second we look at tangara binary path
     propertiesDirectory = getTangaraPath().getParentFile();
   }
   BufferedInputStream input = null;
   try {
     input =
         new BufferedInputStream(
             new FileInputStream(
                 new File(propertiesDirectory, getProperty("checkUpdate.fileName"))));
     updateProperties.load(input);
     input.close();
     return updateProperties;
   } catch (IOException e) {
     LOG.warn("Error trying to load update properties");
   } finally {
     IOUtils.closeQuietly(input);
   }
   return null;
 }
示例#9
0
 private Map<String, Plugin> loadPluginsFromClasspath(Settings settings) {
   Map<String, Plugin> plugins = newHashMap();
   Enumeration<URL> pluginUrls = null;
   try {
     pluginUrls = settings.getClassLoader().getResources("es-plugin.properties");
   } catch (IOException e) {
     logger.warn("Failed to find plugins from classpath", e);
   }
   while (pluginUrls.hasMoreElements()) {
     URL pluginUrl = pluginUrls.nextElement();
     Properties pluginProps = new Properties();
     InputStream is = null;
     try {
       is = pluginUrl.openStream();
       pluginProps.load(is);
       String sPluginClass = pluginProps.getProperty("plugin");
       Class<?> pluginClass = settings.getClassLoader().loadClass(sPluginClass);
       Plugin plugin = (Plugin) pluginClass.newInstance();
       plugins.put(plugin.name(), plugin);
     } catch (Exception e) {
       logger.warn("Failed to load plugin from [" + pluginUrl + "]", e);
     } finally {
       if (is != null) {
         try {
           is.close();
         } catch (IOException e) {
           // ignore
         }
       }
     }
   }
   return plugins;
 }
  public void load() {
    datasources.clear();
    try {
      if (repoURL != null) {
        File[] files = new File(repoURL.getFile()).listFiles();

        for (File file : files) {
          if (!file.isHidden()) {
            Properties props = new Properties();
            props.load(new FileInputStream(file));
            String name = props.getProperty("name");
            String type = props.getProperty("type");
            if (name != null && type != null) {
              Type t = SaikuDatasource.Type.valueOf(type.toUpperCase());
              SaikuDatasource ds = new SaikuDatasource(name, t, props);
              datasources.put(name, ds);
            }
          }
        }
      } else {
        throw new Exception("repo URL is null");
      }
    } catch (Exception e) {
      throw new SaikuServiceException(e.getMessage(), e);
    }
  }
示例#11
0
  static String getPropertyName(int propertyId, boolean bNamed) {
    if (bFirstTime) {
      bFirstTime = false;
      propertyNames = new Properties();
      try {
        InputStream propertyStream = PSTFile.class.getResourceAsStream("/PropertyNames.txt");
        if (propertyStream != null) {
          propertyNames.load(propertyStream);
        } else {
          propertyNames = null;
        }
      } catch (FileNotFoundException e) {
        propertyNames = null;
        e.printStackTrace();
      } catch (IOException e) {
        propertyNames = null;
        e.printStackTrace();
      }
    }

    if (propertyNames != null) {
      String key = String.format((bNamed ? "%08X" : "%04X"), propertyId);
      return propertyNames.getProperty(key);
    }

    return null;
  }
  public static Map<String, String> readProperties(InputStream inputStream) {
    Map<String, String> propertiesMap = null;
    try {
      propertiesMap = new LinkedHashMap<String, String>();

      Properties properties = new Properties();
      properties.load(inputStream);

      Enumeration<?> enumeration = properties.propertyNames();
      while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        String value = (String) properties.get(key);
        propertiesMap.put(key, value);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return propertiesMap;
  }
  private List<String> getTopicTweets(HttpServletRequest request) throws ServletException {

    final String topicFile = request.getParameter("topicFile");
    final String fullFilePath = topicFile;
    List<String> listFiles = new ArrayList<String>();

    Properties properties = new Properties();

    try {
      properties.load(new FileInputStream(fullFilePath));
    } catch (FileNotFoundException e) {
      LOGGER.error("missing file for in topic tweets: '" + fullFilePath + "'" + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      LOGGER.error("can't read file for in topic tweets: '" + fullFilePath + "'" + e.getMessage());
      e.printStackTrace();
    }

    for (Entry<Object, Object> propertyEntry : properties.entrySet()) {
      String key = (String) propertyEntry.getKey();
      if (key.startsWith("inTopic")) {
        listFiles.add((String) propertyEntry.getValue());
      }
    }

    List<String> tweets = new ArrayList<String>();
    for (String filtFile : listFiles) {
      tweets.addAll(parseTweetsFromFile(filtFile));
    }
    return tweets;
  }
  private List<String> getOutOfTopicTweets(HttpServletRequest request) throws ServletException {

    String topicFile = request.getParameter("topicFile");

    List<String> listFiles = new ArrayList<String>();
    Properties properties = new Properties();
    try {
      properties.load(new FileInputStream(topicFile));
    } catch (FileNotFoundException e) {
      final String emsg =
          "missing file for out of topic tweets: '" + topicFile + "'" + e.getMessage();
      LOGGER.error(emsg);
      throw new ServletException(emsg, e);
    } catch (IOException e) {
      final String emsg =
          "can't read file for out of topic tweets: '" + topicFile + "'" + e.getMessage();
      LOGGER.error(emsg);
      throw new ServletException(emsg);
    }

    for (Entry<Object, Object> propertyEntry : properties.entrySet()) {
      String key = (String) propertyEntry.getKey();

      if (key.startsWith("outOfTopic")) {
        listFiles.add((String) propertyEntry.getValue());
      }
    }

    List<String> tweets = new ArrayList<String>();
    for (String filtFile : listFiles) {
      tweets.addAll(parseTweetsFromFile(filtFile));
    }
    return tweets;
  }
示例#15
0
  public static void main(String[] args) throws MessagingException, IOException {
    Properties props = new Properties();
    try (InputStream in = Files.newInputStream(Paths.get("mail", "mail.properties"))) {
      props.load(in);
    }
    List<String> lines = Files.readAllLines(Paths.get(args[0]), Charset.forName("UTF-8"));

    String from = lines.get(0);
    String to = lines.get(1);
    String subject = lines.get(2);

    StringBuilder builder = new StringBuilder();
    for (int i = 3; i < lines.size(); i++) {
      builder.append(lines.get(i));
      builder.append("\n");
    }

    Console console = System.console();
    String password = new String(console.readPassword("Password: "));

    Session mailSession = Session.getDefaultInstance(props);
    // mailSession.setDebug(true);
    MimeMessage message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(builder.toString());
    Transport tr = mailSession.getTransport();
    try {
      tr.connect(null, password);
      tr.sendMessage(message, message.getAllRecipients());
    } finally {
      tr.close();
    }
  }
示例#16
0
 public synchronized boolean reload(boolean force) {
   long now = System.currentTimeMillis();
   if (force == false && now < last_check + 3000) return false;
   last_check = now;
   File file = getPropertyFile();
   if (file.lastModified() == last_load_time) {
     return false;
   }
   last_load_time = file.lastModified();
   Properties temp = new Properties();
   if (file.canRead()) {
     FileInputStream in = null;
     try {
       in = new FileInputStream(file);
       temp.load(in);
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       FileUtil.close(in);
     }
   }
   property = ConfigValueUtil.replaceSysProp(temp);
   apply();
   ConfObserver.run();
   return true;
 }
示例#17
0
 /**
  * Method used to load configuration from specific file
  *
  * @param propertiesFile configuration file
  */
 public static void load(String propertiesFile) {
   try {
     FileInputStream cfgInStream = new FileInputStream(propertiesFile);
     prop.load(cfgInStream);
   } catch (Exception e) {
     logger.debug("error opening propertiesFile: " + propertiesFile, e);
   }
 }
示例#18
0
  protected static void initSystemProperties(MoquiStart cl, boolean useProperties)
      throws IOException {
    Properties moquiInitProperties = new Properties();
    URL initProps = cl.getResource("MoquiInit.properties");
    if (initProps != null) {
      InputStream is = initProps.openStream();
      moquiInitProperties.load(is);
      is.close();
    }

    // before doing anything else make sure the moqui.runtime system property exists (needed for
    // config of various things)
    String runtimePath = System.getProperty("moqui.runtime");
    if (runtimePath != null && runtimePath.length() > 0)
      System.out.println("Determined runtime from system property: " + runtimePath);
    if (useProperties && (runtimePath == null || runtimePath.length() == 0)) {
      runtimePath = moquiInitProperties.getProperty("moqui.runtime");
      if (runtimePath != null && runtimePath.length() > 0)
        System.out.println("Determined runtime from MoquiInit.properties file: " + runtimePath);
    }
    if (runtimePath == null || runtimePath.length() == 0) {
      // see if runtime directory under the current directory exists, if not default to the current
      // directory
      File testFile = new File("runtime");
      if (testFile.exists()) runtimePath = "runtime";
      if (runtimePath != null && runtimePath.length() > 0)
        System.out.println("Determined runtime from existing runtime directory: " + runtimePath);
    }
    if (runtimePath == null || runtimePath.length() == 0) {
      runtimePath = ".";
      System.out.println("Determined runtime by defaulting to current directory: " + runtimePath);
    }
    File runtimeFile = new File(runtimePath);
    runtimePath = runtimeFile.getCanonicalPath();
    System.out.println("Canonicalized runtimePath: " + runtimePath);
    if (runtimePath.endsWith("/")) runtimePath = runtimePath.substring(0, runtimePath.length() - 1);
    System.setProperty("moqui.runtime", runtimePath);

    /* Don't do this here... loads as lower-level that WEB-INF/lib jars and so can't have dependencies on those,
        and dependencies on those are necessary
    // add runtime/lib jar files to the class loader
    File runtimeLibFile = new File(runtimePath + "/lib");
    for (File jarFile: runtimeLibFile.listFiles()) {
        if (jarFile.getName().endsWith(".jar")) cl.jarFileList.add(new JarFile(jarFile));
    }
    */

    // moqui.conf=conf/development/MoquiDevConf.xml
    String confPath = System.getProperty("moqui.conf");
    if (confPath == null || confPath.length() == 0) {
      confPath = moquiInitProperties.getProperty("moqui.conf");
    }
    if (confPath == null || confPath.length() == 0) {
      File testFile = new File(runtimePath + "/" + defaultConf);
      if (testFile.exists()) confPath = defaultConf;
    }
    if (confPath != null) System.setProperty("moqui.conf", confPath);
  }
示例#19
0
 /** Load any progress information for the import so far. */
 void restore() throws IOException {
   try {
     File dir = getStorageDirectory();
     File index = new File(dir, FILE_INDEX);
     props.load(new FileInputStream(index));
   } catch (FileNotFoundException e) {
     // ok if file doesn't exist yet
   }
 }
 private Properties loadOldProperties(File oldPropsFile) throws IOException {
   Properties oldProps = new Properties();
   if (oldPropsFile.exists()) {
     FileInputStream is = new FileInputStream(oldPropsFile);
     oldProps.load(is);
     is.close();
   }
   return oldProps;
 }
示例#21
0
  static {
    PROPS = new Properties();

    try {
      PROPS.load(GridProductImpl.class.getClassLoader().getResourceAsStream(FILE_PATH));
    } catch (IOException e) {
      throw new RuntimeException("Cannot find '" + FILE_PATH + "' file.", e);
    }
  }
示例#22
0
 public void initParam(String paramFile) throws Exception {
   // 使用Properties类来加载属性文件
   Properties props = new Properties();
   props.load(new FileInputStream(paramFile));
   driver = props.getProperty("driver");
   url = props.getProperty("url");
   user = props.getProperty("user");
   pass = props.getProperty("pass");
 }
示例#23
0
 public static void main(String[] args) throws IOException {
   Properties props = new Properties();
   try (InputStream in = Files.newInputStream(Paths.get(args[0]))) {
     props.load(in);
   }
   String url = props.remove("url").toString();
   String result = doPost(url, props);
   System.out.println(result);
 }
示例#24
0
  public static Properties toProperties(FileInputStream fis) {
    Properties props = new Properties();

    try {
      props.load(fis);
    } catch (IOException ioe) {
    }

    return props;
  }
  public void loadFile(String filename) throws IOException {
    final Properties settings = new Properties();
    settings.load(new FileInputStream(filename));

    for (Iterator it = settings.entrySet().iterator(); it.hasNext(); ) {

      Map.Entry setting = (Map.Entry) it.next();
      putAny((String) setting.getKey(), (String) setting.getValue());
    }
  }
示例#26
0
 // Load the anonymizer.properties file.
 // This function is called whenever the Clinical Trial Service is restarted,
 // allowing new anonymization scripts to be loaded.
 private void initialize() {
   reinitialize = false;
   try {
     File propFile = new File(TrialConfig.basepath + TrialConfig.dicomAnonymizerFilename);
     dicomAnonymizerProperties = new Properties();
     dicomAnonymizerProperties.load(new FileInputStream(propFile));
     File lkupFile = new File(TrialConfig.basepath + TrialConfig.lookupTableFilename);
     lookupTableProperties = new Properties();
     try {
       lookupTableProperties.load(new FileInputStream(lkupFile));
     } catch (Exception ex) {
       lookupTableProperties = null;
     }
     if (TrialConfig.dicomImportAnonymizerEnabled())
       Log.message(processorServiceName + ": DicomAnonymizer initialized");
     else Log.message(processorServiceName + ": DicomAnonymizer not enabled");
   } catch (Exception e) {
     Log.message(processorServiceName + ": Unable to configure the DicomAnonymizer");
   }
 }
示例#27
0
 public Configuration() {
   final Properties properties = new Properties();
   try {
     properties.load(new FileReader(getConfigurationFilePath()));
     username = properties.getProperty("username");
     password = properties.getProperty("password");
     from = LocalDate.parse(properties.getProperty("from"));
   } catch (IOException e) {
     System.out.println("No configuration file found.");
   }
 }
示例#28
0
 static {
   try {
     properties = new Properties();
     properties.load(Notepad.class.getResourceAsStream("resources/NotepadSystem.properties"));
     resources = ResourceBundle.getBundle("resources.Notepad", Locale.getDefault());
   } catch (MissingResourceException | IOException e) {
     System.err.println(
         "resources/Notepad.properties " + "or resources/NotepadSystem.properties not found");
     System.exit(1);
   }
 }
示例#29
0
 public TextproParser() {
   try {
     // load the TextPro home dir path from the file ./conf/textpro.properties
     Properties properties = new Properties();
     properties.load(new FileInputStream("./conf/textpro.properties"));
     TEXTPRO_PATH = properties.getProperty("textpropath");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#30
0
  public void buildCalc(InputStreamReader readerCmdList, CStackCalc calc) throws IOException {
    Properties cmdMap = new Properties(); // Перечень комманд калькулятора для создания.

    cmdMap.load(readerCmdList);
    Hashtable<FieldCmdKind, Object> fieldsValue =
        InitValuesFieldForCmd(); // Перечень пар (тип поля, значение для него) (инициализация полей
                                 // команды).

    for (Map.Entry<Object, Object> icmdList : cmdMap.entrySet()) {
      addCmdInCalc(calc, icmdList.getKey().toString(), icmdList.getValue().toString(), fieldsValue);
    }
  }