/** * Construct a new ConcatResourceInputStream * for the specified ResourceCollection. * @param rc the ResourceCollection to combine. */ public ConcatResourceInputStream(ResourceCollection rc) { iter = rc.iterator(); }
if (!rc.isFilesystemOnly() && !supportsNonFileResources()) { throw new BuildException( "Only FileSystem resources are supported."); if (rc.isEmpty()) { throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE); if (rc.size() == 1) { final Resource res = rc.iterator().next(); final FileProvider r = res.as(FileProvider.class); if (file == null) {
/** * Add all resources in a resource collection to the source list. * @since Ant 1.7.1 * @param collection the resource to load * @throws BuildException if a resource cannot be read */ public void loadResources(ResourceCollection collection) { collection.forEach(this::loadResource); }
/** * Take all elements except for the last <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { int ct = getValidCount(); ResourceCollection nested = getResourceCollection(); if (ct > nested.size()) { return Collections.emptyList(); } return nested.stream().limit((long) nested.size() - ct) .collect(Collectors.toList()); }
/** * whether the given resource collection is a (subclass of) * FileSet that only contains file system resources. * @param rc the resource collection to check. * @return true if the collection is a fileset. * @since Ant 1.7 */ protected static boolean isFileFileSet(final ResourceCollection rc) { return rc instanceof FileSet && rc.isFilesystemOnly(); }
/** * Learn whether this {@link ResourceCollection} is empty. * @return boolean */ default boolean isEmpty() { return size() == 0; } }
/** * Set the source resource. * @param a the resource to load as a single element Resource collection. * @since Ant 1.7 */ public synchronized void addConfigured(ResourceCollection a) { if (src != null) { throw new BuildException("only a single source is supported"); } if (a.size() != 1) { throw new BuildException( "only single-element resource collections are supported"); } src = a.iterator().next(); }
private ResourceCollection createResourceCollection(Reference ref) { Object o = ref.getReferencedObject(); if (!(o instanceof ResourceCollection)) { throw new BuildException("Only File based ResourceCollections are supported."); } ResourceCollection rc = (ResourceCollection) o; if (!rc.isFilesystemOnly()) { throw new BuildException("Only ResourceCollections from local file system are supported."); } return rc; }
/** * Fulfill the condition contract. * @return true if the specified ResourceCollection satisfies the set criteria. * @throws BuildException if an error occurs. */ @Override public boolean eval() { if (rc == null) { throw new BuildException(ONE_NESTED_MESSAGE); } if (count == null) { throw new BuildException(COUNT_REQUIRED); } return when.evaluate(Integer.valueOf(rc.size()).compareTo(count)); }
/** * Take the last <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { int count = getValidCount(); ResourceCollection rc = getResourceCollection(); int size = rc.size(); int skip = Math.max(0, size - count); List<Resource> result = rc.stream().skip(skip).collect(Collectors.toList()); int found = result.size(); if (found == count || (size < count && found == size)) { return result; } //mismatch: String msg = String.format( "Resource collection %s reports size %d but returns %d elements.", rc, size, found + skip); //size was understated -> too many results; warn and continue: if (found > count) { log(msg, Project.MSG_WARN); return result.subList(found - count, found); } //size was overstated; we missed some and are now in error-land: throw new BuildException(msg); }
@Override public boolean hasNext() { boolean result = ri != null && ri.hasNext(); while (!result && rci.hasNext()) { ri = rci.next().iterator(); result = ri.hasNext(); } return result; } @Override
/** * Set the source resource. * @param a the resource to pack as a single element Resource collection. */ public void addConfigured(ResourceCollection a) { if (a.size() != 1) { throw new BuildException( "only single argument resource collections are supported as archives"); } setSrcResource(a.iterator().next()); }
/** * Sets the archive that holds this as a single element Resource * collection. * @param a the archive as a single element Resource collection. */ public void addConfigured(ResourceCollection a) { super.addConfigured(a); if (!a.isFilesystemOnly()) { throw new BuildException("only filesystem resources are supported"); } }
/** * Return a {@link Stream} over this {@link ResourceCollection}. * @return {@link Stream} of {@link Resource} * @since Ant 1.10.2 */ default Stream<? extends Resource> stream() { final Stream.Builder<Resource> b = Stream.builder(); forEach(b); return b.build(); }
private Resource getXest(ResourceCollection rc, ResourceComparator c) { return StreamUtils.iteratorAsStream(rc.iterator()).max(c).orElse(null); }
private ResourceCollection createResourceCollection(Reference ref) { Object o = ref.getReferencedObject(); if (!(o instanceof ResourceCollection)) { throw new BuildException("Only File based ResourceCollections are supported."); } ResourceCollection rc = (ResourceCollection) o; if (!rc.isFilesystemOnly()) { throw new BuildException("Only ResourceCollections from local file system are supported."); } return rc; }
/** * Efficient size implementation. * @return int size */ @Override public synchronized int size() { return Math.min(getResourceCollection().size(), getValidCount()); }