For IntelliJ IDEA,
Android Studio or Eclipse



/** * Calls File.setLastModified(long time). Originally written to * to dynamically bind to that call on Java1.2+. * * @param file the file whose modified time is to be set * @param time the time to which the last modified time is to be set. * if this is -1, the current time is used. */ public void setFileLastModified(File file, long time) { ResourceUtils.setLastModified(new FileResource(file), time); }
private static Reader filterWith(Project project, String encoding, Vector<FilterChain> filterChains, InputStream input) { Reader r = new InputStreamReader(input, charsetFor(encoding)); if (filterChains != null && !filterChains.isEmpty()) { final ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(FileUtils.BUF_SIZE); crh.setPrimaryReader(r); crh.setFilterChains(filterChains); crh.setProject(project); r = crh.getAssembledReader(); } return new BufferedReader(r); }
private static void log(final Project project, final String message) { log(project, message, Project.MSG_VERBOSE); }
/** * Compare two Resources by content. * @param foo the first Resource. * @param bar the second Resource. * @return a negative integer, zero, or a positive integer as the first * argument is less than, equal to, or greater than the second. * @throws BuildException if I/O errors occur. * @see org.apache.tools.ant.util.ResourceUtils#compareContent(Resource, Resource, boolean) */ protected int resourceCompare(Resource foo, Resource bar) { try { return ResourceUtils.compareContent(foo, bar, !binary); } catch (IOException e) { throw new BuildException(e); } }
/** * Convenience method to copy content from one Resource to another. * No filtering is performed. * * @param source the Resource to copy from. * Must not be <code>null</code>. * @param dest the Resource to copy to. * Must not be <code>null</code>. * * @throws IOException if the copying fails. * * @since Ant 1.7 */ public static void copyResource(final Resource source, final Resource dest) throws IOException { copyResource(source, dest, null); }
/** * Convenience method to copy content from one Resource to another. * No filtering is performed. * * @param source the Resource to copy from. * Must not be <code>null</code>. * @param dest the Resource to copy to. * Must not be <code>null</code>. * @param project the project instance. * * @throws IOException if the copying fails. * * @since Ant 1.7 */ public static void copyResource(final Resource source, final Resource dest, final Project project) throws IOException { copyResource(source, dest, null, null, false, false, null, null, project); }
private static void copyUsingStreams(final Resource source, final Resource dest, final boolean append, final Project project) throws IOException { if (areSame(source, dest)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + source + " to " + dest); return; } try (InputStream in = source.getInputStream(); OutputStream out = getOutputStream(dest, append, project)) { final byte[] buffer = new byte[FileUtils.BUF_SIZE]; int count = 0; do { out.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); } }
/** * Does the work. * * @exception BuildException if something goes wrong with the build */ public void execute() throws BuildException { final String msg = "".equals(message) ? StringUtils.LINE_SEP : message; try { ResourceUtils .copyResource(new StringResource(msg), output == null ? new LogOutputResource(this, logLevel) : output, null, null, false, false, append, null, "".equals(encoding) ? null : encoding, getProject(), force); } catch (IOException ioe) { throw new BuildException(ioe, getLocation()); } }
/** * Tells which sources should be reprocessed based on the * last modification date of targets. * @param logTo where to send (more or less) interesting output. * @param source ResourceCollection. * @param mapper filename mapper indicating how to find the target Resources. * @param targets object able to map a relative path as a Resource. * @param granularity The number of milliseconds leeway to give * before deciding a target is out of date. * @return ResourceCollection. * @since Ant 1.7 */ public static ResourceCollection selectOutOfDateSources(final ProjectComponent logTo, final ResourceCollection source, final FileNameMapper mapper, final ResourceFactory targets, final long granularity) { logFuture(logTo, source, granularity); return selectSources(logTo, source, mapper, targets, sr -> target -> SelectorUtils.isOutOfDate(sr, target, granularity)); }
/** * Tells which source files should be reprocessed based on the * last modification date of target files. * @param logTo where to send (more or less) interesting output. * @param source array of resources bearing relative path and last * modification date. * @param mapper filename mapper indicating how to find the target * files. * @param targets object able to map as a resource a relative path * at <b>destination</b>. * @return array containing the source files which need to be * copied or processed, because the targets are out of date or do * not exist. */ public static Resource[] selectOutOfDateSources(final ProjectComponent logTo, final Resource[] source, final FileNameMapper mapper, final ResourceFactory targets) { return selectOutOfDateSources(logTo, source, mapper, targets, FILE_UTILS.getFileTimestampGranularity()); }
private Resource[] selectOutOfDateResources(final Resource[] initial, final FileNameMapper mapper) { final Resource[] rs = selectFileResources(initial); Resource[] result = ResourceUtils.selectOutOfDateSources(this, rs, mapper, getZipScanner(), ZIP_FILE_TIMESTAMP_GRANULARITY); if (!doFilesonly) { final Union u = new Union(); u.addAll(Arrays.asList(selectDirectoryResources(initial))); final ResourceCollection rc = ResourceUtils.selectSources(this, u, mapper, getZipScanner(), MISSING_DIR_PROVIDER); if (!rc.isEmpty()) { final List<Resource> newer = new ArrayList<>(); newer.addAll(Arrays.asList(((Union) rc).listResources())); newer.addAll(Arrays.asList(result)); result = newer.toArray(result); } } return result; }
/** * Styles all existing resources. * * @param stylesheet style sheet to use * @since Ant 1.7 */ private void processResources(final Resource stylesheet) { for (final Resource r : resources) { if (!r.isExists()) { continue; } File base = baseDir; String name = r.getName(); final FileProvider fp = r.as(FileProvider.class); if (fp != null) { final FileResource f = ResourceUtils.asFileResource(fp); base = f.getBaseDir(); if (base == null) { name = f.getFile().getAbsolutePath(); } } process(base, name, destDir, stylesheet); } }
/** * Execute the concat task. */ @Override public void execute() { validate(); if (binary && dest == null) { throw new BuildException( "dest|destfile attribute is required for binary concatenation"); } ResourceCollection c = getResources(); if (isUpToDate(c)) { log(dest + " is up-to-date.", Project.MSG_VERBOSE); return; } if (c.isEmpty() && ignoreEmpty) { return; } try { //most of these are defaulted because the concat-as-a-resource code hijacks a lot: ResourceUtils.copyResource(new ConcatResource(c), dest == null ? new LogOutputResource(this, Project.MSG_WARN) : dest, null, null, true, false, append, null, null, getProject(), force); } catch (IOException e) { throw new BuildException("error concatenating content to " + dest, e); } }
private static void copyUsingFileChannels(final File sourceFile, final File destFile, final Project project) throws IOException { if (FileUtils.getFileUtils().areSame(sourceFile, destFile)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + sourceFile + " to " + destFile); return; } final File parent = destFile.getParentFile(); if (parent != null && !parent.isDirectory() && !(parent.mkdirs() || parent.isDirectory())) { throw new IOException("failed to create the parent directory" + " for " + destFile); } try (FileChannel srcChannel = FileChannel.open(sourceFile.toPath(), StandardOpenOption.READ); FileChannel destChannel = FileChannel.open(destFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { long position = 0; final long count = srcChannel.size(); while (position < count) { final long chunk = Math.min(MAX_IO_CHUNK_SIZE, count - position); position += destChannel.transferFrom(srcChannel, position, chunk); } } }
/** * Compares the contents of two files. * * @param f1 the file whose content is to be compared. * @param f2 the other file whose content is to be compared. * @param textfile true if the file is to be treated as a text file and * differences in kind of line break are to be ignored. * * @return true if the content of the files is the same. * * @throws IOException if the files cannot be read. * @since Ant 1.6.3 */ public boolean contentEquals(File f1, File f2, boolean textfile) throws IOException { return ResourceUtils.contentEquals(new FileResource(f1), new FileResource(f2), textfile); }