Search in sources :

Example 16 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class TestFile method copyFrom.

public void copyFrom(final URL resource) {
    final TestFile testFile = this;
    RetryUtil.retry(new Closure(null, null) {

        @SuppressWarnings("UnusedDeclaration")
        void doCall() {
            try {
                FileUtils.copyURLToFile(resource, testFile);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
}
Also used : Closure(groovy.lang.Closure) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException)

Example 17 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultManifest method read.

private void read(Object manifestPath) {
    File manifestFile = fileResolver.resolve(manifestPath);
    try {
        byte[] manifestBytes = FileUtils.readFileToByteArray(manifestFile);
        manifestBytes = prepareManifestBytesForInteroperability(manifestBytes);
        // Eventually convert manifest content to UTF-8 before handing it to java.util.jar.Manifest
        if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = new String(manifestBytes, contentCharset).getBytes(DEFAULT_CONTENT_CHARSET);
        }
        // Effectively read the manifest
        Manifest javaManifest = new Manifest(new ByteArrayInputStream(manifestBytes));
        addJavaManifestToAttributes(javaManifest);
        addJavaManifestToSections(javaManifest);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 18 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultManifest method writeTo.

@Override
public org.gradle.api.java.archives.Manifest writeTo(Object path) {
    File manifestFile = fileResolver.resolve(path);
    try {
        File parentFile = manifestFile.getParentFile();
        if (parentFile != null) {
            FileUtils.forceMkdir(parentFile);
        }
        IoActions.withResource(new FileOutputStream(manifestFile), new Action<FileOutputStream>() {

            @Override
            public void execute(FileOutputStream fileOutputStream) {
                writeTo(fileOutputStream);
            }
        });
        return this;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 19 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultManifest method writeTo.

static void writeTo(org.gradle.api.java.archives.Manifest manifest, OutputStream outputStream, String contentCharset) {
    try {
        Manifest javaManifest = generateJavaManifest(manifest.getEffectiveManifest());
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        javaManifest.write(buffer);
        byte[] manifestBytes;
        if (DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = buffer.toByteArray();
        } else {
            // Convert the UTF-8 manifest bytes to the requested content charset
            manifestBytes = buffer.toString(DEFAULT_CONTENT_CHARSET).getBytes(contentCharset);
        }
        outputStream.write(manifestBytes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Manifest(java.util.jar.Manifest)

Example 20 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultManifest method writeTo.

@Deprecated
@Override
public DefaultManifest writeTo(Writer writer) {
    SingleMessageLogger.nagUserOfDeprecated("Manifest.writeTo(Writer)", "Please use Manifest.writeTo(Object) instead");
    try {
        Manifest javaManifest = generateJavaManifest(getEffectiveManifest());
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        javaManifest.write(buffer);
        String manifestContent = buffer.toString(DEFAULT_CONTENT_CHARSET);
        if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            // Convert the UTF-8 manifest bytes to the requested content charset
            manifestContent = new String(manifestContent.getBytes(contentCharset), contentCharset);
        }
        writer.write(manifestContent);
        writer.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return this;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Manifest(java.util.jar.Manifest)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)82 IOException (java.io.IOException)60 File (java.io.File)25 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 FileOutputStream (java.io.FileOutputStream)5 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Manifest (java.util.jar.Manifest)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 FileVisitor (org.gradle.api.file.FileVisitor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileReader (java.io.FileReader)3 URISyntaxException (java.net.URISyntaxException)3 Matcher (java.util.regex.Matcher)3 ZipEntry (java.util.zip.ZipEntry)3