/** Sets Tesseract's internal parameters. */ private void setTessVariables() { Enumeration<?> em = prop.propertyNames(); while (em.hasMoreElements()) { String key = (String) em.nextElement(); api.TessBaseAPISetVariable(handle, key, prop.getProperty(key)); } }
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 void loadLanguageMappings(Properties props) { Enumeration<?> en = props.propertyNames(); while (en.hasMoreElements()) { String propName = (String) en.nextElement(); String propVal = props.getProperty(propName); if (propName.startsWith(".")) { // This is an extension mapping if (propName.equals(".")) { // The default mapping defaultLanguageImplName = propVal; } else { propName = propName.substring(1); extensionMappings.put(propName, propVal); } } else { // value is made up of an optional module name followed by colon followed by the // FQCN of the factory int colonIndex = propVal.lastIndexOf(COLON); String moduleName; String factoryName; if (colonIndex != -1) { moduleName = propVal.substring(0, colonIndex); factoryName = propVal.substring(colonIndex + 1); } else { throw new IllegalArgumentException( "Language mapping: " + propVal + " does not specify an implementing module"); } LanguageImplInfo langImpl = new LanguageImplInfo(moduleName, factoryName); languageImpls.put(propName, langImpl); extensionMappings.put(propName, propName); // automatically register the name as a mapping } } }
/** * Add set of properties to this object. This method will replace the value of any properties that * already existed. */ public void setProperties(Properties props) { Enumeration names = props.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); setProperty(name, props.getProperty(name)); } }
public Factory readTheFile() { try { // Reading the file String filename = "file.properties"; input = new FileInputStream(filename); if (input == null) { System.out.println("Sorry, unable to find " + filename); return null; } prop.load(input); Enumeration<?> e = prop.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = prop.getProperty(key); // Setting the shop name factory.setShopName(key); // Splitting by type String[] valuesList = value.split(", "); for (String values : valuesList) { // Splitting by value // System.out.println(values); String[] typeAndValues = values.split(":"); typeAndValues[1] = typeAndValues[1].trim(); String[] valueEach = typeAndValues[1].split(" "); // Storing values to the factory if (typeAndValues[0].equals("Sport")) { factory.addSport(valueEach[0], valueEach[1]); } else if (typeAndValues[0].equals("Logical")) { factory.addLogical(valueEach[0], valueEach[1]); } } } } catch (IOException ex) { ex.printStackTrace(); } finally { if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } return factory; }
private void loadConfiguration() throws RuntimeConfigException { trace(String.format("Loading configuration from [%s]", configFilePath)); try { InputStream stream = new FileInputStream(configFilePath); // InputStream stream1 = new FileInputStream("config/ocsswws.config"); try { Properties fileProperties = new Properties(); fileProperties.load(stream); // @todo check tests - code was not backward compatible with Java 5 // so i changed it - but this is not the only place of uncompatibilty // add default properties so that they override file properties // Set<String> propertyNames = fileProperties.stringPropertyNames(); // for (String propertyName : propertyNames) { // String propertyValue = fileProperties.getProperty(propertyName); // if (!isPropertySet(propertyName)) { // setProperty(propertyName, propertyValue); // trace(String.format("Configuration property [%s] added", // propertyName)); // } else { // trace(String.format("Configuration property [%s] ignored", // propertyName)); // } // } Enumeration<?> enumeration = fileProperties.propertyNames(); while (enumeration.hasMoreElements()) { final Object key = enumeration.nextElement(); if (key instanceof String) { final Object value = fileProperties.get(key); if (value instanceof String) { final String keyString = (String) key; String propertyValue = fileProperties.getProperty(keyString); if (!isPropertySet(keyString)) { setProperty(keyString, propertyValue); trace(String.format("Configuration property [%s] added", keyString)); } else { trace(String.format("Configuration property [%s] ignored", keyString)); } } } } } finally { stream.close(); } } catch (IOException e) { throw new RuntimeConfigException( String.format("Failed to load configuration [%s]", configFilePath), e); } }
/** * Take all the properties and translate them to actual values. This method takes the set * properties and traverse them over all entries, including the default properties for that * properties. The values no longer contain macros. * * @return A new Properties with the flattened values */ public Properties getFlattenedProperties() { // Some macros only work in a lower processor, so we // do not report unknown macros while flattening flattening = true; try { Properties flattened = new Properties(); Properties source = domain.getProperties(); for (Enumeration<?> e = source.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); if (!key.startsWith("_")) if (key.startsWith("-")) flattened.put(key, source.getProperty(key)); else flattened.put(key, process(source.getProperty(key))); } return flattened; } finally { flattening = false; } }
public void loadProperties(File file) throws IOException { Properties input = new Properties(); FileInputStream stream = null; try { stream = new FileInputStream(file); input.load(stream); for (Enumeration e = input.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); doSetValue(key, input.getProperty(key)); } } finally { if (stream != null) { stream.close(); } } }
public static void showServerInfo(PrintStream out) { out.println("Server Info"); out.println( " getDocumentBuilderFactoryVersion(): " + XMLEntityResolver.getDocumentBuilderFactoryVersion()); out.println(); Properties sysp = System.getProperties(); Enumeration e = sysp.propertyNames(); List<String> list = Collections.list(e); Collections.sort(list); out.println("System Properties:"); for (String name : list) { String value = System.getProperty(name); out.println(" " + name + " = " + value); } out.println(); }
public void setLanguage(String par1Str) { if (!par1Str.equals(this.currentLanguage)) { Properties var2 = new Properties(); try { this.loadLanguage(var2, "en_US"); } catch (IOException var8) {; } this.isUnicode = false; if (!"en_US".equals(par1Str)) { try { this.loadLanguage(var2, par1Str); Enumeration var3 = var2.propertyNames(); while (var3.hasMoreElements() && !this.isUnicode) { Object var4 = var3.nextElement(); Object var5 = var2.get(var4); if (var5 != null) { String var6 = var5.toString(); for (int var7 = 0; var7 < var6.length(); ++var7) { if (var6.charAt(var7) >= 256) { this.isUnicode = true; break; } } } } } catch (IOException var9) { var9.printStackTrace(); return; } } this.currentLanguage = par1Str; this.translateTable = var2; } }
public JPanel getPanelForProperties(Properties propsArg) { // clear(); propKeyList = new ArrayList(); propValueList = new ArrayList(); for (Enumeration e = propsArg.propertyNames(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); String value = (String) propsArg.getProperty(name); XmlUIElement el = getXmlUIElementFor("textfield"); if (el != null) { propKeyList.add(name); el.setValue(value); if (name.endsWith("#")) { el.setLabelName(name.substring(0, name.length() - 1)); } else { el.setLabelName(name); } propValueList.add(el); } } return getPanelFor(propValueList); }
// Private method to be called when the configuration has // changed to apply any level settings to any pre-existing loggers. private synchronized void setLevelsOnExistingLoggers() { Enumeration enum_ = props.propertyNames(); while (enum_.hasMoreElements()) { String key = (String) enum_.nextElement(); if (!key.endsWith(".level")) { // Not a level definition. continue; } int ix = key.length() - 6; String name = key.substring(0, ix); Level level = getLevelProperty(key, null); if (level == null) { System.err.println("Bad level value for property: " + key); continue; } Logger l = getLogger(name); if (l == null) { continue; } l.setLevel(level); } }
@Override public Response serve(String uri, String method, Properties header, Properties parms) { if (!uri.equals("/mediaserver")) { return super.serve(uri, method, header, parms); // this way we can // also serve up // normal files and // content } logger.fine(method + " '" + uri + "' "); Enumeration<?> e = header.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); logger.fine(" HDR: '" + value + "' = '" + header.getProperty(value) + "'"); } e = parms.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); logger.fine(" PRM: '" + value + "' = '" + parms.getProperty(value) + "'"); } // TODO: check the actual path... final String mediaPath = parms.getProperty("media"); final String outputFormatStr = parms.getProperty("format"); final String mimeType = parms.getProperty("mime"); logger.info("requested media: " + mediaPath); logger.info("requested mime type: " + mimeType); if (mediaPath == null) return new Response(HTTP_FORBIDDEN, "text/plain", "mediaPath parameter not specified"); if (mimeType == null) return new Response(HTTP_FORBIDDEN, "text/plain", "mimeType parameter not specified"); // TODO: if we aren't performing any transcoding, just serve the file up // directly. // TODO: capture sources need to be treated as singletons, with some // kind of broadcasting/cloning to ensure // that multiple connections can be made. final String serverSideUrlStr = mediaPath; // URLUtils.createUrlStr(new // File(mediaPath)); // TODO: // enforce that we can't just // serve up anything anywhere final ContentDescriptor outputContentDescriptor = new FileTypeDescriptor(ContentDescriptor.mimeTypeToPackageName(mimeType)); final Format outputFormat; if (outputFormatStr == null) { outputFormat = null; } else { try { outputFormat = FormatArgUtils.parse(outputFormatStr); } catch (ParseException e1) { logger.log(Level.WARNING, "" + e1, e1); return new Response(HTTP_FORBIDDEN, "text/plain", "" + e1); } } logger.info("serverSideUrlStr: " + serverSideUrlStr); logger.info("outputContentDescriptor: " + outputContentDescriptor); logger.info("outputFormat: " + outputFormat); final InputStream is; try { is = getInputStream(serverSideUrlStr, outputFormat, outputContentDescriptor); } catch (Exception e1) { return new Response(HTTP_FORBIDDEN, "text/plain", "" + e1); } final String responseMimeType; // workaround for the problem that the multipart/x-mixed-replace // boundary is not stored anywhere. // this assumes that if we are serving multipart/x-mixed-replace data, // that MultipartMixedReplaceMux is being used. if (mimeType.equals("multipart/x-mixed-replace")) responseMimeType = mimeType + ";boundary=" + MultipartMixedReplaceMux.BOUNDARY; else responseMimeType = mimeType; logger.info("Response mime type: " + responseMimeType); return new Response(HTTP_OK, responseMimeType, is); }
/** * Loads the configuration properties in the configuration property file associated with the * framework installation; these properties are accessible to the framework and to bundles and are * intended for configuration purposes. By default, the configuration property file is located in * the <tt>conf/</tt> directory of the Felix installation directory and is called * "<tt>config.properties</tt>". The installation directory of Felix is assumed to be the parent * directory of the <tt>felix.jar</tt> file as found on the system class path property. The * precise file from which to load configuration properties can be set by initializing the * "<tt>felix.config.properties</tt>" system property to an arbitrary URL. * * @return A <tt>Properties</tt> instance or <tt>null</tt> if there was an error. */ public static Properties loadConfigProperties() { // The config properties file is either specified by a system // property or it is in the conf/ directory of the Felix // installation directory. Try to load it from one of these // places. // See if the property URL was specified as a property. URL propURL = null; String custom = System.getProperty(CONFIG_PROPERTIES_PROP); if (custom != null) { try { propURL = new URL(custom); } catch (MalformedURLException ex) { System.err.print("Main: " + ex); return null; } } else { // Determine where the configuration directory is by figuring // out where felix.jar is located on the system class path. File confDir = null; String classpath = System.getProperty("java.class.path"); int index = classpath.toLowerCase().indexOf("felix.jar"); int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; if (index >= start) { // Get the path of the felix.jar file. String jarLocation = classpath.substring(start, index); // Calculate the conf directory based on the parent // directory of the felix.jar directory. confDir = new File( new File(new File(jarLocation).getAbsolutePath()).getParent(), CONFIG_DIRECTORY); } else { // Can't figure it out so use the current directory as default. confDir = new File(System.getProperty("user.dir"), CONFIG_DIRECTORY); } try { propURL = new File(confDir, CONFIG_PROPERTIES_FILE_VALUE).toURL(); } catch (MalformedURLException ex) { System.err.print("Main: " + ex); return null; } } // Read the properties file. Properties props = new Properties(); InputStream is = null; try { // Try to load config.properties. is = propURL.openConnection().getInputStream(); props.load(is); is.close(); } catch (Exception ex) { // Try to close input stream if we have one. try { if (is != null) is.close(); } catch (IOException ex2) { // Nothing we can do. } return null; } // Perform variable substitution for system properties. for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); props.setProperty(name, Util.substVars(props.getProperty(name), name, null, props)); } return props; }
@SuppressWarnings("unchecked") public static void main(String[] args) { String dbname; Properties props = new Properties(); Properties fileprops = new Properties(); boolean dotransactions = true; int threadcount = 1; int target = 0; boolean status = false; String label = ""; // parse arguments int argindex = 0; if (args.length == 0) { usageMessage(); System.exit(0); } while (args[argindex].startsWith("-")) { if (args[argindex].compareTo("-threads") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } int tcount = Integer.parseInt(args[argindex]); props.setProperty("threadcount", tcount + ""); argindex++; } else if (args[argindex].compareTo("-target") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } int ttarget = Integer.parseInt(args[argindex]); props.setProperty("target", ttarget + ""); argindex++; } else if (args[argindex].compareTo("-load") == 0) { dotransactions = false; argindex++; } else if (args[argindex].compareTo("-t") == 0) { dotransactions = true; argindex++; } else if (args[argindex].compareTo("-s") == 0) { status = true; argindex++; } else if (args[argindex].compareTo("-db") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } props.setProperty("db", args[argindex]); argindex++; } else if (args[argindex].compareTo("-l") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } label = args[argindex]; argindex++; } else if (args[argindex].compareTo("-P") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } String propfile = args[argindex]; argindex++; Properties myfileprops = new Properties(); try { myfileprops.load(new FileInputStream(propfile)); } catch (IOException e) { System.out.println(e.getMessage()); System.exit(0); } // Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5 for (Enumeration e = myfileprops.propertyNames(); e.hasMoreElements(); ) { String prop = (String) e.nextElement(); fileprops.setProperty(prop, myfileprops.getProperty(prop)); } } else if (args[argindex].compareTo("-p") == 0) { argindex++; if (argindex >= args.length) { usageMessage(); System.exit(0); } int eq = args[argindex].indexOf('='); if (eq < 0) { usageMessage(); System.exit(0); } String name = args[argindex].substring(0, eq); String value = args[argindex].substring(eq + 1); props.put(name, value); // System.out.println("["+name+"]=["+value+"]"); argindex++; } else { System.out.println("Unknown option " + args[argindex]); usageMessage(); System.exit(0); } if (argindex >= args.length) { break; } } if (argindex != args.length) { usageMessage(); System.exit(0); } // set up logging // BasicConfigurator.configure(); // overwrite file properties with properties from the command line // Issue #5 - remove call to stringPropertyNames to make compilable under Java 1.5 for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { String prop = (String) e.nextElement(); fileprops.setProperty(prop, props.getProperty(prop)); } props = fileprops; if (!checkRequiredProperties(props)) { System.exit(0); } long maxExecutionTime = Integer.parseInt(props.getProperty(MAX_EXECUTION_TIME, "0")); // get number of threads, target and db threadcount = Integer.parseInt(props.getProperty("threadcount", "1")); dbname = props.getProperty("db", "com.yahoo.ycsb.BasicDB"); target = Integer.parseInt(props.getProperty("target", "0")); // compute the target throughput double targetperthreadperms = -1; if (target > 0) { double targetperthread = ((double) target) / ((double) threadcount); targetperthreadperms = targetperthread / 1000.0; } System.out.println("YCSB Client 0.1"); System.out.print("Command line:"); for (int i = 0; i < args.length; i++) { System.out.print(" " + args[i]); } System.out.println(); System.err.println("Loading workload..."); // show a warning message that creating the workload is taking a while // but only do so if it is taking longer than 2 seconds // (showing the message right away if the setup wasn't taking very long was confusing people) Thread warningthread = new Thread() { public void run() { try { sleep(2000); } catch (InterruptedException e) { return; } System.err.println(" (might take a few minutes for large data sets)"); } }; warningthread.start(); // set up measurements Measurements.setProperties(props); // load the workload ClassLoader classLoader = Client.class.getClassLoader(); Workload workload = null; try { Class workloadclass = classLoader.loadClass(props.getProperty(WORKLOAD_PROPERTY)); workload = (Workload) workloadclass.newInstance(); } catch (Exception e) { e.printStackTrace(); e.printStackTrace(System.out); System.exit(0); } try { workload.init(props); } catch (WorkloadException e) { e.printStackTrace(); e.printStackTrace(System.out); System.exit(0); } warningthread.interrupt(); // run the workload System.err.println("Starting test."); int opcount; if (dotransactions) { opcount = Integer.parseInt(props.getProperty(OPERATION_COUNT_PROPERTY, "0")); } else { if (props.containsKey(INSERT_COUNT_PROPERTY)) { opcount = Integer.parseInt(props.getProperty(INSERT_COUNT_PROPERTY, "0")); } else { opcount = Integer.parseInt(props.getProperty(RECORD_COUNT_PROPERTY, "0")); } } Vector<Thread> threads = new Vector<Thread>(); for (int threadid = 0; threadid < threadcount; threadid++) { DB db = null; try { db = DBFactory.newDB(dbname, props); } catch (UnknownDBException e) { System.out.println("Unknown DB " + dbname); System.exit(0); } Thread t = new ClientThread( db, dotransactions, workload, threadid, threadcount, props, opcount / threadcount, targetperthreadperms); threads.add(t); // t.start(); } StatusThread statusthread = null; if (status) { boolean standardstatus = false; if (props.getProperty("measurementtype", "").compareTo("timeseries") == 0) { standardstatus = true; } statusthread = new StatusThread(threads, label, standardstatus); statusthread.start(); } long st = System.currentTimeMillis(); for (Thread t : threads) { t.start(); } Thread terminator = null; if (maxExecutionTime > 0) { terminator = new TerminatorThread(maxExecutionTime, threads, workload); terminator.start(); } int opsDone = 0; for (Thread t : threads) { try { t.join(); opsDone += ((ClientThread) t).getOpsDone(); } catch (InterruptedException e) { } } long en = System.currentTimeMillis(); if (terminator != null && !terminator.isInterrupted()) { terminator.interrupt(); } if (status) { statusthread.interrupt(); } try { workload.cleanup(); } catch (WorkloadException e) { e.printStackTrace(); e.printStackTrace(System.out); System.exit(0); } try { exportMeasurements(props, opsDone, en - st); } catch (IOException e) { System.err.println("Could not export measurements, error: " + e.getMessage()); e.printStackTrace(); System.exit(-1); } System.exit(0); }