本文整理汇总了Java中org.apache.tools.ant.types.Resource.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getInputStream方法的具体用法?Java Resource.getInputStream怎么用?Java Resource.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.types.Resource
的用法示例。
在下文中一共展示了Resource.getInputStream方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputStream
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Return an InputStream for reading the contents of this Resource.
* @return an InputStream object.
* @throws IOException if the tar file cannot be opened,
* or the entry cannot be read.
*/
@Override
public InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
}
Resource archive = getArchive();
final TarInputStream i = new TarInputStream(archive.getInputStream());
TarEntry te;
while ((te = i.getNextEntry()) != null) {
if (te.getName().equals(getName())) {
return i;
}
}
FileUtils.close(i);
throw new BuildException("no entry " + getName() + " in "
+ getArchive());
}
示例2: fetchEntry
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* fetches information from the named entry inside the archive.
*/
@Override
protected void fetchEntry() {
Resource archive = getArchive();
try (TarInputStream i = new TarInputStream(archive.getInputStream())) {
TarEntry te = null;
while ((te = i.getNextEntry()) != null) {
if (te.getName().equals(getName())) {
setEntry(te);
return;
}
}
} catch (IOException e) {
log(e.getMessage(), Project.MSG_DEBUG);
throw new BuildException(e);
}
setEntry(null);
}
示例3: expandResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* This method is to be overridden by extending unarchival tasks.
*
* @param srcR the source resource
* @param dir the destination directory
* @since Ant 1.7
*/
@Override
protected void expandResource(Resource srcR, File dir) {
if (!srcR.isExists()) {
throw new BuildException("Unable to untar "
+ srcR.getName()
+ " as the it does not exist",
getLocation());
}
try (InputStream i = srcR.getInputStream()) {
expandStream(srcR.getName(), i, dir);
} catch (IOException ioe) {
throw new BuildException("Error while expanding " + srcR.getName(),
ioe, getLocation());
}
}
示例4: textCompare
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Text compares the contents of two Resources.
* Ignores different kinds of line endings.
* @param r1 the Resource whose content is to be compared.
* @param r2 the other Resource whose content is to be compared.
* @return a negative integer, zero, or a positive integer as the first
* argument is less than, equal to, or greater than the second.
* @throws IOException if the Resources cannot be read.
* @since Ant 1.7
*/
private static int textCompare(final Resource r1, final Resource r2) throws IOException {
try (BufferedReader in1 =
new BufferedReader(new InputStreamReader(r1.getInputStream()));
BufferedReader in2 = new BufferedReader(
new InputStreamReader(r2.getInputStream()))) {
String expected = in1.readLine();
while (expected != null) {
final String actual = in2.readLine();
if (!expected.equals(actual)) {
if (actual == null) {
return 1;
}
return expected.compareTo(actual);
}
expected = in1.readLine();
}
return in2.readLine() == null ? 0 : -1; //NOSONAR
}
}
示例5: copyUsingStreams
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
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);
}
}
示例6: nextResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private void nextResource() throws IOException {
closeCurrent();
while (iter.hasNext()) {
Resource r = iter.next();
if (!r.isExists()) {
continue;
}
log("Concatenating " + r.toLongString(), Project.MSG_VERBOSE);
try {
currentStream = new BufferedInputStream(r.getInputStream());
return;
} catch (IOException eyeOhEx) {
if (!ignoreErrors) {
log("Failed to get input stream for " + r, Project.MSG_ERR);
throw eyeOhEx;
}
}
}
eof = true;
}
示例7: getProperties
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Returns properties from a specified properties file.
*
* @param resource The resource to load properties from.
*/
private Properties getProperties(Resource resource) {
InputStream in = null;
Properties props = new Properties();
try {
in = resource.getInputStream();
props.load(in);
} catch (IOException ioe) {
if (getProject() != null) {
getProject().log("getProperties failed, " + ioe.getMessage(), Project.MSG_ERR);
} else {
ioe.printStackTrace(); //NOSONAR
}
} finally {
FileUtils.close(in);
}
return props;
}
示例8: addResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Add a file entry.
*/
private void addResource(final Resource r, final String name, final String prefix,
final ZipOutputStream zOut, final int mode,
final ZipFile zf, final File fromArchive)
throws IOException {
if (zf != null) {
final ZipEntry ze = zf.getEntry(r.getName());
if (ze != null) {
final boolean oldCompress = doCompress;
if (keepCompression) {
doCompress = (ze.getMethod() == ZipEntry.DEFLATED);
}
try (final BufferedInputStream is = new BufferedInputStream(zf.getInputStream(ze))) {
zipFile(is, zOut, prefix + name, ze.getTime(),
fromArchive, mode, ze.getExtraFields(true));
} finally {
doCompress = oldCompress;
}
}
} else {
try (final BufferedInputStream is = new BufferedInputStream(r.getInputStream())) {
zipFile(is, zOut, prefix + name, r.getLastModified(),
fromArchive, mode, r instanceof ZipResource
? ((ZipResource) r).getExtraFields() : null);
}
}
}
示例9: getReader
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
@Override
public Reader getReader(Resource o) throws IOException {
InputStream is = o.getInputStream();
return new BufferedReader(encoding == null
? new InputStreamReader(is)
: new InputStreamReader(is, encoding));
}
示例10: getProperties
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Load a properties resource.
* @param propertyResource the resource to load the properties from.
* @return loaded <code>Properties</code> object.
* @throws BuildException if the resource could not be found or read.
* @since Ant 1.8.0
*/
public Properties getProperties(Resource propertyResource)
throws BuildException {
Properties props = new Properties();
try (
InputStream
in = propertyResource.getInputStream()){
props.load(in);
} catch (IOException e) {
throw new BuildException("Property resource (%s) cannot be loaded.",
propertyResource.getName());
}
return props;
}
示例11: zipResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* zip a resource to an output stream
* @param resource the resource to zip
* @param zOut the output stream
* @throws IOException on error
*/
protected void zipResource(Resource resource, OutputStream zOut)
throws IOException {
try (InputStream rIn = resource.getInputStream()) {
zipFile(rIn, zOut);
}
}
示例12: isSelected
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* The heart of the matter. This is where the selector gets to decide
* on the inclusion of a Resource.
*
* @param r the Resource to check.
* @return whether the Resource is selected.
*/
public boolean isSelected(Resource r) {
// throw BuildException on error
validate();
if (r.isDirectory() || contains.isEmpty()) {
return true;
}
String userstr = contains;
if (!casesensitive) {
userstr = contains.toLowerCase();
}
if (ignorewhitespace) {
userstr = SelectorUtils.removeWhitespace(userstr);
}
try (BufferedReader in = new BufferedReader(
new InputStreamReader(r.getInputStream(), encoding == null
? Charset.defaultCharset() : Charset.forName(encoding)))) {
try {
String teststr = in.readLine();
while (teststr != null) {
if (!casesensitive) {
teststr = teststr.toLowerCase();
}
if (ignorewhitespace) {
teststr = SelectorUtils.removeWhitespace(teststr);
}
if (teststr.indexOf(userstr) > -1) {
return true;
}
teststr = in.readLine();
}
return false;
} catch (IOException ioe) {
throw new BuildException("Could not read " + r.toLongString());
}
} catch (IOException e) {
throw new BuildException(
"Could not get InputStream from " + r.toLongString(), e);
}
}
示例13: binaryCompare
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Binary compares the contents of two Resources.
* <p>
* simple but sub-optimal comparison algorithm. written for working
* rather than fast. Better would be a block read into buffers followed
* by long comparisons apart from the final 1-7 bytes.
* </p>
*
* @param r1 the Resource whose content is to be compared.
* @param r2 the other Resource whose content is to be compared.
* @return a negative integer, zero, or a positive integer as the first
* argument is less than, equal to, or greater than the second.
* @throws IOException if the Resources cannot be read.
* @since Ant 1.7
*/
private static int binaryCompare(final Resource r1, final Resource r2) throws IOException {
try (InputStream in1 = new BufferedInputStream(r1.getInputStream());
InputStream in2 =
new BufferedInputStream(r2.getInputStream())) {
for (int b1 = in1.read(); b1 != -1; b1 = in1.read()) {
final int b2 = in2.read();
if (b1 != b2) {
return b1 > b2 ? 1 : -1;
}
}
return in2.read() == -1 ? 0 : -1;
}
}