Search in sources :

Example 1 with ExternalResourceWriteResult

use of org.gradle.internal.resource.ExternalResourceWriteResult in project gradle by gradle.

the class LocalFileStandInExternalResource method put.

@Override
public ExternalResourceWriteResult put(ReadableContent location) {
    try {
        if (!localFile.canWrite()) {
            localFile.delete();
        }
        Files.createParentDirs(localFile);
        InputStream input = location.open();
        try {
            CountingOutputStream output = new CountingOutputStream(new FileOutputStream(localFile));
            try {
                IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            return new ExternalResourceWriteResult(output.getCount());
        } finally {
            input.close();
        }
    } catch (IOException e) {
        throw ResourceExceptions.putFailed(getURI(), e);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CountingInputStream(com.google.common.io.CountingInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ExternalResourceWriteResult(org.gradle.internal.resource.ExternalResourceWriteResult)

Example 2 with ExternalResourceWriteResult

use of org.gradle.internal.resource.ExternalResourceWriteResult in project MyLuaApp-Build-Core by dingyi222666.

the class LocalFileStandInExternalResource method put.

@Override
public ExternalResourceWriteResult put(ReadableContent location) {
    try {
        if (!localFile.canWrite()) {
            localFile.delete();
        }
        Files.createParentDirs(localFile);
        InputStream input = location.open();
        try {
            CountingOutputStream output = new CountingOutputStream(new FileOutputStream(localFile));
            try {
                IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            return new ExternalResourceWriteResult(output.getCount());
        } finally {
            input.close();
        }
    } catch (IOException e) {
        throw ResourceExceptions.putFailed(getURI(), e);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CountingInputStream(com.google.common.io.CountingInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ExternalResourceWriteResult(org.gradle.internal.resource.ExternalResourceWriteResult)

Aggregations

CountingInputStream (com.google.common.io.CountingInputStream)2 CountingOutputStream (com.google.common.io.CountingOutputStream)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ExternalResourceWriteResult (org.gradle.internal.resource.ExternalResourceWriteResult)2