List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:com.ery.ertc.estorm.util.DNS.java
/** * Returns all the host names associated by the provided nameserver with the address bound to the specified network interface * /*from w ww .j av a 2s.com*/ * @param strInterface * The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) or the string "default" * @param nameserver * The DNS host name * @return A string vector of all host names associated with the IPs tied to the specified interface * @throws UnknownHostException */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (Exception e) { } if (hosts.size() == 0) return new String[] { InetAddress.getLocalHost().getCanonicalHostName() }; else return hosts.toArray(new String[] {}); }
From source file:org.proxydroid.Profile.java
public static String[] decodeAddrs(String addrs) { String[] list = addrs.split("\\|"); Vector<String> ret = new Vector<String>(); for (String addr : list) { String ta = validateAddr(addr); if (ta != null) ret.add(ta);//from w ww .j av a 2 s . c o m } return ret.toArray(new String[ret.size()]); }
From source file:org.godhuli.rhipe.RHMR.java
public static REXP buildListFromCounters(org.apache.hadoop.mapreduce.Counters counters, double tt) { String[] groupnames = counters.getGroupNames().toArray(new String[] {}); String[] groupdispname = new String[groupnames.length + 1]; Vector<REXP> cn = new Vector<REXP>(); for (int i = 0; i < groupnames.length; i++) { org.apache.hadoop.mapreduce.CounterGroup cgroup = counters.getGroup(groupnames[i]); groupdispname[i] = cgroup.getDisplayName(); REXP.Builder cvalues = REXP.newBuilder(); Vector<String> cnames = new Vector<String>(); cvalues.setRclass(REXP.RClass.REAL); for (org.apache.hadoop.mapreduce.Counter counter : cgroup) { cvalues.addRealValue((double) counter.getValue()); cnames.add(counter.getDisplayName()); }/*from ww w. j av a 2 s. c o m*/ cvalues.addAttrName("names"); cvalues.addAttrValue(RObjects.makeStringVector(cnames.toArray(new String[] {}))); cn.add(cvalues.build()); } groupdispname[groupnames.length] = "job_time"; REXP.Builder cvalues = REXP.newBuilder(); cvalues.setRclass(REXP.RClass.REAL); cvalues.addRealValue(tt); cn.add(cvalues.build()); return (RObjects.makeList(groupdispname, cn)); }
From source file:org.springframework.util.exec.Execute.java
/** * Wrapper for common execution patterns * * @param envVars Environment variables to execute with (optional) * @param cmd a vector of the commands to execute * @param baseDir the base directory to run from (optional) * @param timeToWait milliseconds to wait for completion *///from ww w.j a va 2 s. c om public static int execute(Vector<String> envVars, Vector<String> cmd, File baseDir, int timeToWait) { try { // We can collect the out or provide in if needed ExecuteWatchdog watchdog = new ExecuteWatchdog(timeToWait); watchdog.setDontkill(true); PumpStreamHandler out = new PumpStreamHandler(); Execute exec = new Execute(out, watchdog); String cmdA[] = new String[cmd.size()]; cmd.toArray(cmdA); if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < cmdA.length; i++) { sb.append(cmdA[i] + " "); } log.debug("Exec: " + sb.toString()); } exec.setCommandline(cmdA); if (envVars != null) { String env[] = new String[envVars.size()]; envVars.toArray(env); exec.setEnvironment(env); } exec.setNewenvironment(false); if (baseDir != null) exec.setWorkingDirectory(baseDir); exec.execute(); int status = exec.getExitValue(); log.debug("Exit value " + status); return status; } catch (Exception ex) { System.err.println("An error has occurred in Execute."); return -1; } }
From source file:com.buaa.cfs.net.DNS.java
/** * Returns all the host names associated by the provided nameserver with the address bound to the specified network * interface//from w ww . ja v a2 s. c o m * * @param strInterface The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) * @param nameserver The DNS host name * * @return A string vector of all host names associated with the IPs tied to the specified interface * * @throws UnknownHostException if the given interface is invalid */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) { } catch (NamingException ignored) { } } if (hosts.isEmpty()) { LOG.warn("Unable to determine hostname for interface " + strInterface); return new String[] { cachedHostname }; } else { return hosts.toArray(new String[hosts.size()]); } }
From source file:org.apache.nutch.tools.PruneIndexTool.java
/** * Read a list of Lucene queries from the stream (UTF-8 encoding is assumed). * There should be a single Lucene query per line. Blank lines and comments * starting with '#' are allowed.//from w w w .j a va2s.c om * <p>NOTE: you may wish to use {@link org.apache.nutch.searcher.Query#main(String[])} * method to translate queries from Nutch format to Lucene format.</p> * @param is InputStream to read from * @return array of Lucene queries * @throws Exception */ public static Query[] parseQueries(InputStream is) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "url", new WhitespaceAnalyzer()); Vector<Query> queries = new Vector<Query>(); while ((line = br.readLine()) != null) { line = line.trim(); //skip blanks and comments if (line.length() == 0 || line.charAt(0) == '#') continue; Query q = qp.parse(line); queries.add(q); } return queries.toArray(new Query[0]); }
From source file:org.hyperic.util.exec.Execute.java
/** Wrapper for common execution patterns * @param envVars Environment variables to execute with (optional) * @param cmd a vector of the commands to execute * @param baseDir the base directory to run from (optional) * @param timeToWait milliseconds to wait for completion */// w w w. ja v a 2s . co m public static int execute(Vector envVars, Vector cmd, File baseDir, int timeToWait) { try { // We can collect the out or provide in if needed ExecuteWatchdog watchdog = new ExecuteWatchdog(timeToWait); watchdog.setDontkill(true); PumpStreamHandler out = new PumpStreamHandler(); Execute exec = new Execute(out, watchdog); String cmdA[] = new String[cmd.size()]; cmd.toArray(cmdA); if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < cmdA.length; i++) { sb.append(cmdA[i] + " "); } log.debug("Exec: " + sb.toString()); } exec.setCommandline(cmdA); if (envVars != null) { String env[] = new String[envVars.size()]; envVars.toArray(env); exec.setEnvironment(env); } exec.setNewenvironment(false); if (baseDir != null) exec.setWorkingDirectory(baseDir); exec.execute(); int status = exec.getExitValue(); log.debug("Exit value " + status); return status; } catch (Exception ex) { // ex.printStackTrace(); System.err.println("An error has occurred in Execute."); return -1; } }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * Returns resource requests for a particular type. If there are no resources, * returns an empty array./* www . j ava 2 s . c o m*/ * * @param ctx WikiContext * @param type The resource request type * @return a String array for the resource requests */ @SuppressWarnings("unchecked") public static String[] getResourceRequests(WikiContext ctx, String type) { HashMap<String, Vector<String>> hm = (HashMap<String, Vector<String>>) ctx.getVariable(RESOURCE_INCLUDES); if (hm == null) return new String[0]; Vector<String> resources = hm.get(type); if (resources == null) return new String[0]; String[] res = new String[resources.size()]; return resources.toArray(res); }
From source file:org.glite.slcs.pki.bouncycastle.Codec.java
/** * Return an array of all X509Certificates stored in a PEM encoded source. * The certificate order of the source is respected. * //w w w .j a va 2 s . com * @param reader * The Reader used to read the source. * @return The array of all X509 certificates found in the PEM source. * @throws IOException * If an error occurs while reading the source. */ static public X509Certificate[] readPEMEncodedCertificates(Reader reader) throws IOException { Vector<X509Certificate> certificates = new Vector<X509Certificate>(); LOG.debug("read all certificates"); PEMReader pr = new PEMReader(reader); boolean haveNext = true; while (haveNext) { X509Certificate certificate = (X509Certificate) pr.readObject(); if (certificate == null) { haveNext = false; // stop loop } else { certificates.add(certificate); } } int length = certificates.size(); LOG.debug(length + " certificates found"); X509Certificate certificatesArray[] = (X509Certificate[]) certificates.toArray(new X509Certificate[length]); return certificatesArray; }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport_UK1.java
protected static Object[] loadDataHSARHP_ISARCEP(File a_SARFile, File a_CASFile) throws IOException { Object[] result = new Object[3]; TreeMap<String, double[]> a_SAROptimistaionConstraints = loadCASOptimistaionConstraints(a_SARFile); TreeMap<String, double[]> a_CASOptimistaionConstraints = loadCASOptimistaionConstraints(a_CASFile); Vector<String> variables = GeneticAlgorithm_HSARHP_ISARCEP.getVariableList(); variables.add(0, "Zone_Code"); String[] variableNames = new String[0]; variableNames = variables.toArray(variableNames); result[0] = variableNames;/*from w w w.ja v a 2 s .c o m*/ // Format (Flip) data double[][] a_SARExpectedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; double[][] a_CASObservedData = new double[variables.size() - 1][a_SAROptimistaionConstraints.size()]; String oa; double[] a_SARExpectedRow; double[] a_CASObservedRow; int j = 0; Iterator<String> iterator_String = a_SAROptimistaionConstraints.keySet().iterator(); while (iterator_String.hasNext()) { oa = iterator_String.next(); a_SARExpectedRow = a_SAROptimistaionConstraints.get(oa); a_CASObservedRow = a_CASOptimistaionConstraints.get(oa); // if (oa.equalsIgnoreCase("00AAFQ0013")){ // System.out.println(oa); // } if (a_SARExpectedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { if (a_CASObservedRow == null) { System.out.println( "Warning a_SARExpectedRow == null in loadDataHSARHP_ISARCEP(File,File) for OA " + oa); } else { for (int i = 0; i < variables.size() - 1; i++) { a_SARExpectedData[i][j] = a_SARExpectedRow[i]; a_CASObservedData[i][j] = a_CASObservedRow[i]; } } } j++; } result[1] = a_SARExpectedData; result[2] = a_CASObservedData; return result; }