List of usage examples for java.util Vector elementAt
public synchronized E elementAt(int index)
From source file:com.sittinglittleduck.DirBuster.workGenerators.WorkerGenerator.java
/** Thread run method */ public void run() { String currentDir = "/"; int failcode = 404; String line;/*w w w . j av a 2s. c om*/ Vector extToCheck = new Vector(10, 5); boolean recursive = true; int passTotal = 0; // -------------------------------------------------- try { // find the total number of requests to be made, per pass // based on the fact there is a single entry per line BufferedReader d = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))); passTotal = 0; while ((line = d.readLine()) != null) { if (!line.startsWith("#")) { passTotal++; } } manager.setTotalPass(passTotal); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } // ------------------------------------------------- // checks if the server surports heads requests if (manager.getAuto()) { try { URL headurl = new URL(firstPart); HeadMethod httphead = new HeadMethod(headurl.toString()); // set the custom HTTP headers Vector HTTPheaders = manager.getHTTPHeaders(); for (int a = 0; a < HTTPheaders.size(); a++) { HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a); /* * Host header has to be set in a different way! */ if (httpHeader.getHeader().startsWith("Host:")) { httphead.getParams().setVirtualHost(httpHeader.getValue()); } else { httphead.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue()); } } httphead.setFollowRedirects(Config.followRedirects); int responceCode = httpclient.executeMethod(httphead); if (Config.debug) { System.out.println("DEBUG WokerGen: responce code for head check = " + responceCode); } // if the responce code is method not implemented or if the head requests return // 400! if (responceCode == 501 || responceCode == 400 || responceCode == 405) { if (Config.debug) { System.out.println( "DEBUG WokerGen: Changing to GET only HEAD test returned 501(method no implmented) or a 400"); } // switch the mode to just GET requests manager.setAuto(false); } } catch (MalformedURLException e) { // TODO deal with error } catch (IOException e) { // TODO deal with error } } // end of checks to see if server surpports head requests int counter = 0; while ((!dirQueue.isEmpty() || !workQueue.isEmpty() || !manager.areWorkersAlive()) && recursive) { // get the dir we are about to process String baseResponce = null; recursive = manager.isRecursive(); BaseCase baseCaseObj = null; // rest the skip skipCurrent = false; // deal with the dirs try { // get item from queue // System.out.println("gen about to take"); DirToCheck tempDirToCheck = dirQueue.take(); // System.out.println("gen taken"); // get dir name currentDir = tempDirToCheck.getName(); // get any extention that need to be checked extToCheck = tempDirToCheck.getExts(); manager.setCurrentlyProcessing(currentDir); } catch (InterruptedException e) { e.printStackTrace(); } started = currentDir; // generate the list of dirs if (manager.getDoDirs()) { // find the fail case for the dir URL failurl = null; try { baseResponce = null; baseCaseObj = GenBaseCase.genBaseCase(manager, firstPart + currentDir, true, null); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // end of dir fail case if (stopMe) { return; } // generate work links try { // readin dir names BufferedReader d = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))); if (Config.debug) { System.out.println("DEBUG WokerGen: Generating dir list for " + firstPart); } URL currentURL; // add the first item while doing dir's if (counter == 0) { try { String method; if (manager.getAuto() && !baseCaseObj.useContentAnalysisMode() && !baseCaseObj.isUseRegexInstead()) { method = "HEAD"; } else { method = "GET"; } currentURL = new URL(firstPart + currentDir); // System.out.println("first part = " + firstPart); // System.out.println("current dir = " + currentDir); workQueue.put(new WorkUnit(currentURL, true, "GET", baseCaseObj, null)); if (Config.debug) { System.out.println("DEBUG WokerGen: 1 adding dir to work list " + method + " " + currentDir.toString()); } } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } } // end of dealing with first item int dirsProcessed = 0; // add the rest of the dirs while ((line = d.readLine()) != null) { // code to skip the current work load if (skipCurrent) { // add the totalnumber per pass - the amount process this pass to the // work correction total manager.addToWorkCorrection(passTotal - dirsProcessed); break; } // if the line is not empty or starts with a # if (!line.equalsIgnoreCase("") && !line.startsWith("#")) { line = line.trim(); line = makeItemsafe(line); try { String method; if (manager.getAuto() && !baseCaseObj.useContentAnalysisMode() && !baseCaseObj.isUseRegexInstead()) { method = "HEAD"; } else { method = "GET"; } currentURL = new URL(firstPart + currentDir + line + "/"); // BaseCase baseCaseObj = new BaseCase(currentURL, failcode, true, // failurl, baseResponce); // if the base case is null then we need to switch to content // anylsis mode // System.out.println("Gen about to add to queue"); workQueue.put(new WorkUnit(currentURL, true, method, baseCaseObj, line)); // System.out.println("Gen finshed adding to queue"); if (Config.debug) { System.out.println("DEBUG WokerGen: 2 adding dir to work list " + method + " " + currentURL.toString()); } } catch (MalformedURLException e) { // TODO deal with bad line // e.printStackTrace(); // do nothing if it's malformed, I dont care about them! } catch (InterruptedException e) { e.printStackTrace(); } // if there is a call to stop the work gen then stop! if (stopMe) { return; } dirsProcessed++; } } // end of while } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // generate the list of files if (manager.getDoFiles()) { baseResponce = null; URL failurl = null; // loop for all the different file extentions for (int b = 0; b < extToCheck.size(); b++) { // only test if we are surposed to ExtToCheck extTemp = (ExtToCheck) extToCheck.elementAt(b); if (extTemp.toCheck()) { fileExtention = ""; if (extTemp.getName().equals(ExtToCheck.BLANK_EXT)) { fileExtention = ""; } else { fileExtention = "." + extTemp.getName(); } try { // get the base for this extention baseCaseObj = GenBaseCase.genBaseCase(manager, firstPart + currentDir, false, fileExtention); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // if the manager has sent the stop command then exit if (stopMe) { return; } try { BufferedReader d = new BufferedReader( new InputStreamReader(new FileInputStream(inputFile))); // if(failcode != 200) // { int filesProcessed = 0; while ((line = d.readLine()) != null) { // code to skip the current work load if (skipCurrent) { manager.addToWorkCorrection(passTotal - filesProcessed); break; } // dont process is the line empty for starts with a # if (!line.equalsIgnoreCase("") && !line.startsWith("#")) { line = line.trim(); line = makeItemsafe(line); try { String method; if (manager.getAuto() && !baseCaseObj.useContentAnalysisMode() && !baseCaseObj.isUseRegexInstead()) { method = "HEAD"; } else { method = "GET"; } URL currentURL = new URL(firstPart + currentDir + line + fileExtention); // BaseCase baseCaseObj = new BaseCase(currentURL, true, // failurl, baseResponce); workQueue.put(new WorkUnit(currentURL, false, method, baseCaseObj, line)); if (Config.debug) { System.out.println("DEBUG WokerGen: adding file to work list " + method + " " + currentURL.toString()); } } catch (MalformedURLException e) { // e.printStackTrace(); // again do nothing as I dont care } catch (InterruptedException e) { e.printStackTrace(); } if (stopMe) { return; } filesProcessed++; } } // end of while // } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } // end of file ext loop } // end of if files finished = started; counter++; try { Thread.sleep(200); } catch (InterruptedException ex) { ex.printStackTrace(); } } // end of main while // System.out.println("Gen FINISHED!"); // manager.youAreFinished(); }
From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java
/** * Split using a seperator.// w ww . jav a 2 s .co m * * @param line The String to be seperated. * @param sep The seperator character, eg a comma * @return An array of Strings containing the seperated data. * @see #splitBySeparatorAndParen(String line, char sep) */ public static String[] splitBySeparator(String line, char sep) { String newLine = line; Vector temp = new Vector(); while (true) { int separatorIndex = newLine.indexOf(sep); if (separatorIndex == -1) { String lastNum = newLine.substring(separatorIndex + 1); temp.addElement(lastNum.trim()); break; } else { String newNum = newLine.substring(0, separatorIndex); temp.addElement(newNum.trim()); } newLine = newLine.substring(separatorIndex + 1); } String[] result = new String[temp.size()]; for (int i = 0; i < result.length; i++) { result[i] = (String) temp.elementAt(i); } return (result); }
From source file:com.instantme.api.InstagramAPI.java
private boolean updateToken(String tokenUrl) { boolean result = false; if (tokenUrl.startsWith(REDIRECT_URI)) { Vector v = split(tokenUrl, "="); if (v.size() == 2) { String accessToken = (String) v.elementAt(1); if (accessToken.length() > 0) { println("Access token = " + accessToken); cookies.put("accessToken", accessToken); result = true;// w w w . j av a 2 s . co m } } } return result; }
From source file:com.vangent.hieos.logbrowser.servlets.GetTableServlet.java
/** * * @param column//w ww.ja va 2s .c o m * @param sortingStatus * @return */ private String toJSon(int column, int sortingStatus) { try { JSONObject response = new JSONObject(); JSONObject content = new JSONObject(); JSONArray array = new JSONArray(); if (column == -1 || sortingStatus == -2) { array.put(tableModel.getHeaderVector()); } else if (column > -1 && sortingStatus > -2 && sortingStatus < 2 /*-1,0 or 1 */) { Vector<String> vectorCopy = (Vector<String>) tableModel.getHeaderVector().clone(); for (int header = 0; header < tableModel.getHeaderVector().size(); header++) { if (header == column) { switch (sortingStatus) { case -1: vectorCopy.set(header, vectorCopy.elementAt(header) + " ↓"); break; case 0: vectorCopy.set(header, vectorCopy.elementAt(header) + " ↑↓"); break; case 1: vectorCopy.set(header, vectorCopy.elementAt(header) + " ↑"); break; } } } array.put(vectorCopy); } for (int row = 0; row < tableModel.getDataVector().size(); row++) { array.put((Vector<Object>) tableModel.getDataVector().get(row)); } content.put("table", array); content.put("isAdmin", new Boolean(isAdmin).toString()); response.put("result", content); return response.toString(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:net.nosleep.superanalyzer.analysis.views.PlayCountView.java
private void refreshDataset() { Stat itemStats = null;/* w ww . j a v a 2 s . com*/ if (_comboBox == null) { itemStats = _analysis.getStats(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); itemStats = _analysis.getStats(item.getKind(), item.getValue()); } Vector playCountList = new Vector(); Hashtable playCounts = itemStats.getPlayCounts(); Enumeration e = playCounts.keys(); while (e.hasMoreElements()) { Integer playCount = (Integer) e.nextElement(); Integer count = (Integer) playCounts.get(playCount); if (count.intValue() > 0) playCountList.addElement(new PlayCountItem(playCount.intValue(), count.intValue())); } Collections.sort(playCountList, new PlayCountComparator()); XYSeries series = new XYSeries(Misc.getString("PLAY_COUNT")); for (int i = 0; i < playCountList.size(); i++) { PlayCountItem item = (PlayCountItem) playCountList.elementAt(i); series.add(item.PlayCount, item.Count); } collection.removeAllSeries(); collection.addSeries(series); }
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 ww w. j a v a 2 s . 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:net.nosleep.superanalyzer.analysis.views.RatingView.java
private void refreshDataset() { _dataset.clear();//from w w w . j av a 2 s . c o m Stat itemStats = null; if (_comboBox == null) { itemStats = _analysis.getStats(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); itemStats = _analysis.getStats(item.getKind(), item.getValue()); } Vector<Double> counts = new Vector<Double>(6); double[] ratings = itemStats.getRatings(); for (int i = 0; i < ratings.length; i++) counts.addElement(new Double(ratings[i])); Vector<String> labels = new Vector<String>(6); labels.add(new String(Misc.getString("NOT_RATED"))); labels.add(new String("1 " + Misc.getString("STAR"))); labels.add(new String("2 " + Misc.getString("STARS"))); labels.add(new String("3 " + Misc.getString("STARS"))); labels.add(new String("4 " + Misc.getString("STARS"))); labels.add(new String("5 " + Misc.getString("STARS"))); PiePlot3D plot = (PiePlot3D) _chart.getPlot(); Color[] colors = Theme.getColorSet(); plot.setIgnoreZeroValues(true); for (int i = 0; i < counts.size(); i++) { // if((Double)counts.elementAt(i) > 0) { _dataset.setValue((String) labels.elementAt(i), (Double) counts.elementAt(i)); plot.setSectionPaint((String) labels.elementAt(i), colors[5 - i]); } } }
From source file:net.nosleep.superanalyzer.analysis.views.YearView.java
/** * Creates a sample dataset./*from ww w . j a va 2 s . c om*/ * * @return The dataset. */ private void refreshDataset() { // TimeSeries t1 = new TimeSeries("Songs you have", "Year", "Count"); // TimeSeries t2 = new TimeSeries("Songs you played", "Year", "Count"); XYSeries t1 = new XYSeries(Misc.getString("SONGS_YOU_HAVE")); XYSeries t2 = new XYSeries(Misc.getString("SONGS_YOU_PLAYED")); Stat itemStats = null; if (_comboBox == null) { itemStats = _analysis.getStats(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); itemStats = _analysis.getStats(item.getKind(), item.getValue()); } Vector yearCountListHave = new Vector(); Hashtable years = itemStats.getYears(); Enumeration e = years.keys(); while (e.hasMoreElements()) { Integer year = (Integer) e.nextElement(); Integer count = (Integer) years.get(year); // if (count.intValue() > 0) yearCountListHave.addElement(new YearCountItem(year.intValue(), count.intValue())); } Collections.sort(yearCountListHave, new YearCountComparator()); for (int i = 0; i < yearCountListHave.size(); i++) { YearCountItem item = (YearCountItem) yearCountListHave.elementAt(i); // _dataset.addValue(item.Count, "Songs you have", new // Integer(item.Year)); t1.add(item.Year, new Integer(item.Count)); } Vector yearCountListPlay = new Vector(); Hashtable yearPlays = itemStats.getPlayYears(); e = yearPlays.keys(); while (e.hasMoreElements()) { Integer year = (Integer) e.nextElement(); Integer count = (Integer) yearPlays.get(year); // if (count.intValue() > 0) yearCountListPlay.addElement(new YearCountItem(year.intValue(), count.intValue())); } Collections.sort(yearCountListPlay, new YearCountComparator()); for (int i = 0; i < yearCountListPlay.size(); i++) { YearCountItem item = (YearCountItem) yearCountListPlay.elementAt(i); // _dataset.addValue(item.Count, "Songs you've played", new // Integer(item.Year)); t2.add(item.Year, new Integer(item.Count)); } _dataset.removeAllSeries(); _dataset.addSeries(t1); _dataset.addSeries(t2); // TimeSeriesCollection tsc = new TimeSeriesCollection(t1); XYPlot plot = (XYPlot) _chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeStickyZero(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Theme.getColorSet()[0]); renderer.setSeriesPaint(1, Theme.getColorSet()[2]); }
From source file:com.verisign.epp.codec.gen.EPPUtil.java
/** * Decode a <code>List</code> of <code>String</code>'s by XML namespace and * tag name, from an XML Element. The children elements of * <code>aElement</code> will be searched for the specified <code>aNS</code> * namespace URI and the specified <code>aTagName</code>. Each XML element * found will be decoded and added to the returned <code>List</code>. Empty * child elements, will result in empty string ("") return <code>List</code> * elements.//from w w w.j av a 2 s . c om * * @param aElement * XML Element to scan. For example, the element could be * <domain:update> * @param aNS * XML namespace of the elements. For example, for domain element * this is "urn:iana:xmlns:domain". * @param aTagName * Tag name of the element including an optional namespace * prefix. For example, the tag name for the domain name servers * is "domain:server". * @return <code>List</code> of <code>String</code> elements representing * the text nodes of the found XML elements. * @exception EPPDecodeException * Error decoding <code>aElement</code>. */ public static List decodeList(Element aElement, String aNS, String aTagName) throws EPPDecodeException { List retVal = new ArrayList(); Vector theChildren = EPPUtil.getElementsByTagNameNS(aElement, aNS, aTagName); for (int i = 0; i < theChildren.size(); i++) { Element currChild = (Element) theChildren.elementAt(i); Text currVal = (Text) currChild.getFirstChild(); // Element has text? if (currVal != null) { retVal.add(currVal.getNodeValue()); } else { // No text in element. retVal.add(""); } } return retVal; }
From source file:com.verisign.epp.codec.gen.EPPUtil.java
/** * Decode a <code>Vector</code> of <code>String</code>'s by XML namespace * and tag name, from an XML Element. The children elements of * <code>aElement</code> will be searched for the specified <code>aNS</code> * namespace URI and the specified <code>aTagName</code>. Each XML element * found will be decoded and added to the returned <code>Vector</code>. * Empty child elements, will result in empty string ("") return * <code>Vector</code> elements. * /*from ww w . j a v a2s . co m*/ * @param aElement * XML Element to scan. For example, the element could be * <domain:update> * @param aNS * XML namespace of the elements. For example, for domain element * this is "urn:iana:xmlns:domain". * @param aTagName * Tag name of the element including an optional namespace * prefix. For example, the tag name for the domain name servers * is "domain:server". * @return <code>Vector</code> of <code>String</code> elements representing * the text nodes of the found XML elements. * @exception EPPDecodeException * Error decoding <code>aElement</code>. */ public static <X> Vector<X> decodeVector(Element aElement, String aNS, String aTagName) throws EPPDecodeException { Vector retVal = new Vector(); Vector theChildren = EPPUtil.getElementsByTagNameNS(aElement, aNS, aTagName); for (int i = 0; i < theChildren.size(); i++) { Element currChild = (Element) theChildren.elementAt(i); Text currVal = (Text) currChild.getFirstChild(); // Element has text? if (currVal != null) { retVal.addElement(currVal.getNodeValue()); } else { // No text in element. retVal.addElement(""); } } return retVal; }