List of usage examples for java.util Vector size
public synchronized int size()
From source file:com.jada.admin.contactus.ContactUsMaintAction.java
public void initSearchInfo(ContactUsMaintActionForm form, String siteId) throws Exception { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); Query query = em//from w w w . j a va 2 s.c o m .createQuery("from country in class Country where country.siteId = :siteId order by countryName"); query.setParameter("siteId", siteId); Iterator<?> iterator = query.getResultList().iterator(); Vector<LabelValueBean> vector = new Vector<LabelValueBean>(); while (iterator.hasNext()) { Country country = (Country) iterator.next(); LabelValueBean bean = new LabelValueBean(country.getCountryName(), country.getCountryCode()); vector.add(bean); } LabelValueBean countries[] = new LabelValueBean[vector.size()]; vector.copyInto(countries); form.setCountries(countries); String sql = ""; sql = "from State state " + "left join fetch state.country country " + "where country.siteId = :siteId " + "order by country.countryId, state.stateName"; query = em.createQuery(sql); query.setParameter("siteId", siteId); iterator = query.getResultList().iterator(); vector = new Vector<LabelValueBean>(); vector.add(new LabelValueBean("", "")); while (iterator.hasNext()) { State state = (State) iterator.next(); LabelValueBean bean = new LabelValueBean(state.getStateName(), state.getStateCode()); vector.add(bean); } LabelValueBean states[] = new LabelValueBean[vector.size()]; vector.copyInto(states); form.setStates(states); }
From source file:fsi_admin.JSmtpConn.java
@SuppressWarnings("rawtypes") private boolean adjuntarArchivo(StringBuffer msj, BodyPart messagebodypart, MimeMultipart multipart, Vector archivos) { if (!archivos.isEmpty()) { FileItem actual = null;/*from w w w . ja v a 2s .c o m*/ try { for (int i = 0; i < archivos.size(); i++) { InputStream inputStream = null; try { actual = (FileItem) archivos.elementAt(i); inputStream = actual.getInputStream(); byte[] sourceBytes = IOUtils.toByteArray(inputStream); String name = actual.getName(); messagebodypart = new MimeBodyPart(); ByteArrayDataSource rawData = new ByteArrayDataSource(sourceBytes); DataHandler data = new DataHandler(rawData); messagebodypart.setDataHandler(data); messagebodypart.setFileName(name); multipart.addBodyPart(messagebodypart); //////////////////////////////////////////////// /* messagebodypart = new MimeBodyPart(); DataSource source = new FileDataSource(new File(actual.getName())); byte[] sourceBytes = actual.get(); OutputStream sourceOS = source.getOutputStream(); sourceOS.write(sourceBytes); messagebodypart.setDataHandler(new DataHandler(source)); messagebodypart.setFileName(actual.getName()); multipart.addBodyPart(messagebodypart); */ /////////////////////////////////////////////////////// } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } catch (MessagingException e) { e.printStackTrace(); msj.append("Error de Mensajeria al cargar adjunto SMTP: " + e.getMessage()); return false; } catch (IOException e) { e.printStackTrace(); msj.append("Error de Entrada/Salida al cargar adjunto SMTP: " + e.getMessage()); return false; } } else return true; }
From source file:AppletFinder.java
public String[] findApplets(URL u) { BufferedReader inrdr = null;/*from w w w . java 2 s . c om*/ Vector v = new Vector(); char thisChar = 0; try { inrdr = new BufferedReader(new InputStreamReader(u.openStream())); int i; while ((i = inrdr.read()) != -1) { thisChar = (char) i; if (thisChar == '<') { String tag = readTag(inrdr); // System.out.println("TAG: " + tag); if (tag.toUpperCase().startsWith("<APPLET")) v.addElement(tag); } } inrdr.close(); } catch (IOException e) { System.err.println("Error reading from main URL: " + e); } String applets[] = new String[v.size()]; v.copyInto(applets); return applets; }
From source file:cm.aptoide.pt.RemoteInSearch.java
private String downloadFile(int position) { Vector<DownloadNode> tmp_serv = new Vector<DownloadNode>(); String getserv = new String(); String md5hash = null;/* ww w .j ava 2s.co m*/ String repo = null; try { tmp_serv = db.getPathHash(apk_lst.get(position).apkid); if (tmp_serv.size() > 0) { DownloadNode node = tmp_serv.get(0); getserv = node.repo + "/" + node.path; md5hash = node.md5h; repo = node.repo; } if (getserv.length() == 0) throw new TimeoutException(); Message msg = new Message(); msg.arg1 = 0; msg.obj = new String(getserv); download_handler.sendMessage(msg); /*BufferedInputStream getit = new BufferedInputStream(new URL(getserv).openStream()); String path = new String(APK_PATH+apk_lst.get(position).name+".apk"); FileOutputStream saveit = new FileOutputStream(path); BufferedOutputStream bout = new BufferedOutputStream(saveit,1024); byte data[] = new byte[1024]; int readed = getit.read(data,0,1024); while(readed != -1) { bout.write(data,0,readed); readed = getit.read(data,0,1024); } bout.close(); getit.close(); saveit.close();*/ String path = new String(APK_PATH + apk_lst.get(position).name + ".apk"); FileOutputStream saveit = new FileOutputStream(path); DefaultHttpClient mHttpClient = new DefaultHttpClient(); HttpGet mHttpGet = new HttpGet(getserv); String[] logins = null; logins = db.getLogin(repo); if (logins != null) { URL mUrl = new URL(getserv); mHttpClient.getCredentialsProvider().setCredentials(new AuthScope(mUrl.getHost(), mUrl.getPort()), new UsernamePasswordCredentials(logins[0], logins[1])); } HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet); if (mHttpResponse.getStatusLine().getStatusCode() == 401) { return null; } else { byte[] buffer = EntityUtils.toByteArray(mHttpResponse.getEntity()); saveit.write(buffer); } File f = new File(path); Md5Handler hash = new Md5Handler(); if (md5hash == null || md5hash.equalsIgnoreCase(hash.md5Calc(f))) { return path; } else { return null; } } catch (Exception e) { return null; } }
From source file:amulet.appbuilder.AppBuilder.java
@SuppressWarnings("unchecked") private boolean callPipeLine(String filename) { QMReader qm = new QMReader(filename); try {//from www . j a v a2 s. c o m manifestReader = new ManifestReader(filename); } catch (Exception exp) { System.out.println("Exception when creating manifest reader for " + filename); exp.printStackTrace(); return false; } // This will be written to a file for parsing by the Resource Profile UI finalJSONGraphStructure = new JSONObject(); if (passToolchain) { Vector<QMClass> classes = qm.getClasses(); authModule = new AuthorizationModule(manifestReader); for (int j = 0; j < classes.size(); j++) { QMClass qmclass = classes.get(j); Vector<State> states = qmclass.getStates(); Vector<Node> action_nodes = qmclass.getActionNodes(); Vector<Node> guard_nodes = qmclass.getGuardNodes(); Vector<Node> operation_nodes = qmclass.getOperationNodes(); // Get all the attributes (global variables) that are put in FRAM HashMap<String, String[]> attdetails = qmclass.getAttributesWithDetails(); resourceProfiler.setGlobalContext(qmclass.getName()); for (String key : attdetails.keySet()) { String[] attinfo = attdetails.get(key); resourceProfiler.addMemoryResource(qmclass.getName(), attinfo[0], key, attinfo[1], ResourceType.GLOBAL_MEMORY); } resourceProfiler.clearProfilerContext(); // This outputs a JSON format of the QMClass finalJSONGraphStructure.put("appname", qmclass.getName()); finalJSONGraphStructure.put("app_human_readable_name", manifestReader.getAppName()); finalJSONGraphStructure.put("app_human_readable_description", manifestReader.getAppDescription()); /* * States. */ // DEBUG:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //NodeList initNodes = qmclass.getInitialTransition(); //for(int n = 0; n < initNodes.getLength(); n++) { // String target = initNodes.item(n).getAttributes().getNamedItem("target").getNodeValue(); // System.out.println("##DEBUG## init->" + qmclass.getQmSateId2NameMapEntry("NONE", target)); //} // DEBUG:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: for (int i = 0; i < states.size(); i++) { State state = states.get(i); if (state != null) { // Set state attributes. String stateName = state.getName(); // DEBUG:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //for(Transition t : state.getTransitions()) { // QMTransition qmt = (QMTransition) t; // System.out.println("##DEBUG## " + qmt.getSource().getName() + "->" + qmt.getTrigger() + "->" + qmt.getTarget().getName()); //} // DEBUG:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // [ENTER] State i. resourceProfiler.setStateContext(stateName); // AFT analyzer/translator/profiler (entry) if (state.getEntryCode() != null && state.getEntryCode().length() > 0) { compatchecker = new CompatChecker(state.getEntryCode(), qmclass.getName()); if (!compatchecker.getSuccess()) return false; if (!authModule.checkApiAuthorization(state.getEntryCode())) return false; runtimecheck = new RuntimeCheck(qmclass, state.getEntryCode(), togglePins, qmclass.getArrayAttributes(), resourceProfiler); state.setEntryCode(runtimecheck.getCheckedCode()); attributeMapper = new AttributeMapper(state.getEntryCode(), qmclass.getAttributes()); state.setEntryCode(attributeMapper.getMappedCode()); } // AFT analyzer/translator/profiler (exit) if (state.getExitCode() != null && state.getExitCode().length() > 0) { compatchecker = new CompatChecker(state.getExitCode(), qmclass.getName()); if (!compatchecker.getSuccess()) return false; if (!authModule.checkApiAuthorization(state.getExitCode())) return false; runtimecheck = new RuntimeCheck(qmclass, state.getExitCode(), togglePins, qmclass.getArrayAttributes(), resourceProfiler); state.setExitCode(runtimecheck.getCheckedCode()); attributeMapper = new AttributeMapper(state.getExitCode(), qmclass.getAttributes()); state.setExitCode(attributeMapper.getMappedCode()); } // Add "basic blocks" record to state. Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(), ResourceType.COMPUTATION, 0.0); resourceProfiler.add(record); // [EXIT] State i. resourceProfiler.clearProfilerContext(); } } /* * Action Nodes (i.e., Transitions). */ JSONArray statesJsonArray = new JSONArray(); String prevState = null, prevTrigger = null, prevTarget = null; for (int i = 0; i < action_nodes.size(); i++) { if (action_nodes.get(i) != null && action_nodes.get(i).getTextContent() != null) { /* * Set transition attributes. */ String currentState = "", triggerName = "", targetNameID = ""; Node action_node = action_nodes.get(i); Node parent1 = action_node.getParentNode(); Node parent2 = parent1.getParentNode(); // Set the "source" (i.e., the state which this action node is contained within---the "parent state"). currentState = QMClass.getCurrentQMStateFromActionNode(action_node); // Set the "trigger". if (parent1.getAttributes().getNamedItem("trig") != null) { triggerName = parent1.getAttributes().getNamedItem("trig").getNodeValue(); } else if (parent2.getAttributes().getNamedItem("trig") != null) { triggerName = parent2.getAttributes().getNamedItem("trig").getNodeValue(); } else { triggerName = "init"; } // Set the "target". if (parent1.getAttributes().getNamedItem("target") != null) { targetNameID = parent1.getAttributes().getNamedItem("target").getNodeValue(); } else if (parent2.getAttributes().getNamedItem("target") != null) { targetNameID = parent2.getAttributes().getNamedItem("target").getNodeValue(); } else { targetNameID = "init-target-unset?"; } // Fetch the (human-readable) name of the state referenced by the ID specified in the action node. String targetName = qmclass.getQmSateId2NameMapEntry(currentState, targetNameID); /* * Guard against recording duplicate records (it can happen!). * * NOTE: This is a little sloppy, since it assumes that the duplicate records happen in * sequence; this seems to always be true with the QM files we've worked with, but this * issue may need to be re-addressed later... */ if (!currentState.equals(prevState) || !triggerName.equals(prevTrigger) || !targetName.equals(prevTarget)) { //System.out.println(" + TRIGGER:: currentState=" + currentState + "->triggerName="+triggerName + "->targetName="+targetName + " (targetNameID="+targetNameID+")"); // Maintain a JSON representation of the FSM (i.e., states and transitions). JSONObject actionJsonObj = new JSONObject(); actionJsonObj.put("source", currentState); actionJsonObj.put("trigger", triggerName); actionJsonObj.put("target", targetName); statesJsonArray.add(actionJsonObj); // [ENTER] Action Node i. resourceProfiler.setActionContext(currentState, triggerName, targetName); // AFT analyzer/translator/profiler compatchecker = new CompatChecker(action_nodes.get(i).getTextContent(), qmclass.getName()); if (!compatchecker.getSuccess()) return false; if (!authModule.checkApiAuthorization(action_nodes.get(i).getTextContent())) return false; runtimecheck = new RuntimeCheck(qmclass, action_nodes.get(i).getTextContent(), togglePins, qmclass.getArrayAttributes(), resourceProfiler); action_nodes.get(i).setTextContent(runtimecheck.getCheckedCode()); attributeMapper = new AttributeMapper(action_nodes.get(i).getTextContent(), qmclass.getAttributes()); action_nodes.get(i).setTextContent(attributeMapper.getMappedCode()); // Add "basic blocks" record to action. Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(), ResourceType.COMPUTATION, 0.0); resourceProfiler.add(record); // [EXIT] Action Node i. resourceProfiler.clearProfilerContext(); } // Keep track of the previous trigger information... prevState = currentState; prevTrigger = triggerName; prevTarget = targetName; } } finalJSONGraphStructure.put("states", statesJsonArray); /* * Guard Nodes. */ for (int i = 0; i < guard_nodes.size(); i++) { if (guard_nodes.get(i) != null && guard_nodes.get(i).getTextContent() != null && guard_nodes.get(i).getTextContent().length() > 0) { // [ENTER] Guard Node i. resourceProfiler.setGuardContext(); // AFT analyzer/translator/profiler compatchecker = new CompatChecker(guard_nodes.get(i).getTextContent(), qmclass.getName()); if (!compatchecker.getSuccess()) return false; if (!authModule.checkApiAuthorization(guard_nodes.get(i).getTextContent())) return false; runtimecheck = new RuntimeCheck(qmclass, guard_nodes.get(i).getTextContent(), togglePins, qmclass.getArrayAttributes(), resourceProfiler); guard_nodes.get(i).setTextContent(runtimecheck.getCheckedCode()); attributeMapper = new AttributeMapper(guard_nodes.get(i).getTextContent(), qmclass.getAttributes()); guard_nodes.get(i).setTextContent(attributeMapper.getMappedCode()); // Add "basic blocks" record to guard. Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(), ResourceType.COMPUTATION, 0.0); resourceProfiler.add(record); // [EXIT] Guard Node i. resourceProfiler.clearProfilerContext(); } } /* * Operation Nodes. */ for (int i = 0; i < operation_nodes.size(); i++) { if (operation_nodes.get(i) != null && operation_nodes.get(i).getTextContent() != null && operation_nodes.get(i).getTextContent().length() > 0) { // Set operations attributes. String name = operation_nodes.get(i).getParentNode().getAttributes().getNamedItem("name") .getNodeValue(); String type = operation_nodes.get(i).getParentNode().getAttributes().getNamedItem("type") .getNodeValue(); String visibility = operation_nodes.get(i).getParentNode().getAttributes() .getNamedItem("visibility").getNodeValue(); String properties = operation_nodes.get(i).getParentNode().getAttributes() .getNamedItem("properties").getNodeValue(); // [ENTER] Operation Node i. resourceProfiler.setOperationContext(name, type, visibility, properties); // AFT analyzer/translator/profiler compatchecker = new CompatChecker(operation_nodes.get(i).getTextContent(), qmclass.getName()); if (!compatchecker.getSuccess()) return false; if (!authModule.checkApiAuthorization(operation_nodes.get(i).getTextContent())) return false; runtimecheck = new RuntimeCheck(qmclass, operation_nodes.get(i).getTextContent(), togglePins, qmclass.getArrayAttributes(), resourceProfiler); operation_nodes.get(i).setTextContent(runtimecheck.getCheckedCode()); attributeMapper = new AttributeMapper(operation_nodes.get(i).getTextContent(), qmclass.getAttributes()); operation_nodes.get(i).setTextContent(attributeMapper.getMappedCode()); // Add "basic blocks" record to operation. Resource record = new Resource(ComputationType.BASIC_BLOCKS.text(), qmclass.getName(), ResourceType.COMPUTATION, 0.0); resourceProfiler.add(record); // [EXIT] Operation Node i. resourceProfiler.clearProfilerContext(); // For now, add a place-holder entry to the operation map -- it will be updated later // when a request is made to the Resource Profiler to calculate the cost of some application. resourceProfiler.getCurrentQMAppObj().addOperationRecord(name, 0.0, 0.0); } } // Verify checks against function white-list pass... funcWhiteList = new FunctionWhitelist(qmclass.getName(), states, action_nodes, guard_nodes, qmclass.getOperations()); if (!funcWhiteList.getSuccess()) return false; } } else { System.out.println("AFT WARNING: skipping AFT processing -- code has not been properly validated!"); } qm.saveAs(filename + ".temp"); return true; }
From source file:com.xpn.xwiki.plugin.svg.SVGPlugin.java
protected String[] expandSources(Vector sources) { Vector expandedSources = new Vector(); Iterator iter = sources.iterator(); while (iter.hasNext()) { String v = (String) iter.next(); File f = new File(v); if (f.exists() && f.isDirectory()) { File[] fl = f.listFiles(new SVGConverter.SVGFileFilter()); for (File element : fl) { expandedSources.addElement(element.getPath()); }/*from w w w. ja v a2 s. com*/ } else { expandedSources.addElement(v); } } String[] s = new String[expandedSources.size()]; expandedSources.copyInto(s); return s; }
From source file:net.aepik.alasca.core.ldap.Schema.java
/** * Ajoute un ensemble d'objets au schema. * @param v Un ensemble d'objets du schema. * @return True si l'opration a russi, false sinon. * Si l'opration n'a pas russi, aucun objet n'aura t ajout. *//*from w ww. ja va2s.co m*/ public boolean addObjects(Vector<SchemaObject> v) { SchemaObject[] o = new SchemaObject[v.size()]; Iterator<SchemaObject> it = v.iterator(); int position = 0; while (it.hasNext()) { o[position] = it.next(); position++; } return addObjects(o); }
From source file:gov.nih.nci.evs.browser.utils.TreeUtils.java
public HashMap getSubconcepts(String scheme, String version, String code) { //String assocName = "hasSubtype"; String hierarchicalAssoName = "hasSubtype"; Vector hierarchicalAssoName_vec = getHierarchyAssociationId(scheme, version); if (hierarchicalAssoName_vec != null && hierarchicalAssoName_vec.size() > 0) { hierarchicalAssoName = (String) hierarchicalAssoName_vec.elementAt(0); }//from ww w .ja v a 2s. c o m return getAssociationTargets(scheme, version, code, hierarchicalAssoName); }
From source file:fr.dyade.aaa.util.MySqlDBRepository.java
/** * Gets a list of persistent objects that name corresponds to prefix. * * @return The list of corresponding names. *///from ww w.ja v a 2 s . c o m public String[] list(String prefix) throws IOException { try { // Creating a statement lets us issue commands against the connection. Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT name FROM JoramDB WHERE name LIKE '" + prefix + "%'"); Vector v = new Vector(); while (rs.next()) { v.add(rs.getString(1)); } rs.close(); s.close(); String[] result = new String[v.size()]; result = (String[]) v.toArray(result); return result; } catch (SQLException sqle) { if (sqle instanceof com.mysql.jdbc.CommunicationsException && !reconnectLoop) { logger.log(BasicLevel.WARN, "Database reconnection problem at list, Reconnecting"); reconnection(); reconnectLoop = true; String[] result = list(prefix); reconnectLoop = false; return result; } if (reconnectLoop) logger.log(BasicLevel.WARN, "Database reconnection problem at list"); logger.log(BasicLevel.WARN, "list, problem list " + prefix); sqle.printStackTrace(); throw new IOException(sqle.getMessage()); } catch (Exception e) { logger.log(BasicLevel.WARN, "list, problem list " + prefix + " in e with " + e.getMessage()); e.printStackTrace(); throw new IOException(e.getMessage()); } }
From source file:mypackage.FeedlyAPI.java
public void keepOneOrMultipleArticlesAsUnread(Vector entryIds) throws IOException, Exception { // Keep one or multiple articles as unread // POST /v3/markers if (entryIds.size() == 0) { throw new Exception("FeedlyAPI::keepOneOrMultipleArticlesAsUnread()0"); }/*from w w w . j av a2 s . c om*/ // JSONObject json = new JSONObject(); try { json.put("action", "keepUnread"); json.put("type", "entries"); json.put("entryIds", entryIds); } catch (JSONException e) { throw new Exception("FeedlyAPI::keepOneOrMultipleArticlesAsUnread()1"); } // O???Aw???s?B for (int i = 0; i < NUM_OF_TRIALS; i++) { try { doPost(getEndpoint("/v3/markers"), json); return; } catch (IOException e) { continue; } catch (Exception e) { continue; } } throw new Exception("FeedlyAPI::keepOneOrMultipleArticlesAsUnread()2"); }