List of usage examples for java.util Vector copyInto
public synchronized void copyInto(Object[] anArray)
From source file:com.toughra.mlearnplayer.EXEStrMgr.java
/** * Gets a list of the keys that need replicated to the cloud *///from ww w . j a v a 2 s . c o m public String[] getReplicateList() { Vector repList = new Vector(); String prefListStr = prefs.getPref(KEY_REPLIST); if (prefListStr == null) { return new String[] {};//zero length string means nothing to replicate } int pos = 0; while (pos < prefListStr.length()) { //search for the next property - all property names start with a : int nextPos = prefListStr.indexOf(':', pos + 1); String propName = prefListStr.substring(pos + 1, nextPos); repList.addElement(propName); pos = nextPos + 1;//e.g. after the ending : for that property } String[] repArr = new String[repList.size()]; repList.copyInto(repArr); return repArr; }
From source file:EditorPaneExample10A.java
public URL[] findLinks(Document doc, String protocol) { Vector links = new Vector(); Vector urlNames = new Vector(); URL baseURL = (URL) doc.getProperty(Document.StreamDescriptionProperty); if (doc instanceof HTMLDocument) { HTMLDocument.Iterator iterator = ((HTMLDocument) doc).getIterator(HTML.Tag.A); for (; iterator.isValid(); iterator.next()) { AttributeSet attrs = iterator.getAttributes(); Object linkAttr = attrs.getAttribute(HTML.Attribute.HREF); if (linkAttr instanceof String) { try { URL linkURL = new URL(baseURL, (String) linkAttr); if (protocol == null || protocol.equalsIgnoreCase(linkURL.getProtocol())) { String linkURLName = linkURL.toString(); if (urlNames.contains(linkURLName) == false) { urlNames.addElement(linkURLName); links.addElement(linkURL); }/* w w w. ja v a 2 s.c om*/ } } catch (MalformedURLException e) { // Ignore invalid links } } } } URL[] urls = new URL[links.size()]; links.copyInto(urls); links.removeAllElements(); urlNames.removeAllElements(); return urls; }
From source file:org.openbravo.erpCommon.utility.ComboTableData.java
public FieldProvider[] select(ConnectionProvider conn, Map<String, String> lparameters, boolean includeActual, Integer startRow, Integer endRow) throws Exception { String actual = lparameters != null ? lparameters.get("@ACTUAL_VALUE@") : getParameter("@ACTUAL_VALUE@"); String filterValue = lparameters != null ? lparameters.get("FILTER_VALUE") : getParameter("FILTER_VALUE"); if (lparameters != null && lparameters.containsKey("@ONLY_ONE_RECORD@") && !lparameters.get("@ONLY_ONE_RECORD@").isEmpty()) { String strSqlSingleRecord = getQuery(false, null, lparameters.get("@ONLY_ONE_RECORD@"), null, null, null, false);// ww w.ja v a 2s.c om log4j.debug("Query for single record: " + strSqlSingleRecord); PreparedStatement stSingleRecord = conn.getPreparedStatement(strSqlSingleRecord); try { ResultSet result; int iParameter = 0; iParameter = setSQLParameters(stSingleRecord, lparameters, iParameter, null, lparameters.get("@ONLY_ONE_RECORD@")); result = stSingleRecord.executeQuery(); if (result.next()) { SQLReturnObject sqlReturnObject = new SQLReturnObject(); sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); sqlReturnObject.setData("NAME", UtilSql.getValue(result, "NAME")); sqlReturnObject.setData("DESCRIPTION", UtilSql.getValue(result, "DESCRIPTION")); Vector<Object> vector = new Vector<Object>(0); vector.add(sqlReturnObject); FieldProvider objectListData[] = new FieldProvider[vector.size()]; vector.copyInto(objectListData); return (objectListData); } if (includeActual && actual != null && !actual.equals("")) { String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; String strSqlDisc = getQuery(true, discard, null, null, null, null, false); PreparedStatement stInactive = conn.getPreparedStatement(strSqlDisc); iParameter = setSQLParameters(stInactive, lparameters, 0, discard); UtilSql.setValue(stInactive, ++iParameter, 12, null, actual); ResultSet resultIn = stInactive.executeQuery(); while (resultIn.next()) { SQLReturnObject sqlReturnObject = new SQLReturnObject(); sqlReturnObject.setData("ID", UtilSql.getValue(resultIn, "ID")); String strName = UtilSql.getValue(resultIn, "NAME"); if (!strName.startsWith(INACTIVE_DATA)) strName = INACTIVE_DATA + strName; sqlReturnObject.setData("NAME", strName); Vector<Object> vector = new Vector<Object>(0); vector.add(sqlReturnObject); FieldProvider objectListData[] = new FieldProvider[vector.size()]; vector.copyInto(objectListData); return (objectListData); } } } finally { conn.releasePreparedStatement(stSingleRecord); } } String strSql = getQuery(false, null, null, startRow, endRow, conn, !StringUtils.isEmpty(filterValue)); if (log4j.isDebugEnabled()) log4j.debug("SQL: " + strSql); PreparedStatement st = conn.getPreparedStatement(strSql); ResultSet result; Vector<Object> vector = new Vector<Object>(0); try { int iParameter = 0; iParameter = setSQLParameters(st, lparameters, iParameter, null, null, filterValue); boolean idFound = false; result = st.executeQuery(); while (result.next()) { SQLReturnObject sqlReturnObject = new SQLReturnObject(); sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); sqlReturnObject.setData("NAME", UtilSql.getValue(result, "NAME")); sqlReturnObject.setData("DESCRIPTION", UtilSql.getValue(result, "DESCRIPTION")); if (includeActual && actual != null && !actual.equals("")) { if (actual.equals(sqlReturnObject.getData("ID"))) { if (!idFound) { vector.addElement(sqlReturnObject); idFound = true; } } else { vector.addElement(sqlReturnObject); } } else vector.addElement(sqlReturnObject); if (lparameters != null && lparameters.containsKey("#ONLY_ONE_RECORD#")) { FieldProvider objectListData[] = new FieldProvider[vector.size()]; vector.copyInto(objectListData); return (objectListData); } } result.close(); if (includeActual && actual != null && !actual.equals("") && !idFound) { boolean allDataInSinglePage; if (startRow != null && endRow != null) { allDataInSinglePage = startRow == 0 && vector.size() < endRow - startRow; } else { // This method is invoked with startRow = endRow = null for lists. Lists always have load // all data in a single page allDataInSinglePage = true; } if (!allDataInSinglePage) { // retrieved a partial set of data, checking if current id is in a page different that the // served applying the same criteria, if so, do not add it again to the list (it will // appear in its own page) conn.releasePreparedStatement(st); strSql = getQuery(true, null, null, 0, 1, conn, !StringUtils.isEmpty(filterValue)); log4j.debug("SQL to check if actual ID is in another page: " + strSql); st = conn.getPreparedStatement(strSql); setSQLParameters(st, lparameters, 0, null, actual, filterValue); result = st.executeQuery(); idFound = result.next(); result.close(); } if (!idFound) { conn.releasePreparedStatement(st); String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; strSql = getQuery(true, discard, null, null, null, null, false); if (log4j.isDebugEnabled()) log4j.debug("SQL Actual ID: " + strSql); st = conn.getPreparedStatement(strSql); iParameter = setSQLParameters(st, lparameters, 0, discard); UtilSql.setValue(st, ++iParameter, 12, null, actual); result = st.executeQuery(); if (result.next()) { SQLReturnObject sqlReturnObject = new SQLReturnObject(); sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); String strName = UtilSql.getValue(result, "NAME"); if (!strName.startsWith(INACTIVE_DATA)) strName = INACTIVE_DATA + strName; sqlReturnObject.setData("NAME", strName); vector.addElement(sqlReturnObject); idFound = true; } } result.close(); if (!idFound) { SQLReturnObject sqlReturnObject = new SQLReturnObject(); sqlReturnObject.setData("ID", actual); sqlReturnObject.setData("NAME", INACTIVE_DATA + Utility.messageBD(conn, "NotFound", lparameters != null ? lparameters.get("#AD_LANGUAGE") : getParameter("#AD_LANGUAGE"))); vector.addElement(sqlReturnObject); } } } catch (SQLException e) { log4j.error("Error of SQL in query: " + strSql + "Exception:" + e); throw new Exception("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage()); } finally { conn.releasePreparedStatement(st); } FieldProvider objectListData[] = new FieldProvider[vector.size()]; vector.copyInto(objectListData); return (objectListData); }
From source file:org.eredlab.g4.ccl.net.nntp.NNTPClient.java
/*** * List all new articles added to the NNTP server since a particular * date subject to the conditions of the specified query. If no new * new news is found, a zero length array will be returned. If the * command fails, null will be returned. You must add at least one * newsgroup to the query, else the command will fail. Each String * in the returned array is a unique message identifier including the * enclosing < and >.//www .j a v a2s . c o m * <p> * @param query The query restricting how to search for new news. You * must add at least one newsgroup to the query. * @return An array of String instances containing the unique message * identifiers for each new article added to the NNTP server. If no * new news is found, a zero length array will be returned. If the * command fails, null will be returned. * @exception NNTPConnectionClosedException * If the NNTP server prematurely closes the connection as a result * of the client being idle or some other reason causing the server * to send NNTP reply code 400. This exception may be caught either * as an IOException or independently as itself. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ public String[] listNewNews(NewGroupsOrNewsQuery query) throws IOException { int size; String line; Vector list; String[] result; BufferedReader reader; if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(), query.isGMT(), query.getDistributions()))) return null; list = new Vector(); reader = new BufferedReader(new DotTerminatedMessageReader(_reader_)); while ((line = reader.readLine()) != null) list.addElement(line); size = list.size(); if (size < 1) return new String[0]; result = new String[size]; list.copyInto(result); return result; }
From source file:org.eredlab.g4.ccl.net.nntp.NNTPClient.java
private NewsgroupInfo[] __readNewsgroupListing() throws IOException { int size;/*from w w w . j a v a 2 s . co m*/ String line; Vector list; BufferedReader reader; NewsgroupInfo tmp, info[]; reader = new BufferedReader(new DotTerminatedMessageReader(_reader_)); // Start of with a big vector because we may be reading a very large // amount of groups. list = new Vector(2048); while ((line = reader.readLine()) != null) { tmp = __parseNewsgroupListEntry(line); if (tmp != null) list.addElement(tmp); else throw new MalformedServerReplyException(line); } if ((size = list.size()) < 1) return new NewsgroupInfo[0]; info = new NewsgroupInfo[size]; list.copyInto(info); return info; }
From source file:DragDropTreeExample.java
protected File[] getFileList(List files) { int size = files.size(); // Get the files into an array for sorting File[] f = new File[size]; Iterator iter = files.iterator(); int count = 0; while (iter.hasNext()) { f[count++] = (File) iter.next(); }//from w w w. java2 s. c om // Sort the files into alphabetical order // based on pathnames. Arrays.sort(f, new Comparator() { public boolean equals(Object o1) { return false; } public int compare(Object o1, Object o2) { return ((File) o1).getAbsolutePath().compareTo(((File) o2).getAbsolutePath()); } }); // Remove duplicates, retaining the results in a Vector Vector v = new Vector(); char separator = System.getProperty("file.separator").charAt(0); outer: for (int i = f.length - 1; i >= 0; i--) { String secondPath = f[i].getAbsolutePath(); int secondLength = secondPath.length(); for (int j = i - 1; j >= 0; j--) { String firstPath = f[j].getAbsolutePath(); int firstLength = firstPath.length(); if (secondPath.startsWith(firstPath) && firstLength != secondLength && secondPath.charAt(firstLength) == separator) { continue outer; } } v.add(f[i]); } // Copy the retained files into an array f = new File[v.size()]; v.copyInto(f); return f; }
From source file:org.openbravo.base.MultipartRequest.java
protected void readSubmittedFile(InputStream in) throws IOException { Vector<FieldProvider> vector = new Vector<FieldProvider>(); int result = 0; String linea = ""; Vector<Byte> vectorInt = new Vector<Byte>(); boolean isFirstRow = true; while ((result = in.read()) != -1) { if (result == 13 || result == 10) { if (vectorInt.size() > 0) { byte[] b = new byte[vectorInt.size()]; for (int i = 0; i < vectorInt.size(); i++) { Byte bAux = vectorInt.elementAt(i); b[i] = bAux.byteValue(); }/*from ww w . j a va2 s . c o m*/ vectorInt = new Vector<Byte>(); linea = new String(b, "UTF-8"); if (!isFirstRow || !firstRowHeads) { FieldProvider fieldProvider = setFieldProvider(linea); vector.addElement(fieldProvider); } } isFirstRow = false; } else { byte aux = new Integer(result).byteValue(); vectorInt.addElement(new Byte(aux)); } } if (vectorInt.size() > 0 && (!isFirstRow || !firstRowHeads)) { byte[] b = new byte[vectorInt.size()]; for (int i = 0; i < vectorInt.size(); i++) { Byte bAux = vectorInt.elementAt(i); b[i] = bAux.byteValue(); } vectorInt = new Vector<Byte>(); linea = new String(b); FieldProvider fieldProvider = setFieldProvider(linea); vector.addElement(fieldProvider); } objectFieldProvider = new FieldProvider[vector.size()]; vector.copyInto(objectFieldProvider); }
From source file:org.smap.smapTask.android.activities.MainMapsActivity.java
private void refreshTaskOverlay() { Vector<OnMapElement> places = new Vector<OnMapElement>(); Vector<OnMapElement> polygons = new Vector<OnMapElement>(); Vector<OnMapElement> linestrings = new Vector<OnMapElement>(); PolyStyle polyStyle = null;//from w ww . j a v a2s . c om LineStyle lineStyle = null; mapComponent.removeOnMapElements(taskPlaces); // Clear the existing tasks mapComponent.removeOnMapElements(polyArray); // Clear the existing tasks mapComponent.removeOnMapElements(lineArray); // Clear the existing tasks for (Line line : routeLines) { mapComponent.removeLine(line); } routeLines.clear(); // get all tasks try { FileDbAdapter fda = new FileDbAdapter(); fda.open(); taskListCursor = fda.fetchTasksForSource(getSource(), true); fda.close(); } catch (Exception e) { e.printStackTrace(); // TODO handle exception } if (taskListCursor.moveToFirst()) { do { int taskIdIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ID); int taskLonIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_LON); int taskLatIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_LAT); int taskNameIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_TITLE); int taskStatusIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_STATUS); int taskALonIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ADHOC_LON); int taskALatIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ADHOC_LAT); int taskLocationIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_LOCATION); int taskGeomTypeIndex = taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_GEOM_TYPE); int taskId = taskListCursor.getInt(taskIdIndex); String taskLongitude = taskListCursor.getString(taskLonIndex); String taskLatitude = taskListCursor.getString(taskLatIndex); String taskALongitude = taskListCursor.getString(taskALonIndex); String taskALatitude = taskListCursor.getString(taskALatIndex); String taskName = taskListCursor.getString(taskNameIndex); String taskStatus = taskListCursor.getString(taskStatusIndex); String taskLocation = taskListCursor.getString(taskLocationIndex); String taskGeomType = taskListCursor.getString(taskGeomTypeIndex); if (taskLongitude == null || taskLatitude == null) { continue; } try { double lon = Double.parseDouble(taskLongitude); double lat = Double.parseDouble(taskLatitude); Bitmap icon = null; if (taskStatus.equals(FileDbAdapter.STATUS_T_ACCEPTED)) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.task_marker_accepted); polyStyle = POLY_ACCEPTED; lineStyle = LINE_ACCEPTED; } else if (taskStatus.equals(FileDbAdapter.STATUS_T_DONE)) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.task_marker_done); polyStyle = POLY_DONE; lineStyle = LINE_DONE; } else if (taskStatus.equals(FileDbAdapter.STATUS_T_MISSED) || taskStatus.equals(FileDbAdapter.STATUS_T_CANCELLED) || taskStatus.equals(FileDbAdapter.STATUS_T_REJECTED) || taskStatus.equals(FileDbAdapter.STATUS_T_DELETED)) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.task_marker_missed); polyStyle = POLY_MISSED; lineStyle = LINE_MISSED; } else if (taskStatus.equals(FileDbAdapter.STATUS_T_PENDING)) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.task_marker_pending); polyStyle = POLY_PENDING; lineStyle = LINE_PENDING; } if (icon != null) { // Ignore if an icon was not found for the status final Placemark defaultIcon = new PlaceIcon(Image.createImage(icon), icon.getWidth() / 2, icon.getHeight()); // Add an extra marker to show actual location of completed task if (taskStatus.equals(FileDbAdapter.STATUS_T_DONE)) { try { if (taskALongitude != null && taskALatitude != null) { double lonA = Double.parseDouble(taskALongitude); double latA = Double.parseDouble(taskALatitude); WgsPoint donePoint = new WgsPoint(lonA, latA); Place donePlace = new Place((int) taskId, new PlaceLabel(taskName), pMarkDone, donePoint); places.add(donePlace); } } catch (Exception e) { e.printStackTrace(); } } WgsPoint taskPoint = new WgsPoint(lon, lat); Place newPlace = new Place((int) taskId, new PlaceLabel(taskName), defaultIcon, taskPoint); if (taskGeomType != null && !taskGeomType.equals("POINT")) { String[] coords = taskLocation.split(","); if (coords.length > 1) { Vector<WgsPoint> points = new Vector<WgsPoint>(); for (String c : coords) { String[] cElem = c.split(" "); if (cElem.length == 2) { WgsPoint p = new WgsPoint(Double.parseDouble(cElem[0]), Double.parseDouble(cElem[1])); points.add(p); } } WgsPoint[] pa = new WgsPoint[points.size()]; points.copyInto(pa); if (taskGeomType.equals("POLYGON")) { Polygon aPolygon = new Polygon(pa, polyStyle); polygons.add(aPolygon); } else if (taskGeomType.equals("LINESTRING")) { Line aLine = new Line(pa, lineStyle); linestrings.add(aLine); } } } places.add(newPlace); } } catch (NumberFormatException numberFormatException) { numberFormatException.printStackTrace(); } } while (taskListCursor.moveToNext()); } taskListCursor.close(); // Save a copy of the task places so that they can be removed easily taskPlaces = new OnMapElement[places.size()]; places.copyInto(taskPlaces); mapComponent.addOnMapElements(taskPlaces); if (polygons.size() > 0) { polyArray = new Polygon[polygons.size()]; polygons.copyInto(polyArray); mapComponent.addOnMapElements(polyArray); } if (linestrings.size() > 0) { lineArray = new Line[linestrings.size()]; linestrings.copyInto(lineArray); mapComponent.addOnMapElements(lineArray); } if (!justCreated) { // Prevent nutiteq zooming to to whole world first time onResume is called setMaxBoundingBox(); } justCreated = false; }
From source file:org.globus.gsi.X509Credential.java
protected void loadCertificate(InputStream input) throws CredentialException { if (input == null) { throw new IllegalArgumentException("Input stream to load X509Credential is null"); }//from w ww .j av a2 s.com X509Certificate cert; Vector<X509Certificate> chain = new Vector<X509Certificate>(); String line; BufferedReader reader = null; try { if (input.markSupported()) { input.reset(); } reader = new BufferedReader(new InputStreamReader(input)); while ((line = reader.readLine()) != null) { if (line.indexOf("BEGIN CERTIFICATE") != -1) { byte[] data = getDecodedPEMObject(reader); cert = CertificateLoadUtil.loadCertificate(new ByteArrayInputStream(data)); chain.addElement(cert); } } } catch (IOException e) { throw new CredentialException(e); } catch (GeneralSecurityException e) { throw new CredentialException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { logger.debug("error closing reader", e); // This is ok } } } int size = chain.size(); if (size > 0) { this.certChain = new X509Certificate[size]; chain.copyInto(this.certChain); } }
From source file:org.globus.gsi.X509Credential.java
protected void load(InputStream input) throws CredentialException { if (input == null) { throw new IllegalArgumentException("input stream cannot be null"); }// w w w . j a v a 2 s .co m X509Certificate cert = null; Vector chain = new Vector(3); String line; BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(input)); while ((line = reader.readLine()) != null) { if (line.indexOf("BEGIN CERTIFICATE") != -1) { byte[] data = getDecodedPEMObject(reader); cert = CertificateLoadUtil.loadCertificate(new ByteArrayInputStream(data)); chain.addElement(cert); } else if (line.indexOf("BEGIN RSA PRIVATE KEY") != -1) { byte[] data = getDecodedPEMObject(reader); this.opensslKey = new BouncyCastleOpenSSLKey("RSA", data); } } } catch (Exception e) { throw new CredentialException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } int size = chain.size(); if (size == 0) { throw new CredentialException("no certs"); } if (opensslKey == null) { throw new CredentialException("no key"); } // set chain this.certChain = new X509Certificate[size]; chain.copyInto(certChain); }