List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:org.apache.nutch.tools.PruneIndexTool.java
/** * Create an instance of the tool, and open all input indexes. * @param indexDirs directories with input indexes. At least one valid index must * exist, otherwise an Exception is thrown. * @param queries pruning queries. Each query will be processed in turn, and the * length of the array must be at least one, otherwise an Exception is thrown. * @param checkers if not null, they will be used to perform additional * checks on matching documents - each checker's method {@link PruneChecker#isPrunable(Query, IndexReader, int)} * will be called in turn, for each matching document, and if it returns true this means that * the document should be deleted. A logical AND is performed on the results returned * by all checkers (which means that if one of them returns false, the document will * not be deleted)./*from w ww. java2s . c o m*/ * @param unlock if true, and if any of the input indexes is locked, forcibly * unlock it. Use with care, only when you are sure that other processes don't * modify the index at the same time. * @param dryrun if set to true, don't change the index, just show what would be done. * If false, perform all actions, changing indexes as needed. Note: dryrun doesn't prevent * PruneCheckers from performing changes or causing any other side-effects. * @throws Exception */ public PruneIndexTool(File[] indexDirs, Query[] queries, PruneChecker[] checkers, boolean unlock, boolean dryrun) throws Exception { if (indexDirs == null || queries == null) throw new Exception("Invalid arguments."); if (indexDirs.length == 0 || queries.length == 0) throw new Exception("Nothing to do."); this.queries = queries; this.checkers = checkers; this.dryrun = dryrun; if (dryrun) dr = "[DRY RUN] "; int numIdx = 0; if (indexDirs.length == 1) { Directory dir = FSDirectory.open(indexDirs[0]); if (IndexWriter.isLocked(dir)) { if (!unlock) { throw new Exception("Index " + indexDirs[0] + " is locked."); } if (!dryrun) { IndexWriter.unlock(dir); if (LOG.isDebugEnabled()) { LOG.debug(" - had to unlock index in " + dir); } } } reader = IndexReader.open(dir); numIdx = 1; } else { Directory dir; Vector<IndexReader> indexes = new Vector<IndexReader>(indexDirs.length); for (int i = 0; i < indexDirs.length; i++) { try { dir = FSDirectory.open(indexDirs[i]); if (IndexWriter.isLocked(dir)) { if (!unlock) { if (LOG.isWarnEnabled()) { LOG.warn(dr + "Index " + indexDirs[i] + " is locked. Skipping..."); } continue; } if (!dryrun) { IndexWriter.unlock(dir); if (LOG.isDebugEnabled()) { LOG.debug(" - had to unlock index in " + dir); } } } IndexReader r = IndexReader.open(dir); indexes.add(r); numIdx++; } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(dr + "Invalid index in " + indexDirs[i] + " - skipping..."); } } } if (indexes.size() == 0) throw new Exception("No input indexes."); IndexReader[] readers = indexes.toArray(new IndexReader[0]); reader = new MultiReader(readers); } if (LOG.isInfoEnabled()) { LOG.info(dr + "Opened " + numIdx + " index(es) with total " + reader.numDocs() + " documents."); } searcher = new IndexSearcher(reader); }
From source file:org.jafer.zclient.AbstractClient.java
public JaferException[] getSearchException(String[] databases) throws JaferException { // create empty array for success condition Vector errors = new Vector(); // make sure database names are specified and this client has a // JaferException lined up to report if the database name matches if (databases != null) { for (int i = 0; i < databases.length; i++) { if (databases[i] == null) { errors.add(null);/*from w w w . j a v a 2 s . co m*/ } else { errors.add(this.getSearchException(databases[i])); } } } return (JaferException[]) errors.toArray(new JaferException[] {}); }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param databaseName/*from w w w . j ava2s.c om*/ * @param restoreFilePath * @param glassPane * @param completionMsgKey */ protected boolean doRestoreInBackground(final String databaseName, final String restoreFilePath, final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl, final boolean doSynchronously) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc()); getNumberofTables(); SynchronousWorker backupWorker = new SynchronousWorker() { long dspMegs = 0; long fileSize = 0; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileInputStream input = null; try { String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName(); String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword(); String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); String cmdLine = String.format("%s -u %s --password=%s --host=%s %s %s", mysqlLoc, userName, password, server, (port != null ? ("--port=" + port) : ""), databaseName); Vector<String> args = new Vector<String>(); args.add(mysqlLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); Thread.sleep(100); OutputStream out = process.getOutputStream(); // wait as long it takes till the other process has prompted. try { File inFile = new File(restoreFilePath); fileSize = inFile.length(); //System.out.println(fileSize); double oneMB = (1024.0 * 1024.0); double threshold = fileSize < (oneMB * 4) ? 8192 * 8 : oneMB; long totalBytes = 0; dspMegs = 0; input = new FileInputStream(inFile); try { byte[] bytes = new byte[8192 * 4]; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { out.write(bytes, 0, numBytes); long megs = (long) (totalBytes / threshold); if (megs != dspMegs) { dspMegs = megs; firePropertyChange(MEGS, dspMegs, (int) ((100.0 * totalBytes) / fileSize)); } } else { break; } } while (true); } finally { input.close(); } } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MySQLBackupService.class, ex); ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_RS"); } catch (Exception ex) { ex.printStackTrace(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } setProgress(100); out.flush(); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.err.println(line); } in = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { if (line.startsWith("ERR")) { sb.append(line); sb.append("\n"); } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } return null; } @Override protected void done() { super.done(); JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { statusBar.setProgressDone(STATUSBAR_NAME); } if (glassPane != null) { UIRegistry.clearSimpleGlassPaneMsg(); } if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (statusBar != null) { statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs)); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1)); } } }; if (glassPane != null) { glassPane.setProgress(0); } backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName()) && glassPane != null) { int value = (Integer) evt.getNewValue(); if (value < 100) { glassPane.setProgress((Integer) evt.getNewValue()); } else { glassPane.setProgress(100); } } } }); if (doSynchronously) { return backupWorker.doWork(); } backupWorker.execute(); return true; }
From source file:net.sf.joost.stx.Processor.java
/** * Initialize a <code>Processor</code> object *///from ww w . j a va 2 s . co m private void init(TransformFactory.Instance pTransformNode) { context = new Context(); context.emitter = initializeEmitter(context); eventStack = context.ancestorStack; setErrorHandler(context.errorHandler); // register error handler context.currentProcessor = this; context.currentGroup = context.targetGroup = transformNode = pTransformNode; // first Data frame; needed for the first target group dataStack.push(new Data(context)); // initialize namespaces initNamespaces(); // array of global templates if (globalTemplates == null) { // note: getGlobalTemplates() returns null at the second invocation! Vector tempVec = transformNode.getGlobalTemplates(); globalTemplates = new TemplateFactory.Instance[tempVec.size()]; tempVec.toArray(globalTemplates); Arrays.sort(globalTemplates); } initOutputProperties(); }
From source file:ORG.oclc.os.SRW.SRWDatabase.java
public ScanResponseType doRequest(ScanRequestType request) throws ServletException { searchRequest = null;/*from w ww. j a v a 2s .c o m*/ response = null; ScanResponseType scanResponse = new ScanResponseType(); String version = request.getVersion(); if (version != null && !version.equals("1.1")) return diagnostic(SRWDiagnostic.UnsupportedVersion, version, scanResponse); CQLTermNode root = null; int max = maxTerms, pos = position; long startTime = System.currentTimeMillis(); PositiveInteger pi = request.getMaximumTerms(); if (pi != null) { max = pi.intValue(); pos = max / 2 + 1; } NonNegativeInteger nni = request.getResponsePosition(); if (nni != null) pos = nni.intValue(); String scanTerm = request.getScanClause(); try { if (scanTerm != null) log.info("scanTerm:\n" + Utilities.byteArrayToString(scanTerm.getBytes("UTF-8"))); } catch (Exception e) { } log.info("maxTerms=" + max + ", position=" + pos); try { root = Utilities.getFirstTerm(parser.parse(scanTerm)); } catch (CQLParseException e) { log.error(e); return diagnostic(SRWDiagnostic.QuerySyntaxError, e.getMessage(), scanResponse); } catch (IOException e) { log.error(e); return diagnostic(SRWDiagnostic.QuerySyntaxError, e.getMessage(), scanResponse); } if (root.getTerm().length() == 0) // The method getQualifier() was replaced by getIndex() in version // 1.0 of the parser. This code ensures that either one works. //root = new CQLTermNode(root.getQualifier(), root.getRelation(), "$"); root = new CQLTermNode(SRWSoapBindingImpl.getQualifier(root), root.getRelation(), "$"); String resultSetID = root.getResultSetName(); if (resultSetID != null) { // you can't scan on resultSetId! return diagnostic(SRWDiagnostic.UnsupportedIndex, "cql.resultSetId", scanResponse); } TermsType terms = new TermsType(); TermList tl = getTermList(root, pos, max, request); terms.setTerm(tl.getTerms()); scanResponse.setTerms(terms); Vector<DiagnosticType> diagnostics = tl.getDiagnostics(); if (diagnostics != null && !diagnostics.isEmpty()) { DiagnosticType diagArray[] = new DiagnosticType[diagnostics.size()]; diagnostics.toArray(diagArray); scanResponse.setDiagnostics(new DiagnosticsType(diagArray)); } log.info("scan " + scanTerm + ": (" + (System.currentTimeMillis() - startTime) + "ms)"); return scanResponse; }
From source file:inforuh.eventfinder.sync.SyncAdapter.java
private void handleResponse(String json) { Gson gson = new Gson(); EventsData response = gson.fromJson(json, EventsData.class); List<Event> events = response.events; final int size = events.size(); if (size == 0) return; // empty response int matcher = 0; Vector<ContentValues> evVector = new Vector<>(size); for (Event event : events) { ContentValues ev = new ContentValues(); ev.put(Contract.EventColumn.ID, event.id); ev.put(Contract.EventColumn.TITLE, event.title); ev.put(Contract.EventColumn.CONTENT, event.content); ev.put(Contract.EventColumn.CATEGORY, event.category); ev.put(Contract.EventColumn.START_DATE, event.dateStart); ev.put(Contract.EventColumn.END_DATE, event.endDate); ev.put(Contract.EventColumn.LONGITUDE, event.longitude); ev.put(Contract.EventColumn.LATITUDE, event.latitude); ev.put(Contract.EventColumn.LOCATION, event.location); ev.put(Contract.EventColumn.MAP_ZOOM, event.zoom); ev.put(Contract.EventColumn.IMAGE, event.picture); ev.put(Contract.EventColumn.BARCODE, event.barcode); ev.put(Contract.EventColumn.PRICE, event.price); ev.put(Contract.EventColumn.URL, event.url); ev.put(Contract.EventColumn.ORGANIZER, event.organizer); ev.put(Contract.EventColumn.CONTACT_MAIN, event.contact); ev.put(Contract.EventColumn.CONTACT_TWITTER, event.twitter); ev.put(Contract.EventColumn.CONTACT_FACEBOOK, event.facebook); ev.put(Contract.EventColumn.CONTACT_LINE, event.line); ev.put(Contract.EventColumn.CONTACT_INSTAGRAM, event.instagram); ev.put(Contract.EventColumn.CONTACT_PATH, event.path); if (evVector.add(ev)) matcher++;//from w w w.ja v a2 s. c o m } if (matcher != size) return; if (evVector.size() > 0) { ContentValues[] evArray = new ContentValues[evVector.size()]; evVector.toArray(evArray); long count = getContext().getContentResolver().bulkInsert(Contract.EventColumn.CONTENT_URI, evArray); Log.d(LOG_TAG, "Inserted: " + count); } LocalBroadcastManager.getInstance(getContext()).sendBroadcast(new Intent(ACTION_GET_TIMELINE_FINISH)); }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * Does the backup on a SwingWorker Thread. * @param isMonthly whether it is a monthly backup * @param doSendAppExit requests sending an application exit command when done * @return true if the prefs are set up and there were no errors before the SwingWorker thread was started *///from w w w .j a va 2s . com private boolean doBackUp(final boolean isMonthly, final boolean doSendAppExit, final PropertyChangeListener propChgListener) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqldumpLoc = remotePrefs.get(MYSQLDUMP_LOC, getDefaultMySQLDumpLoc()); final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc()); if (!(new File(mysqldumpLoc)).exists()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_DUMP", mysqldumpLoc); if (propChgListener != null) { propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } return false; } File backupDir = new File(backupLoc); if (!backupDir.exists()) { if (!backupDir.mkdir()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile()); if (propChgListener != null) { propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } return false; } } errorMsg = null; final String databaseName = DBConnection.getInstance().getDatabaseName(); getNumberofTables(); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected String fullPath = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileOutputStream backupOut = null; try { Thread.sleep(100); // Create output file SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_kk_mm_ss"); String fileName = sdf.format(Calendar.getInstance().getTime()) + (isMonthly ? "_monthly" : "") + ".sql"; fullPath = backupLoc + File.separator + fileName; File file = new File(fullPath); backupOut = new FileOutputStream(file); writeStats(getCollectionStats(getTableNames()), getStatsName(fullPath)); String userName = DBConnection.getInstance().getUserName(); String password = DBConnection.getInstance().getPassword(); if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) { Pair<String, String> up = UserAndMasterPasswordMgr.getInstance().getUserNamePasswordForDB(); if (up != null && up.first != null && up.second != null) { userName = up.first; password = up.second; } } String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); Vector<String> args = new Vector<String>(); args.add(mysqldumpLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); InputStream input = process.getInputStream(); byte[] bytes = new byte[8192 * 2]; double oneMeg = (1024.0 * 1024.0); long dspMegs = 0; long totalBytes = 0; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { long megs = (long) (totalBytes / oneMeg); if (megs != dspMegs) { dspMegs = megs; long megsWithTenths = (long) ((totalBytes * 10.0) / oneMeg); firePropertyChange(MEGS, 0, megsWithTenths); } backupOut.write(bytes, 0, numBytes); } else { break; } } while (true); StringBuilder sb = new StringBuilder(); String line; BufferedReader errIn = new BufferedReader(new InputStreamReader(process.getErrorStream())); while ((line = errIn.readLine()) != null) { //System.err.println(line); if (line.startsWith("ERR") || StringUtils.contains(line, "Got error")) { sb.append(line); sb.append("\n"); if (StringUtils.contains(line, "1044") && StringUtils.contains(line, "LOCK TABLES")) { sb.append("\n"); sb.append(UIRegistry.getResourceString("MySQLBackupService.LCK_TBL_ERR")); sb.append("\n"); } } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_BK"); } finally { if (backupOut != null) { try { backupOut.flush(); backupOut.close(); } catch (IOException ex) { ex.printStackTrace(); errorMsg = ex.toString(); } } } return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(STATUSBAR_NAME); UIRegistry.clearSimpleGlassPaneMsg(); if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (doSendAppExit) { CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit")); } if (propChgListener != null) { propChgListener .propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, null, fullPath)); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(STATUSBAR_NAME, true); UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.BACKINGUP", databaseName), 24); backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName())) { long value = (Long) evt.getNewValue(); double val = value / 10.0; statusBar.setText(UIRegistry.getLocalizedMessage("MySQLBackupService.BACKUP_MEGS", val)); } } }); backupWorker.execute(); return true; }
From source file:com.chinamobile.bcbsp.bspstaff.StaffRunner.java
/** * Start to run a BSP staff./*from w w w.j a va2 s . co m*/ */ @Override public void run() { try { String sep = System.getProperty("path.separator"); File workDir = new File(new File(staff.getJobFile()).getParent(), "work"); boolean isCreated = workDir.mkdirs(); if (!isCreated) { LOG.debug("StaffRunner.workDir : " + workDir); } StringBuffer classPath = new StringBuffer(); classPath.append(System.getProperty("java.class.path")); classPath.append(sep); if (Constants.USER_BC_BSP_JOB_TYPE_C.equals(this.conf.getJobType())) { String exe = conf.getJobExe(); if (exe != null) { classPath.append(sep); classPath.append(exe); classPath.append(sep); classPath.append(workDir); } } else { String jar = conf.getJar(); // if jar exists, it into workDir if (jar != null) { RunJar.unJar(new File(jar), workDir); File[] libs = new File(workDir, "lib").listFiles(); if (libs != null) { for (int i = 0; i < libs.length; i++) { // add libs from jar to classpath classPath.append(sep); classPath.append(libs[i]); } } classPath.append(sep); classPath.append(new File(workDir, "classes")); classPath.append(sep); classPath.append(workDir); } } // Build exec child jmv args. Vector<String> vargs = new Vector<String>(); File jvm = new File(new File(System.getProperty("java.home"), "bin"), "java"); vargs.add(jvm.toString()); // bsp.child.java.opts String javaOpts = conf.getConf().get("bsp.child.java.opts", "-Xmx200m"); javaOpts = javaOpts.replace("@taskid@", staff.getStaffID().toString()); String[] javaOptsSplit = javaOpts.split(" "); for (int i = 0; i < javaOptsSplit.length; i++) { vargs.add(javaOptsSplit[i]); } // Add classpath. vargs.add("-classpath"); vargs.add(classPath.toString()); // Setup the log4j prop long logSize = StaffLog.getStaffLogLength(((BSPConfiguration) conf.getConf())); vargs.add("-Dbcbsp.log.dir=" + new File(System.getProperty("bcbsp.log.dir")).getAbsolutePath()); vargs.add("-Dbcbsp.root.logger=INFO,TLA"); LOG.info("debug: staff ID is " + staff.getStaffID()); vargs.add("-Dbcbsp.tasklog.taskid=" + staff.getStaffID()); vargs.add("-Dbcbsp.tasklog.totalLogFileSize=" + logSize); // Add main class and its arguments vargs.add(WorkerManager.Child.class.getName()); InetSocketAddress addr = workerManager.getStaffTrackerReportAddress(); vargs.add(addr.getHostName()); vargs.add(Integer.toString(addr.getPort())); vargs.add(staff.getStaffID().toString()); vargs.add(Integer.toString(getFaultSSStep())); vargs.add(workerManager.getHostName()); vargs.add(this.conf.getJobType()); // Run java runChild(vargs.toArray(new String[0]), workDir); } catch (Exception e) { LOG.error("[run]", e); } }
From source file:org.commoncrawl.hadoop.mergeutils.SequenceFileMerger.java
/** * internal init method//ww w. j av a 2s .c o m * * @param fileSystem * @param conf * @param inputSegments * @param spillWriter * @param keyClass * @param valueClass * @param comparator * @param optionalKeyGenerator * @param optionalCombiner * @throws IOException */ private void init(FileSystem fileSystem, Configuration conf, Vector<Path> inputSegments, SpillWriter<KeyType, ValueType> spillWriter, Class<KeyType> keyClass, Class<ValueType> valueClass, KeyValuePairComparator<KeyType, ValueType> comparator, OptimizedKeyGeneratorAndComparator<KeyType, ValueType> optionalKeyGenerator, SpillValueCombiner<KeyType, ValueType> optionalCombiner ) throws IOException { _comparator = comparator; _optimizedKeyGenerator = optionalKeyGenerator; if (_comparator instanceof RawKeyValueComparator) { _rawComparator = (RawKeyValueComparator<KeyType, ValueType>) _comparator; } if (_rawComparator != null && _optimizedKeyGenerator != null) { throw new IOException("RawComparator not compatible with OptimizedKeyGenerator option!"); } _optionalCombiner = optionalCombiner; try { Vector<MergeResultSegment<KeyType, ValueType>> segments = new Vector<MergeResultSegment<KeyType, ValueType>>(); for (Path path : inputSegments) { // LOG.info("Loading QueryResultSegment:" + path); MergeResultSegment<KeyType, ValueType> resultSegment = new MergeResultSegment<KeyType, ValueType>( fileSystem, conf, path, keyClass, valueClass, _rawComparator != null || _optimizedKeyGenerator != null, _optimizedKeyGenerator); if (!resultSegment.next()) { // LOG.info("QueryResultSegment:" + path // +" returned EOS on initial next.Ignoring Segment"); try { resultSegment.close(); } catch (IOException e) { LOG.error("QueryResultSegment:" + path + " Threw Exception:" + CCStringUtils.stringifyException(e)); } } else { _inputRecordCount++; segments.add(resultSegment); } } // create temporary array for sorting purposes ... MergeResultSegment<KeyType, ValueType> segmentArray[] = segments.toArray(new MergeResultSegment[0]); // sort the array ... Arrays.sort(segmentArray, new Comparator<MergeResultSegment<KeyType, ValueType>>() { @Override public int compare(MergeResultSegment<KeyType, ValueType> o1, MergeResultSegment<KeyType, ValueType> o2) { try { if (_optimizedKeyGenerator != null) { int result = 0; if ((_optimizedKeyType & OptimizedKey.KEY_TYPE_LONG) != 0) { result = (int) (o1.getOptimizedKey().getLongKeyValue() - o2.getOptimizedKey().getLongKeyValue()); } if (result == 0 && ((_optimizedKeyType & OptimizedKey.KEY_TYPE_BUFFER) != 0)) { // compare buffers ... result = _optimizedKeyGenerator.compareOptimizedBufferKeys( o1.getOptimizedKey().getBufferKeyValue().get(), o1.getOptimizedKey().getBufferKeyValue().getOffset(), o1.getOptimizedKey().getBufferKeyValue().getCount(), o2.getOptimizedKey().getBufferKeyValue().get(), o2.getOptimizedKey().getBufferKeyValue().getOffset(), o2.getOptimizedKey().getBufferKeyValue().getCount()); } return result; } else if (_rawComparator != null) { return _rawComparator.compareRaw(o1.getRawKeyData().getData(), 0, o1.getRawKeyData().getLength(), o2.getRawKeyData().getData(), 0, o2.getRawKeyData().getLength(), o1.getRawValueData().getData(), 0, o1.getRawValueData().getLength(), o2.getRawValueData().getData(), 0, o2.getRawValueData().getLength()); } else { return _comparator.compare(o1.getKey(), o1.getValue(), o2.getKey(), o2.getValue()); } } catch (IOException e) { LOG.error(CCStringUtils.stringifyException(e)); throw new RuntimeException(e); } } }); // LOG.info("Initial sorted segment list is ...."); // now store the segments in sorted order ... int index = 0; for (MergeResultSegment<KeyType, ValueType> segment : segmentArray) { segment.setIndex(index++); _segmentList.addTail(segment); } _originalSegementCount = segmentArray.length; _writer = spillWriter; if (!(_writer instanceof RawDataSpillWriter)) { throw new IOException("Writer supplied with RawComparator does not implement RawDataSpillWriter"); } _rawWriter = (RawDataSpillWriter<KeyType, ValueType>) _writer; } catch (IOException e) { LOG.error(CCStringUtils.stringifyException(e)); for (MergeResultSegment<KeyType, ValueType> segment : _segmentList) { try { segment.close(); } catch (IOException e2) { LOG.error(CCStringUtils.stringifyException(e2)); } } throw e; } }
From source file:org.opennaas.extensions.router.model.utils.OpticalSwitchCardProfileLoader.java
/** * //from w w w . ja va 2s . co m * @param type * @param subtype * @param Param * @param name * @return */ public String[] getPortsParameter(String type, String subtype, String paramName) { Vector<String> vector = new Vector<String>(); NodeList ports = getPorts(type, subtype); if (ports != null) { for (int j = 0; j < ports.getLength(); j++) { Node port = ports.item(j); if (port.getNodeType() == Node.ELEMENT_NODE) { if (port.getNodeName().trim().equals("port")) { // get desired param boolean added = false; NodeList portParams = port.getChildNodes(); for (int k = 0; k < portParams.getLength(); k++) { Node paramData = portParams.item(k); if (paramData.getNodeType() == Node.ELEMENT_NODE) { if (paramData.getAttributes() != null) { if (paramData.getAttributes().getNamedItem("name") != null) { if (paramData.getAttributes().getNamedItem("name").getTextContent() .equals(paramName)) { vector.add(paramData.getTextContent().trim()); added = true; } } } } } // if param is not found add empty string if (!added) { vector.add(""); } } } } } String[] values = new String[vector.size()]; return vector.toArray(values); }