List of usage examples for java.util Iterator forEachRemaining
default void forEachRemaining(Consumer<? super E> action)
From source file:org.cristalise.lookup.LookupTestBase.java
public void compare(List<Path> expecteds, Iterator<Path> actualsIter) { List<Path> actuals = new ArrayList<>(); actualsIter.forEachRemaining(actuals::add); assertReflectionEquals(expecteds, actuals, LENIENT_ORDER); }
From source file:org.eclipse.che.api.project.server.impl.FileItemUtils.java
static FileItemParsed parseFile(Iterator<FileItem> iterator) throws ServerException { List<FileItem> fileItems = new LinkedList<>(); iterator.forEachRemaining(fileItems::add); List<FileItem> fileContents = fileItems.stream().filter(it -> !it.isFormField()) .collect(Collectors.toList()); if (fileContents.size() > 1) { throw new ServerException("Expected no more than one file to upload"); }//from w ww . ja v a 2s.co m if (fileContents.size() < 1) { throw new ServerException("Can't find file for upload"); } FileItem content = fileContents.iterator().next(); InputStream inputStream; try { inputStream = content.getInputStream(); } catch (IOException e) { throw new ServerException(e); } Optional<String> name = fileItems.stream().filter(FileItem::isFormField) .filter(it -> "name".equals(it.getFieldName())).map(FileItem::getString).map(String::trim) .filter(Objects::nonNull).filter(it -> !it.isEmpty()).findAny(); Optional<Boolean> overwrite = fileItems.stream().filter(FileItem::isFormField) .filter(it -> "overwrite".equals(it.getFieldName())).map(FileItem::getString).map(String::trim) .map(Boolean::parseBoolean).findAny(); return new FileItemParsed() { @Override public String getName() { return name.orElse(content.getName()); } @Override public InputStream getContent() { return inputStream; } @Override public boolean getOverwrite() { return overwrite.orElse(false); } }; }
From source file:org.eclipse.che.api.project.server.impl.FileItemUtils.java
static FileItemParsed parseDir(Iterator<FileItem> iterator) throws ServerException { List<FileItem> fileItems = new LinkedList<>(); iterator.forEachRemaining(fileItems::add); List<FileItem> fileContents = fileItems.stream().filter(it -> !it.isFormField()) .collect(Collectors.toList()); if (fileContents.size() > 1) { throw new ServerException("Expected no more than one file to upload"); }/* ww w . j a va 2 s . c om*/ if (fileContents.size() < 1) { throw new ServerException("Can't find file for upload"); } FileItem content = fileContents.iterator().next(); InputStream inputStream; try { inputStream = content.getInputStream(); } catch (IOException e) { throw new ServerException(e); } return new FileItemParsed() { @Override public String getName() { throw new UnsupportedOperationException("Not supported for directories"); } @Override public InputStream getContent() { return inputStream; } @Override public boolean getOverwrite() { throw new UnsupportedOperationException("Not supported for directories"); } }; }
From source file:org.jaqpot.core.service.data.ReportService.java
public void report2PDF(Report report, OutputStream os) { Document document = new Document(); document.setPageSize(PageSize.A4);/* w ww . j av a 2 s. c o m*/ document.setMargins(50, 45, 80, 40); document.setMarginMirroring(false); try { PdfWriter writer = PdfWriter.getInstance(document, os); TableHeader event = new TableHeader(); writer.setPageEvent(event); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } document.open(); /** setup fonts for pdf */ Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC); Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC); Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); /** print link to jaqpot*/ Chunk chunk = new Chunk( "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage", ffont); chunk.setAnchor("http://www.jaqpot.org"); Paragraph paragraph = new Paragraph(chunk); paragraph.add(Chunk.NEWLINE); Chapter chapter = new Chapter(paragraph, 1); chapter.setNumberDepth(0); /** get title */ String title = null; if (report.getMeta() != null && report.getMeta().getTitles() != null && !report.getMeta().getTitles().isEmpty()) title = report.getMeta().getTitles().iterator().next(); /** print title aligned centered in page */ if (title == null) title = "Report"; chunk = new Chunk(title, chapterFont); paragraph = new Paragraph(chunk); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); chapter.add(paragraph); /** report Description */ if (report.getMeta() != null && report.getMeta().getDescriptions() != null && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { paragraph = new Paragraph(); paragraph.add(new Chunk("Description: ", paragraphFontBold)); paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"), paragraphFont)); chapter.add(paragraph); chapter.add(Chunk.NEWLINE); } /** report model, algorithm and/or dataset id */ if (report.getMeta() != null && report.getMeta().getHasSources() != null && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty() && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) { Iterator<String> sources = report.getMeta().getHasSources().iterator(); sources.forEachRemaining(o -> { if (o != null) { String[] source = o.split("/"); if (source[source.length - 2].trim().equals("model") || source[source.length - 2].trim().equals("algorithm") || source[source.length - 2].trim().equals("dataset")) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase() + source[source.length - 2].substring(1) + ": ", paragraphFontBold)); paragraph1.add(new Chunk(source[source.length - 1], paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } } }); } /** report single calculations */ report.getSingleCalculations().forEach((key, value) -> { Paragraph paragraph1 = new Paragraph(); paragraph1 = new Paragraph(); paragraph1.add(new Chunk(key + ": ", paragraphFontBold)); paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); }); /** report date of completion */ if (report.getMeta() != null && report.getMeta().getDate() != null) { Paragraph paragraph1 = new Paragraph(); paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold)); paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont)); chapter.add(paragraph1); chapter.add(Chunk.NEWLINE); } try { document.add(chapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } Integer chapterNumber = 0; /** report all_data */ for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) { String label = entry.getKey(); ArrayCalculation ac = entry.getValue(); PdfPTable table = new PdfPTable(ac.getColNames().size() + 1); for (Entry<String, List<Object>> row : ac.getValues().entrySet()) { try { XMLWorkerHelper.getInstance().parseXHtml(w -> { if (w instanceof WritableElement) { List<Element> elements = ((WritableElement) w).elements(); for (Element element : elements) { PdfPCell pdfCell = new PdfPCell(); pdfCell.addElement(element); table.addCell(pdfCell); } } }, new StringReader(row.getKey())); } catch (IOException e) { e.printStackTrace(); } for (Object o : row.getValue()) { table.addCell(o.toString()); } table.completeRow(); } try { Chunk tableChunk = new Chunk(label, tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(Chunk.NEWLINE); tableChapter.add(table); document.newPage(); document.add(tableChapter); } catch (DocumentException ex) { throw new InternalServerErrorException(ex); } } /** report plots */ for (Entry<String, String> entry : report.getFigures().entrySet()) { try { byte[] valueDecoded = Base64.decodeBase64(entry.getValue()); Image l = Image.getInstance(valueDecoded); document.newPage(); //image starts at the half's half of pdf page l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2)); l.scaleToFit(document.getPageSize()); Chunk tableChunk = new Chunk(entry.getKey(), tableFont); Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber); tableChapter.add(l); document.add(tableChapter); } catch (IOException | DocumentException e) { e.printStackTrace(); } } document.close(); }
From source file:org.jboss.prod.jardif.JarDif.java
private void compare(Path maven, Path gradle) { System.out.println("==============================================="); System.out.println(maven + " vs " + gradle); System.out.println("==============================================="); Path gradleDir = new File(workDir, "gradle-" + gradle.getFileName().toString()).toPath(); Path mvnDir = new File(workDir, "maven-" + maven.getFileName().toString()).toPath(); ZipUtils.unzip(maven, mvnDir);/* ww w . ja v a 2s .c o m*/ ZipUtils.unzip(gradle, gradleDir); List<String> mvnContents = OSUtils.runCommandIn("find . -type f", mvnDir); mvnContents.sort(Comparator.comparingInt(String::hashCode)); List<String> gradleContents = OSUtils.runCommandIn("find . -type f", gradleDir); gradleContents.sort(Comparator.comparingInt(String::hashCode)); Iterator<String> mvnFiles = mvnContents.stream().iterator(); Iterator<String> gradleFiles = gradleContents.stream().iterator(); if (!mvnFiles.hasNext() || !gradleFiles.hasNext()) { throw new IllegalStateException("One of the jars: " + maven + ", " + gradle + " is empty! Exitting"); } String mvnFile = mvnFiles.next(); String gradleFile = gradleFiles.next(); while (mvnFiles.hasNext() && gradleFiles.hasNext()) { if (mvnFile.equals(gradleFile)) { compareFiles(new File(mvnDir.toFile(), mvnFile), new File(gradleDir.toFile(), gradleFile)); mvnFile = mvnFiles.next(); gradleFile = gradleFiles.next(); } else if (mvnFile.hashCode() < gradleFile.hashCode()) { System.out.println("+" + mvnFile); mvnFile = mvnFiles.next(); } else { System.out.println("-" + gradleFile); gradleFile = gradleFiles.next(); } } mvnFiles.forEachRemaining(e -> System.out.println("+" + e)); gradleFiles.forEachRemaining(e -> System.out.println("-" + e)); System.out.println(); System.out.println(); }
From source file:org.matonto.catalog.impl.SimpleCatalogManager.java
@Override public List<Resource> getCommitChain(Resource commitId) throws MatOntoException { List<Resource> results = new ArrayList<>(); if (resourceExists(commitId, Commit.TYPE)) { try (RepositoryConnection conn = repository.getConnection()) { Iterator<Value> commits = getCommitChainIterator(commitId, conn); commits.forEachRemaining(commit -> results.add((Resource) commit)); return results; } catch (RepositoryException e) { throw new MatOntoException("Error in repository connection", e); }/*from ww w . j a va 2s . co m*/ } return results; }
From source file:org.matonto.catalog.impl.SimpleCatalogManager.java
/** * Builds the Model based on the provided Iterator and Resource. * * @param iterator The Iterator of commits which are supposed to be contained in the Model. * @param conn The RepositoryConnection which contains the requested Commits. * @return The Model containing the summation of all the Commits statements. */// w w w .ja v a 2 s . c om private Model createModelFromIterator(Iterator<Value> iterator, RepositoryConnection conn) { Model model = mf.createModel(); iterator.forEachRemaining(value -> addRevisionStatementsToModel(model, (Resource) value, conn)); return model; }
From source file:org.mskcc.shenkers.data.interval.GIntervalTree.java
public void remove(String chr, int start, int end, Strand strand) { Iterator<Node> queryNodes = queryNodes(chr, start, end, strand); queryNodes.forEachRemaining(n -> { if (start == n.getStart() && end == n.getEnd()) { queryNodes.remove();/*w w w . j ava 2 s. c o m*/ } }); }
From source file:org.sonar.scanner.config.DefaultConfiguration.java
/** * In most cases we expect a single record. <br>Having multiple records means the input value was splitted over multiple lines (this is common in Maven). * For example:/*from ww w.j a v a 2 s. c o m*/ * <pre> * <sonar.exclusions> * src/foo, * src/bar, * src/biz * <sonar.exclusions> * </pre> * In this case records will be merged to form a single list of items. Last item of a record is appended to first item of next record. * <p> * This is a very curious case, but we try to preserve line break in the middle of an item: * <pre> * <sonar.exclusions> * a * b, * c * <sonar.exclusions> * </pre> * will produce ['a\nb', 'c'] */ private static void processRecords(List<String> result, List<CSVRecord> records) { for (CSVRecord csvRecord : records) { Iterator<String> it = csvRecord.iterator(); if (!result.isEmpty()) { String next = it.next(); if (!next.isEmpty()) { int lastItemIdx = result.size() - 1; String previous = result.get(lastItemIdx); if (previous.isEmpty()) { result.set(lastItemIdx, next); } else { result.set(lastItemIdx, previous + "\n" + next); } } } it.forEachRemaining(result::add); } }
From source file:org.sonatype.nexus.tasklog.TaskLogCleanup.java
void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { // we are forgiving if the task logs home is not defined. Just log a message with a call to action. log.warn(/* w ww . ja v a2 s .c o m*/ "Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { // NOSONAR log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } }); }