List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:net.cloudkit.relaxation.VerifyImage.java
public String getResult(Map<String, byte[][]> fontMods, BufferedImage src) { int w = src.getWidth(); int h = src.getHeight(); byte[][] p = imgToByteArray(src); ArrayList offsetXs = new ArrayList(9); offsetXs.add(Integer.valueOf(0)); ArrayList offsetYs = new ArrayList(9); offsetYs.add(Integer.valueOf(0)); if (this.sum(p[0]) < 3) { offsetXs.add(Integer.valueOf(1)); }//from ww w . java2 s .com if (this.sum(p[w - 1]) < 3) { offsetXs.add(Integer.valueOf(-1)); } int s1 = 0; int s2 = 0; for (int fontSets = 0; fontSets < w; ++fontSets) { s1 += p[fontSets][0]; s2 += p[fontSets][h - 1]; } if (s1 < 3) { offsetYs.add(Integer.valueOf(1)); } if (s2 < 3) { offsetYs.add(Integer.valueOf(-1)); } Set var29 = fontMods.entrySet(); Map.Entry rs = null; int minDiff = -1; Iterator i$ = offsetXs.iterator(); while (i$.hasNext()) { Integer osx = (Integer) i$.next(); Iterator i$1 = offsetYs.iterator(); label103: while (i$1.hasNext()) { Integer osy = (Integer) i$1.next(); Iterator i$2 = var29.iterator(); while (true) { Map.Entry font; int diff; do { int mw; int mh; do { do { if (!i$2.hasNext()) { continue label103; } font = (Map.Entry) i$2.next(); diff = 0; mw = ((byte[][]) font.getValue()).length; mh = ((byte[][]) font.getValue())[0].length; } while (Math.abs(h + osy.intValue() - mh) > 3); } while (Math.abs(w + osx.intValue() - mw) > 3); int minH = Math.min(h + osy.intValue(), mh); int minW = Math.min(w + osx.intValue(), mw); byte[][] fontV = (byte[][]) font.getValue(); for (int yi = 0; yi < minH; ++yi) { for (int xi = 0; xi < minW; ++xi) { int tx = xi + osx.intValue(); int ty = yi + osy.intValue(); if (tx >= 0 && ty >= 0 && tx < w && ty < h && fontV[xi][yi] != p[tx][ty]) { ++diff; } } } } while (minDiff != -1 && minDiff <= diff); minDiff = diff; rs = font; } } } if (minDiff > 10) { System.out.println("?" + minDiff); return ""; } else { return rs == null ? "" : ((String) rs.getKey()).substring(0, 1); } }
From source file:com.day.cq.wcm.foundation.List.java
@SuppressWarnings("unchecked") private boolean init() { if (!inited) { initConfig();//from w ww. j av a 2s . c o m // Note: this iter can also be set from the outside (setPageIterator()) if (pageIterator == null) { PageManager pm = request.getResourceResolver().adaptTo(PageManager.class); // per default we don't want duplicate pages in the result boolean allowDuplicates = properties.get(ALLOW_DUPLICATES_PROPERTY_NAME, false); try { Session session = resource.getResourceResolver().adaptTo(Session.class); // advanced search = querybuilder if (SOURCE_QUERYBUILDER.equals(source)) { QueryBuilder queryBuilder = resource.getResourceResolver().adaptTo(QueryBuilder.class); if (session != null && queryBuilder != null) { try { Query query = queryBuilder .loadQuery(resource.getPath() + "/" + SAVEDQUERY_PROPERTY_NAME, session); if (query != null) { query.setHitsPerPage(limit); SearchResult result = query.getResult(); // store as both page and node iterator pageIterator = new HitBasedPageIterator(pm, result.getHits().iterator(), !allowDuplicates, this.pageFilter); nodeIterator = result.getNodes(); } } catch (Exception e) { log.error("error loading stored querybuilder query from " + resource.getPath(), e); } } // simple search } else if (SOURCE_SEARCH.equals(source)) { if (DEFAULT_QUERY.equals(query)) { pageIterator = EmptyIterator.INSTANCE; } if (queryType != null) { javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager() .createQuery(query, queryType); QueryResult result = jcrQuery.execute(); pageIterator = new NodeBasedPageIterator(pm, result.getNodes(), !allowDuplicates, this.pageFilter); } else { SimpleSearch search = getSearch(resource.getPath()); search.setQuery(query); search.setSearchIn(startIn); // ensure we only get pages search.addPredicate(new Predicate("type", "type").set("type", NameConstants.NT_PAGE)); search.setHitsPerPage(100000); // run simple search SearchResult result = search.getResult(); pageIterator = new HitBasedPageIterator(pm, result.getHits().iterator(), !allowDuplicates, this.pageFilter); } // list child pages } else if (SOURCE_CHILDREN.equals(source)) { // default to current page String parentPath = properties.get(PARENT_PAGE_PROPERTY_NAME, resource.getPath()); Page startPage = pm.getContainingPage(parentPath); if (startPage != null) { // only get pages that are valid (on/off times, hide in nav) // Use default page filter if there is no page filter, because it was working this way // before adding PageFilter support pageIterator = startPage .listChildren(this.pageFilter != null ? this.pageFilter : new PageFilter()); } else { pageIterator = EmptyIterator.INSTANCE; } // list from tags } else if (SOURCE_TAGS.equals(source)) { // default to current page String parentPath = properties.get(TAGS_SEARCH_ROOT_PROPERTY_NAME, resource.getPath()); String[] tags = properties.get(TAGS_PROPERTY_NAME, new String[0]); boolean matchAny = properties.get(TAGS_MATCH_PROPERTY_NAME, "any").equals("any"); Page startPage = pm.getContainingPage(parentPath); if (startPage != null && tags.length > 0) { TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class); RangeIterator<Resource> results = tagManager.find(startPage.getPath(), tags, matchAny); LinkedHashMap<String, Page> pages = new LinkedHashMap<String, Page>(); while (results.hasNext()) { Resource r = results.next(); Page page = pm.getContainingPage(r); if (page != null && (pageFilter == null || pageFilter.includes(page))) { pages.put(page.getPath(), page); } } pageIterator = pages.values().iterator(); } else { pageIterator = EmptyIterator.INSTANCE; } // fixed list of pages } else { ArrayList<Page> staticPages = new ArrayList<Page>(); String[] statics = properties.get(PAGES_PROPERTY_NAME, new String[0]); for (String path : statics) { Page p = pm.getContainingPage(path); if (p != null && (pageFilter == null || pageFilter.includes(p))) { staticPages.add(p); } } pageIterator = staticPages.iterator(); } } catch (Exception e) { log.error("error creating page iterator", e); } } pages = new ArrayList<Page>(); resources = new ArrayList<Resource>(); if (pageIterator == null) { return false; } // build list of pages and resources from page iterator while (pageIterator.hasNext()) { Page page = pageIterator.next(); pages.add(page); } // apply sort order if present if (orderComparator != null) { Collections.sort(pages, orderComparator); } else if (orderBy != null) { Collections.sort(pages, new PageComparator<Page>(orderBy)); } // apply limit if (pages.size() > limit) { pages = pages.subList(0, limit); } for (Page p : pages) { resources.add(p.getContentResource()); } inited = true; } return true; }
From source file:gr.iit.demokritos.cru.cps.api.SubmitUserFormalEvaluationList.java
public JSONObject processRequest() throws IOException, Exception { String response_code = "e0"; long user_id = 0; String[] users = users_list.split(";"); ArrayList<Long> users_id = new ArrayList<Long>(); for (int i = 0; i < users.length; i++) { users_id.add(Long.parseLong(users[i])); }/*from w w w . j a va 2s . co m*/ String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { Connection connection = mysql.connectToCPSDatabase(); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT window FROM windows WHERE current_window=1"); int window = -1; while (rs.next()) { window = rs.getInt(1); } rs.close(); UserManager um = new UserManager(Long.parseLong(application_key), users_id); CreativityExhibitModelController cemc = new CreativityExhibitModelController(window, Long.parseLong(application_key), user_id, users_id); boolean isvalid = false; isvalid = um.validateClientApplication(mysql); if (isvalid == true) { Iterator it = users_id.iterator(); while (it.hasNext()) { um.setUser_id((Long) it.next()); isvalid = um.validateUser(mysql); if (isvalid == false) { break; } } if (isvalid == true) { cemc.storeFormalEvaluation(mysql); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); for (Long temp_user : users_id) { list.add(Long.toString(temp_user)); } JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("user_id", Long.toString(user_id)); obj.put("users_id", list); obj.put("response_code", response_code); return obj; }
From source file:logdruid.util.DataMiner.java
public static FileMineResultSet fastMine(ArrayList<FileRecord> arrayList, final Repository repo, final Source source, final boolean stats, final boolean timings) { ThreadPool_FileWorkers = Executors .newFixedThreadPool(Integer.parseInt(Preferences.getPreference("ThreadPool_File"))); Date startDate = null;/*from w w w . j a va 2 s . com*/ Date endDate = null; // Map<String, ExtendedTimeSeries> statMap = HashObjObjMaps<String, // ExtendedTimeSeries>(); Map<String, ExtendedTimeSeries> statMap = new HashMap<String, ExtendedTimeSeries>(); Map<String, ExtendedTimeSeries> eventMap = new HashMap<String, ExtendedTimeSeries>(); Map<String, long[]> timingStatsMap = new HashMap<String, long[]>(); Map<String, Map<Date, FileLine>> fileLine = new HashMap<String, Map<Date, FileLine>>(); Collection<Callable<FileMineResult>> tasks = new ArrayList<Callable<FileMineResult>>(); ArrayList<Object> mapArrayList; mapArrayList = new ArrayList<>(); if (logger.isEnabledFor(Level.INFO)) logger.info("mine called on " + source.getSourceName()); Iterator<FileRecord> fileArrayListIterator = arrayList.iterator(); while (fileArrayListIterator.hasNext()) { final FileRecord fileRec = fileArrayListIterator.next(); tasks.add(new Callable<FileMineResult>() { public FileMineResult call() throws Exception { logger.debug("file mine on " + fileRec); return fileMine(fileRec, repo, source, stats, timings); } }); } List<Future<FileMineResult>> results = null; try { results = ThreadPool_FileWorkers.invokeAll(tasks, 1000, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (Future<FileMineResult> f : results) { FileMineResult fileMineRes = null; try { if (f != null) { fileMineRes = f.get(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NullPointerException e) { // TODO Auto-generated catch block // e.printStackTrace(); } if (fileMineRes != null) { mapArrayList.add(fileMineRes); } } ArrayList<Object[]> fileDates = new ArrayList<Object[]>(); Iterator<Object> mapArrayListIterator = mapArrayList.iterator(); while (mapArrayListIterator.hasNext()) { FileMineResult fMR = (FileMineResult) mapArrayListIterator.next(); if (startDate == null) { startDate = fMR.getStartDate(); } if (endDate == null) { endDate = fMR.getEndDate(); } if (fMR.getEndDate() != null && fMR.getStartDate() != null) { if (fMR.getEndDate().after(endDate)) { endDate = fMR.getEndDate(); } else if (fMR.getStartDate().before(startDate)) { startDate = fMR.getStartDate(); } if (logger.isDebugEnabled()) { logger.debug("1: " + fMR.getStartDate() + "2: " + fMR.getEndDate() + "3: " + fMR.getFile()); } fileDates.add(new Object[] { fMR.getStartDate(), fMR.getEndDate(), fMR.getFile() }); } Map<String, ExtendedTimeSeries> tempStatMap = fMR.statGroupTimeSeries; tempStatMap.entrySet(); Iterator it = tempStatMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, ExtendedTimeSeries> pairs = (Map.Entry<String, ExtendedTimeSeries>) it.next(); if (!statMap.containsKey(pairs.getKey())) { statMap.put(pairs.getKey(), pairs.getValue()); } else { ExtendedTimeSeries ts = statMap.get(pairs.getKey()); if (stats) { int[] array = { pairs.getValue().getStat()[0] + ts.getStat()[0], pairs.getValue().getStat()[1] + ts.getStat()[1] }; ts.setStat(array); } ts.getTimeSeries().addAndOrUpdate(pairs.getValue().getTimeSeries()); statMap.put(pairs.getKey(), ts); // logger.info(pairs.getKey()); } } Map tempEventMap = fMR.eventGroupTimeSeries; tempEventMap.entrySet(); it = tempEventMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, ExtendedTimeSeries> pairs = (Map.Entry<String, ExtendedTimeSeries>) it.next(); if (!eventMap.containsKey(pairs.getKey())) { eventMap.put(pairs.getKey(), pairs.getValue()); } else { ExtendedTimeSeries ts = eventMap.get(pairs.getKey()); if (stats) { int[] array = { pairs.getValue().getStat()[0] + ts.getStat()[0], pairs.getValue().getStat()[1] + ts.getStat()[1] }; ts.setStat(array); } ts.getTimeSeries().addAndOrUpdate(pairs.getValue().getTimeSeries()); eventMap.put(pairs.getKey(), ts); } } it = fMR.matchingStats.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, long[]> pairs = (Map.Entry<String, long[]>) it.next(); if (!timingStatsMap.containsKey(pairs.getKey())) { timingStatsMap.put(pairs.getKey(), pairs.getValue()); } else { long[] array = timingStatsMap.get(pairs.getKey()); // 0-> sum of time for success matching of given // recording ; 1-> sum of time for failed // matching ; 2-> count of match attempts, // 3->count of success attempts long[] array2 = { pairs.getValue()[0] + array[0], pairs.getValue()[1] + array[1], pairs.getValue()[2] + array[2], pairs.getValue()[3] + array[3] }; timingStatsMap.put(pairs.getKey(), array2); } } it = fMR.fileLineDateMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Map<Date, FileLine>> pairs = (Map.Entry<String, Map<Date, FileLine>>) it.next(); if (logger.isDebugEnabled()) { logger.debug("Entry<String,Map<Date, FileLine>> : " + pairs); } if (!fileLine.containsKey(pairs.getKey())) { fileLine.put(pairs.getKey(), pairs.getValue()); if (logger.isDebugEnabled()) { logger.debug("fileLine.put " + pairs.getKey() + " -> " + pairs.getValue()); } } else { Map<Date, FileLine> ts = fileLine.get(pairs.getKey()); Map<Date, FileLine> newDateFileLineEntries = pairs.getValue(); Iterator it2 = newDateFileLineEntries.entrySet().iterator(); while (it2.hasNext()) { Map.Entry<Date, FileLine> pairs2 = (Map.Entry<Date, FileLine>) it2.next(); fileLine.get(pairs.getKey()).put(pairs2.getKey(), pairs2.getValue()); if (logger.isDebugEnabled()) { logger.debug("fileLine.put " + pairs2.getKey() + " -> " + pairs2.getValue().getFileId() + ":" + pairs2.getValue().getLineNumber()); } } //logger.info("cont2: "+fileLine.get(pairs.getKey())); } } } return new FileMineResultSet(fileDates, statMap, eventMap, timingStatsMap, fileLine, startDate, endDate); }
From source file:ar.com.fdvs.dj.core.layout.ClassicLayoutManager.java
protected void applyFooterAutotexts() { if (getReport().getAutoTexts() == null) return;//from w w w .ja v a 2s. c o m JRDesignBand footerband = (JRDesignBand) getDesign().getPageFooter(); if (footerband == null) { footerband = new JRDesignBand(); getDesign().setPageFooter(footerband); } ArrayList positions = new ArrayList(); positions.add(HorizontalBandAlignment.LEFT); positions.add(HorizontalBandAlignment.CENTER); positions.add(HorizontalBandAlignment.RIGHT); for (Iterator iterator = positions.iterator(); iterator.hasNext();) { HorizontalBandAlignment currentAlignment = (HorizontalBandAlignment) iterator.next(); int yOffset = 0; /** * Apply the autotext in footer if any */ for (Iterator iter = getReport().getAutoTexts().iterator(); iter.hasNext();) { AutoText autotext = (AutoText) iter.next(); if (autotext.getPosition() == AutoText.POSITION_FOOTER && autotext.getAlignment().equals(currentAlignment)) { CommonExpressionsHelper.add(yOffset, (DynamicJasperDesign) getDesign(), this, footerband, autotext); yOffset += autotext.getHeight().intValue(); } } } }
From source file:hermes.browser.HermesBrowser.java
/** * Initialise the underlying Hermes that we're gonna do all our work with * //from ww w .ja v a 2 s.co m * @throws HermesException * @throws NamingException */ public void loadConfig() throws NamingException, HermesException { Properties props = new Properties(); Context oldContext = context; HermesConfig oldConfig = null; props.put(Context.INITIAL_CONTEXT_FACTORY, HermesInitialContextFactory.class.getName()); props.put(Context.PROVIDER_URL, getCurrentConfigURL()); props.put("hermes.loader", JAXBHermesLoader.class.getName()); log.debug("props=" + props); Iterator listeners = null; if (loader != null) { listeners = loader.getConfigurationListeners(); oldConfig = loader.getConfig(); } if (oldConfig != null) { Set naming = new HashSet(); naming.addAll(oldConfig.getNaming()); for (Iterator iter = naming.iterator(); iter.hasNext();) { NamingConfig oldNaming = (NamingConfig) iter.next(); loader.notifyNamingRemoved(oldNaming); } } context = new InitialContext(props); loader = (HermesLoader) context.lookup(HermesContext.LOADER); if (listeners != null) { while (listeners.hasNext()) { loader.addConfigurationListener((HermesConfigurationListener) listeners.next()); } } if (oldContext != null) { for (NamingEnumeration iter = oldContext.listBindings(""); iter.hasMoreElements();) { Binding binding = (Binding) iter.next(); try { if (oldContext.lookup(binding.getName()) instanceof Hermes) { Hermes hermes = (Hermes) oldContext.lookup(binding.getName()); Hermes newHermes = null; try { newHermes = (Hermes) context.lookup(hermes.getId()); } catch (NamingException e) { // NOP } if (newHermes == null) { loader.notifyHermesRemoved(hermes); } } } catch (NamingException ex) { // NOP } } } if (!firstLoad) { closeWatches(); final ArrayList tmpList = new ArrayList(); tmpList.addAll(loader.getConfig().getWatch()); loader.getConfig().getWatch().clear(); for (Iterator iter = tmpList.iterator(); iter.hasNext();) { WatchConfig wConfig = (WatchConfig) iter.next(); createWatch(wConfig); } } setTitle("HermesJMS - " + TextUtils.crumble(getCurrentConfigURL(), 100)); }
From source file:com.cyberway.issue.crawler.frontier.WorkQueueFrontier.java
/** * @param w Writer to print to./*from w w w . j av a 2s . c o m*/ */ private void standardReportTo(PrintWriter w) { int allCount = allQueues.size(); int inProcessCount = inProcessQueues.uniqueSet().size(); int readyCount = readyClassQueues.size(); int snoozedCount = snoozedClassQueues.size(); int activeCount = inProcessCount + readyCount + snoozedCount; int inactiveCount = inactiveQueues.size(); int retiredCount = retiredQueues.size(); int exhaustedCount = allCount - activeCount - inactiveCount - retiredCount; w.print("Frontier report - "); w.print(ArchiveUtils.get12DigitDate()); w.print("\n"); w.print(" Job being crawled: "); w.print(controller.getOrder().getCrawlOrderName()); w.print("\n"); w.print("\n -----===== STATS =====-----\n"); w.print(" Discovered: "); w.print(Long.toString(discoveredUriCount())); w.print("\n"); w.print(" Queued: "); w.print(Long.toString(queuedUriCount())); w.print("\n"); w.print(" Finished: "); w.print(Long.toString(finishedUriCount())); w.print("\n"); w.print(" Successfully: "); w.print(Long.toString(succeededFetchCount())); w.print("\n"); w.print(" Failed: "); w.print(Long.toString(failedFetchCount())); w.print("\n"); w.print(" Disregarded: "); w.print(Long.toString(disregardedUriCount())); w.print("\n"); w.print("\n -----===== QUEUES =====-----\n"); w.print(" Already included size: "); w.print(Long.toString(alreadyIncluded.count())); w.print("\n"); w.print(" pending: "); w.print(Long.toString(alreadyIncluded.pending())); w.print("\n"); w.print("\n All class queues map size: "); w.print(Long.toString(allCount)); w.print("\n"); w.print(" Active queues: "); w.print(activeCount); w.print("\n"); w.print(" In-process: "); w.print(inProcessCount); w.print("\n"); w.print(" Ready: "); w.print(readyCount); w.print("\n"); w.print(" Snoozed: "); w.print(snoozedCount); w.print("\n"); w.print(" Inactive queues: "); w.print(inactiveCount); w.print("\n"); w.print(" Retired queues: "); w.print(retiredCount); w.print("\n"); w.print(" Exhausted queues: "); w.print(exhaustedCount); w.print("\n"); w.print("\n -----===== IN-PROCESS QUEUES =====-----\n"); @SuppressWarnings("unchecked") Collection<WorkQueue> inProcess = inProcessQueues; ArrayList<WorkQueue> copy = extractSome(inProcess, REPORT_MAX_QUEUES); appendQueueReports(w, copy.iterator(), copy.size(), REPORT_MAX_QUEUES); w.print("\n -----===== READY QUEUES =====-----\n"); appendQueueReports(w, this.readyClassQueues.iterator(), this.readyClassQueues.size(), REPORT_MAX_QUEUES); w.print("\n -----===== SNOOZED QUEUES =====-----\n"); copy = extractSome(snoozedClassQueues, REPORT_MAX_QUEUES); appendQueueReports(w, copy.iterator(), copy.size(), REPORT_MAX_QUEUES); WorkQueue longest = longestActiveQueue; if (longest != null) { w.print("\n -----===== LONGEST QUEUE =====-----\n"); longest.reportTo(w); } w.print("\n -----===== INACTIVE QUEUES =====-----\n"); appendQueueReports(w, this.inactiveQueues.iterator(), this.inactiveQueues.size(), REPORT_MAX_QUEUES); w.print("\n -----===== RETIRED QUEUES =====-----\n"); appendQueueReports(w, this.retiredQueues.iterator(), this.retiredQueues.size(), REPORT_MAX_QUEUES); w.flush(); }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public void detachImeiFromSurvey(String surveyID, String imeiNumber) throws MSMApplicationException { String sQuery = "from Transactionlog t where t.transactionType = "; sQuery += "\'"; sQuery += TransactionLogVO.TYPE_SEND_SURVEY; sQuery += "\'"; sQuery += " and survey.idSurvey = :surveyID"; sQuery += " and t.imei.imei = :imeiNumber"; Query q = manager.createQuery(sQuery); q.setParameter("surveyID", surveyID); q.setParameter("imeiNumber", imeiNumber); ArrayList<Transactionlog> queryResult = (ArrayList<Transactionlog>) q.getResultList(); Iterator<Transactionlog> queryIterator = queryResult.iterator(); while (queryIterator.hasNext()) { Transactionlog transactionlog = (Transactionlog) queryIterator.next(); manager.remove(transactionlog);//from w w w . j av a 2s . c om } }
From source file:BwaPairedAlignment.java
/** * Code to run in each one of the mappers. This is, the alignment with the corresponding entry data * The entry data has to be written into the local filesystem *///w w w . j a v a 2 s . com @Override public Iterator<String> call(Integer arg0, Iterator<Tuple2<String, String>> arg1) throws Exception { // STEP 1: Input fastq reads tmp file creation LOG.info("JMAbuin:: Tmp dir: " + this.tmpDir); String fastqFileName1 = this.tmpDir + this.appId + "-RDD" + arg0 + "_1"; String fastqFileName2 = this.tmpDir + this.appId + "-RDD" + arg0 + "_2"; LOG.info("JMAbuin:: Writing file: " + fastqFileName1); LOG.info("JMAbuin:: Writing file: " + fastqFileName2); File FastqFile1 = new File(fastqFileName1); File FastqFile2 = new File(fastqFileName2); FileOutputStream fos1; FileOutputStream fos2; BufferedWriter bw1; BufferedWriter bw2; ArrayList<String> returnedValues = new ArrayList<String>(); //We write the data contained in this split into the two tmp files try { fos1 = new FileOutputStream(FastqFile1); fos2 = new FileOutputStream(FastqFile2); bw1 = new BufferedWriter(new OutputStreamWriter(fos1)); bw2 = new BufferedWriter(new OutputStreamWriter(fos2)); Tuple2<String, String> newFastqRead; while (arg1.hasNext()) { newFastqRead = arg1.next(); bw1.write(newFastqRead._1.toString()); bw1.newLine(); bw2.write(newFastqRead._2.toString()); bw2.newLine(); } bw1.close(); bw2.close(); arg1 = null; returnedValues = this.runAlignmentProcess(arg0, fastqFileName1, fastqFileName2); // Delete temporary files, as they have now been copied to the // output directory LOG.info("JMAbuin:: Deleting file: " + fastqFileName1); FastqFile1.delete(); LOG.info("JMAbuin:: Deleting file: " + fastqFileName2); FastqFile2.delete(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); LOG.error(e.toString()); } return returnedValues.iterator(); }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public Collection<SurveyVO> listSurveysByImeiDB(String imei, String status) throws MSMApplicationException, MSMSystemException { NdgUser user = businessDelegate.getUserByImei(imei); ArrayList<SurveyVO> ret = new ArrayList<SurveyVO>(); Query q = manager.createQuery("from Transactionlog t where transactionType = " + "\'" + TransactionLogVO.TYPE_SEND_SURVEY + "\' " + "and imei.imei = :imei " + "and transactionStatus = :status " + "group by t.survey.idSurvey"); q.setParameter("imei", imei); q.setParameter("status", status); ArrayList<Transactionlog> al = (ArrayList<Transactionlog>) q.getResultList(); Iterator<Transactionlog> it = al.iterator(); while (it.hasNext()) { SurveyXML survey = null;//from w ww. j av a 2 s . c o m Transactionlog surveyTransactionLog = (Transactionlog) it.next(); SurveyVO vo = new SurveyVO(); vo.setIdSurvey(surveyTransactionLog.getSurvey().getIdSurvey()); survey = loadSurveyAndResultsDB(user.getUserAdmin(), surveyTransactionLog.getSurvey().getIdSurvey()); CreateXml.xmlToString(survey.getXmldoc()); Survey surveyPojo = manager.find(Survey.class, surveyTransactionLog.getSurvey().getIdSurvey()); try { byte[] stringXMLByte = surveyPojo.getSurveyXml().getBytes("UTF-8"); vo.setSurvey(new String(stringXMLByte, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } vo.setTitle(survey.getTitle()); vo.setResultsSent(survey.getResultsSize()); vo.setStatus(surveyTransactionLog.getTransactionStatus()); ret.add(vo); } return ret; }