List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:com.salesmanager.core.util.FileUtil.java
/** * Decrypt & Parses a url with tokens for displaying url page * needs 2 tokens, an id (first) and ten a dat * @param tokens// w w w .j a v a2 s . c om * @return * @throws Exception */ public static Map<String, String> getUrlTokens(String token) throws Exception { String decrypted = EncryptionUtil.decrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant), token); StringTokenizer st = new StringTokenizer(decrypted, "|"); String id = ""; String date = ""; int i = 0; while (st.hasMoreTokens()) { String t = st.nextToken(); if (i == 0) { id = t; } else if (i == 1) { date = t; } else { break; } i++; } if (StringUtils.isBlank(id) || StringUtils.isBlank(date)) { throw new Exception("Invalid URL parameters for FileUtil.getUrlTokens " + token); } Map response = new HashMap(); response.put("ID", id); response.put("DATE", date); return response; }
From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java
/** * Set up initial status information// w w w. ja va 2 s. c o m */ public static void initialize(SessionContext sessionContext, String targets) { StringTokenizer parser = new StringTokenizer(targets, " \t,"); ArrayList dbList = new ArrayList(); HashMap targetMap = getNewStatusMap(sessionContext); /* * Establish the DB list and initial (pre-LOGON) status */ while (parser.hasMoreTokens()) { String db = parser.nextToken(); HashMap emptyMap = new HashMap(); /* * Empty status entry */ emptyMap.put("STATUS", "INACTIVE"); emptyMap.put("STATUS_MESSAGE", "<none>"); emptyMap.put("HITS", "0"); emptyMap.put("ESTIMATE", "0"); emptyMap.put("MERGED", "0"); /* * Save */ dbList.add(db); targetMap.put(db, emptyMap); } /* * Search targets, global status */ sessionContext.put("TARGETS", dbList); sessionContext.putInt("active", 0); sessionContext.put("STATUS", "INACTIVE"); sessionContext.put("STATUS_MESSAGE", "<none>"); /* * Initial totals */ sessionContext.putInt("TOTAL_ESTIMATE", 0); sessionContext.putInt("TOTAL_HITS", 0); sessionContext.putInt("maxRecords", 0); /* * Assume this search is synchronous. An OSID that implements an * asynchronous search will need to set the async flags manually after * this code has finished. */ clearAsyncSearch(sessionContext); clearAsyncInit(sessionContext); }
From source file:net.pms.encoders.AviSynthMEncoder.java
public static File getAVSScript(String fileName, DLNAMediaSubtitle subTrack, int fromFrame, int toFrame, String frameRateRatio, String frameRateNumber, PmsConfiguration configuration) throws IOException { String onlyFileName = fileName.substring(1 + fileName.lastIndexOf('\\')); File file = new File(configuration.getTempFolder(), "pms-avs-" + onlyFileName + ".avs"); try (PrintWriter pw = new PrintWriter(new FileOutputStream(file))) { String numerator;//from w ww . j a v a2 s. c o m String denominator; if (frameRateRatio != null && frameRateNumber != null) { if (frameRateRatio.equals(frameRateNumber)) { // No ratio was available numerator = frameRateRatio; denominator = "1"; } else { String[] frameRateNumDen = frameRateRatio.split("/"); numerator = frameRateNumDen[0]; denominator = "1001"; } } else { // No framerate was given so we should try the most common one numerator = "24000"; denominator = "1001"; frameRateNumber = "23.976"; } String assumeFPS = ".AssumeFPS(" + numerator + "," + denominator + ")"; String directShowFPS = ""; if (!"0".equals(frameRateNumber)) { directShowFPS = ", fps=" + frameRateNumber; } String convertfps = ""; if (configuration.getAvisynthConvertFps()) { convertfps = ", convertfps=true"; } File f = new File(fileName); if (f.exists()) { fileName = ProcessUtil.getShortFileNameIfWideChars(fileName); } String movieLine = "DirectShowSource(\"" + fileName + "\"" + directShowFPS + convertfps + ")" + assumeFPS; String mtLine1 = ""; String mtLine2 = ""; String mtLine3 = ""; String interframeLines = null; String interframePath = configuration.getInterFramePath(); int Cores = 1; if (configuration.getAvisynthMultiThreading()) { Cores = configuration.getNumberOfCpuCores(); // Goes at the start of the file to initiate multithreading mtLine1 = "SetMemoryMax(512)\nSetMTMode(3," + Cores + ")\n"; // Goes after the input line to make multithreading more efficient mtLine2 = "SetMTMode(2)"; // Goes at the end of the file to allow the multithreading to work with MEncoder mtLine3 = "SetMTMode(1)\nGetMTMode(false) > 0 ? distributor() : last"; } // True Motion if (configuration.getAvisynthInterFrame()) { String GPU = ""; movieLine += ".ConvertToYV12()"; // Enable GPU to assist with CPU if (configuration.getAvisynthInterFrameGPU() && interframegpu.isEnabled()) { GPU = ", GPU=true"; } interframeLines = "\n" + "PluginPath = \"" + interframePath + "\"\n" + "LoadPlugin(PluginPath+\"svpflow1.dll\")\n" + "LoadPlugin(PluginPath+\"svpflow2.dll\")\n" + "Import(PluginPath+\"InterFrame2.avsi\")\n" + "InterFrame(Cores=" + Cores + GPU + ", Preset=\"Faster\")\n"; } String subLine = null; if (subTrack != null && configuration.isAutoloadExternalSubtitles() && !configuration.isDisableSubtitles()) { if (subTrack.getExternalFile() != null) { LOGGER.info("AviSynth script: Using subtitle track: " + subTrack); String function = "TextSub"; if (subTrack.getType() == SubtitleType.VOBSUB) { function = "VobSub"; } subLine = function + "(\"" + ProcessUtil.getShortFileNameIfWideChars(subTrack.getExternalFile().getAbsolutePath()) + "\")"; } } ArrayList<String> lines = new ArrayList<>(); lines.add(mtLine1); boolean fullyManaged = false; String script = configuration.getAvisynthScript(); StringTokenizer st = new StringTokenizer(script, PMS.AVS_SEPARATOR); while (st.hasMoreTokens()) { String line = st.nextToken(); if (line.contains("<movie") || line.contains("<sub")) { fullyManaged = true; } lines.add(line); } lines.add(mtLine2); if (configuration.getAvisynthInterFrame()) { lines.add(interframeLines); } lines.add(mtLine3); if (fullyManaged) { for (String s : lines) { if (s.contains("<moviefilename>")) { s = s.replace("<moviefilename>", fileName); } s = s.replace("<movie>", movieLine); s = s.replace("<sub>", subLine != null ? subLine : "#"); pw.println(s); } } else { pw.println(movieLine); if (subLine != null) { pw.println(subLine); } pw.println("clip"); } } file.deleteOnExit(); return file; }
From source file:com.glaf.core.util.FtpUtils.java
private static void changeToDirectory(String remoteFile) { if (!remoteFile.startsWith("/")) { throw new RuntimeException(" path must start with '/'"); }/*from w w w . jav a 2 s . com*/ if (remoteFile.startsWith("/") && remoteFile.indexOf("/") > 0) { try { getFtpClient().changeWorkingDirectory("/"); String tmp = ""; remoteFile = remoteFile.substring(0, remoteFile.lastIndexOf("/")); StringTokenizer token = new StringTokenizer(remoteFile, "/"); while (token.hasMoreTokens()) { String str = token.nextToken(); tmp = tmp + "/" + str; getFtpClient().changeWorkingDirectory(tmp); } } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:keel.Algorithms.Neural_Networks.IRPropPlus_Clas.KEELIRPropPlusWrapperClas.java
/** * <p>/*from w w w . ja v a2 s . c o m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the * execution * </p> */ @SuppressWarnings("unchecked") private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); // Configure schema byte[] schema = null; try { schema = readSchema(trainFile); } catch (IOException e) { e.printStackTrace(); } catch (DatasetException e) { e.printStackTrace(); } // Auxiliar configuration file XMLConfiguration conf = new XMLConfiguration(); conf.setRootElementName("algorithm"); // Configure randGenFactory randGenFactory = new RanNnepFactory(); conf.addProperty("rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); if (randGenFactory instanceof IConfigure) ((IConfigure) randGenFactory).configure(conf.subset("rand-gen-factory")); // Configure species NeuralNetIndividualSpecies nnspecies = new NeuralNetIndividualSpecies(); species = (ISpecies) nnspecies; if (props.getProperty("Transfer").equals("Product_Unit")) { conf.addProperty("species.neural-net-type", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.MSEOptimizablePUNeuralNetClassifier"); conf.addProperty("species.hidden-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.ExpLayer"); conf.addProperty("species.hidden-layer[@biased]", false); } else { conf.addProperty("species.neural-net-type", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.MSEOptimizableSigmNeuralNetClassifier"); conf.addProperty("species.hidden-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.SigmLayer"); conf.addProperty("species.hidden-layer[@biased]", true); } int neurons = Integer.parseInt(props.getProperty("Hidden_nodes")); conf.addProperty("species.hidden-layer.minimum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.initial-maximum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.maximum-number-of-neurons", neurons); conf.addProperty("species.hidden-layer.initiator-of-links", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator"); conf.addProperty("species.hidden-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval"); conf.addProperty("species.hidden-layer.weight-range[@closure]", "closed-closed"); if (props.getProperty("Transfer").equals("Product_Unit")) { conf.addProperty("species.hidden-layer.weight-range[@left]", -0.1); conf.addProperty("species.hidden-layer.weight-range[@right]", 0.1); } else { conf.addProperty("species.hidden-layer.weight-range[@left]", -5.0); conf.addProperty("species.hidden-layer.weight-range[@right]", 5.0); } conf.addProperty("species.output-layer[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.LinearLayer"); conf.addProperty("species.output-layer[@biased]", true); conf.addProperty("species.output-layer.initiator-of-links", "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator"); conf.addProperty("species.output-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval"); conf.addProperty("species.output-layer.weight-range[@closure]", "closed-closed"); conf.addProperty("species.output-layer.weight-range[@left]", -5.0); conf.addProperty("species.output-layer.weight-range[@right]", 5.0); if (species instanceof IConfigure) ((IConfigure) species).configure(conf.subset("species")); // Configure evaluator evaluator = (IEvaluator) new SoftmaxClassificationProblemEvaluator(); if (props.getProperty("Transfer").equals("Product_Unit")) conf.addProperty("evaluator[@log-input-data]", true); conf.addProperty("evaluator[@normalize-data]", true); conf.addProperty("evaluator.error-function", "keel.Algorithms.Neural_Networks.NNEP_Clas.problem.errorfunctions.LogisticErrorFunction"); conf.addProperty("evaluator.input-interval[@closure]", "closed-closed"); conf.addProperty("evaluator.input-interval[@left]", 0.1); conf.addProperty("evaluator.input-interval[@right]", 0.9); conf.addProperty("evaluator.output-interval[@closure]", "closed-closed"); conf.addProperty("evaluator.output-interval[@left]", 0.0); conf.addProperty("evaluator.output-interval[@right]", 1.0); if (evaluator instanceof IConfigure) ((IConfigure) evaluator).configure(conf.subset("evaluator")); // Configure provider provider = new NeuralNetCreator(); KEELIRPropPlusWrapperClas system = new KEELIRPropPlusWrapperClas(); provider.contextualize(system); // Configure iRProp+ algorithm algorithm = new IRPropPlus(); conf.addProperty("algorithm.initial-step-size[@value]", 0.0125); conf.addProperty("algorithm.minimum-delta[@value]", 0.0); conf.addProperty("algorithm.maximum-delta[@value]", 50.0); conf.addProperty("algorithm.positive-eta[@value]", 1.2); conf.addProperty("algorithm.negative-eta[@value]", 0.2); conf.addProperty("algorithm.cycles[@value]", Integer.parseInt(props.getProperty("Epochs"))); if (algorithm instanceof IConfigure) ((IConfigure) algorithm).configure(conf.subset("algorithm")); // Read data ProblemEvaluator<AbstractIndividual<INeuralNet>> evaluator2 = (ProblemEvaluator<AbstractIndividual<INeuralNet>>) evaluator; evaluator2.readData(schema, new KeelDataSet(trainFile), new KeelDataSet(testFile)); nnspecies.setNOfInputs(evaluator2.getTrainData().getNofinputs()); nnspecies.setNOfOutputs(evaluator2.getTrainData().getNofoutputs() - 1); algorithm.setTrainingData(evaluator2.getTrainData()); // Read output files tokenizer = new StringTokenizer(props.getProperty("outputData")); String trainResultFile = tokenizer.nextToken(); trainResultFile = trainResultFile.substring(1, trainResultFile.length() - 1); consoleReporter.setTrainResultFile(trainResultFile); String testResultFile = tokenizer.nextToken(); testResultFile = testResultFile.substring(1, testResultFile.length() - 1); consoleReporter.setTestResultFile(testResultFile); String bestModelResultFile = tokenizer.nextToken(); bestModelResultFile = bestModelResultFile.substring(1, bestModelResultFile.length() - 1); consoleReporter.setBestModelResultFile(bestModelResultFile); }
From source file:com.glaf.core.util.FtpUtils.java
/** * FTP//from w ww . ja v a 2 s . co m * * @param remotePath * FTP"/" */ public static void mkdirs(String remotePath) { if (!remotePath.startsWith("/")) { throw new RuntimeException(" path must start with '/'"); } try { getFtpClient().changeWorkingDirectory("/"); if (remotePath.indexOf("/") != -1) { String tmp = ""; StringTokenizer token = new StringTokenizer(remotePath, "/"); while (token.hasMoreTokens()) { String str = token.nextToken(); tmp = tmp + "/" + str; getFtpClient().mkd(str); getFtpClient().changeWorkingDirectory(tmp); } } } catch (IOException ex) { ex.printStackTrace(); logger.error("mkdirs error", ex); throw new RuntimeException(ex); } }
From source file:BeanUtil.java
/** * <p>Gets the specified attribute from the specified object. For example, * <code>getObjectAttribute(o, "address.line1")</code> will return * the result of calling <code>o.getAddress().getLine1()</code>.<p> * * <p>The attribute specified may contain as many levels as you like. If at * any time a null reference is acquired by calling one of the successive * getter methods, then the return value from this method is also null.</p> * * <p>When reading from a boolean property the underlying bean introspector * first looks for an is<Property> read method, not finding one it will * still look for a get<Property> read method. Not finding either, the * property is considered write-only.</p> * * @param bean the bean to set the property on * @param propertyNames the name of the propertie(s) to retrieve. If this is * null or the empty string, then <code>bean</code> will be returned. * @return the object value of the bean attribute * * @throws PropertyNotFoundException indicates the the given property * could not be found on the bean * @throws NoSuchMethodException Not thrown * @throws InvocationTargetException if a specified getter method throws an * exception./*from w ww . j a v a2 s. com*/ * @throws IllegalAccessException if a getter method is * not public or property is write-only. */ public static Object getObjectAttribute(Object bean, String propertyNames) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Object result = bean; StringTokenizer propertyTokenizer = new StringTokenizer(propertyNames, PROPERTY_SEPARATOR); // Run through the tokens, calling get methods and // replacing result with the new object each time. // If the result equals null, then simply return null. while (propertyTokenizer.hasMoreElements() && result != null) { Class resultClass = result.getClass(); String currentPropertyName = propertyTokenizer.nextToken(); PropertyDescriptor propertyDescriptor = getPropertyDescriptor(currentPropertyName, resultClass); Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod == null) { throw new IllegalAccessException( "User is attempting to " + "read from a property that has no read method. " + " This is likely a write-only bean property. Caused " + "by property [" + currentPropertyName + "] on class [" + resultClass + "]"); } result = readMethod.invoke(result, NO_ARGUMENTS_ARRAY); } return result; }
From source file:net.pms.encoders.Player.java
/** * This method populates the supplied {@link OutputParams} object with the correct audio track (aid) * based on the MediaInfo metadata and PMS configuration settings. * * @param media/*from www .ja va 2s. co m*/ * The MediaInfo metadata for the file. * @param params * The parameters to populate. */ public static void setAudioOutputParameters(DLNAMediaInfo media, OutputParams params) { // Use device-specific pms conf PmsConfiguration configuration = PMS.getConfiguration(params); if (params.aid == null && media != null && media.getFirstAudioTrack() != null) { // check for preferred audio DLNAMediaAudio dtsTrack = null; StringTokenizer st = new StringTokenizer(configuration.getAudioLanguages(), ","); while (st.hasMoreTokens()) { String lang = st.nextToken().trim(); LOGGER.trace("Looking for an audio track with lang: " + lang); for (DLNAMediaAudio audio : media.getAudioTracksList()) { if (audio.matchCode(lang)) { params.aid = audio; LOGGER.trace("Matched audio track: " + audio); return; } if (dtsTrack == null && audio.isDTS()) { dtsTrack = audio; } } } // preferred audio not found, take a default audio track, dts first if available if (dtsTrack != null) { params.aid = dtsTrack; LOGGER.trace("Found priority audio track with DTS: " + dtsTrack); } else { params.aid = media.getAudioTracksList().get(0); LOGGER.trace("Chose a default audio track: " + params.aid); } } }
From source file:bioLockJ.Config.java
/** * Get a property as list (must be comma delimited) * @param propName// ww w. j a v a2 s .c om * @return */ public static List<String> getList(final String propName) { final List<String> list = new ArrayList<>(); final String val = getAProperty(propName); if (val != null) { final StringTokenizer st = new StringTokenizer(val, ","); while (st.hasMoreTokens()) { list.add(st.nextToken().trim()); } } return list; }
From source file:fr.ign.cogit.geoxygene.datatools.ojb.GeOxygeneBrokerHelper.java
/** * splits up the name string and extract db url, user name and password and * build a new PBKey instance - the token '#' is used to separate the * substrings./*from ww w .j a v a 2s. c om*/ * @throws PersistenceBrokerException if given name was <code>null</code> */ public static PBKey extractAllTokens(String name) { if (name == null) { throw new PersistenceBrokerException("Could not extract PBKey, given argument is 'null'"); //$NON-NLS-1$ } String user = null; String passwd = null; StringTokenizer tok = new StringTokenizer(name, GeOxygeneBrokerHelper.REPOSITORY_NAME_SEPARATOR); String dbName = tok.nextToken(); if (tok.hasMoreTokens()) { user = tok.nextToken(); if (user != null && user.trim().equals("")) { //$NON-NLS-1$ user = null; } } if (tok.hasMoreTokens()) { if (user != null) { passwd = tok.nextToken(); } } if (user != null && passwd == null) { passwd = ""; //$NON-NLS-1$ } PBKey key = new PBKey(dbName, user, passwd); return key; }