Search in sources :

Example 61 with UncheckedIOException

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

the class GeneratePluginDescriptors method writePropertiesTo.

private void writePropertiesTo(Properties properties, File descriptorFile) {
    try {
        OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(descriptorFile));
        GUtil.savePropertiesNoDateComment(properties, outputStream);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 62 with UncheckedIOException

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

the class NestedModelRuleDescriptor method describeTo.

@Override
public void describeTo(Appendable appendable) {
    parent.describeTo(appendable);
    try {
        appendable.append(" > ");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    child.describeTo(appendable);
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 63 with UncheckedIOException

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

the class SimpleHttpFileServerFactory method start.

public HttpFileServer start(File contentRoot, int port) {
    Container container = new SimpleFileServerContainer(new FileContext(contentRoot));
    try {
        final Server server = new ContainerServer(container);
        Connection connection = new SocketConnection(server);
        InetSocketAddress address = new InetSocketAddress(port);
        InetSocketAddress usedAddress = (InetSocketAddress) connection.connect(address);
        return new SimpleHttpFileServer(contentRoot, usedAddress.getPort(), new Stoppable() {

            public void stop() {
                try {
                    server.stop();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) ContainerServer(org.simpleframework.http.core.ContainerServer) Container(org.simpleframework.http.core.Container) SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) Server(org.simpleframework.transport.Server) HttpFileServer(org.gradle.plugins.javascript.envjs.http.HttpFileServer) ContainerServer(org.simpleframework.http.core.ContainerServer) SocketConnection(org.simpleframework.transport.connect.SocketConnection) InetSocketAddress(java.net.InetSocketAddress) Connection(org.simpleframework.transport.connect.Connection) SocketConnection(org.simpleframework.transport.connect.SocketConnection) Stoppable(org.gradle.internal.concurrent.Stoppable) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) FileContext(org.simpleframework.http.resource.FileContext)

Example 64 with UncheckedIOException

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

the class SimpleFileServerContainer method handle.

public void handle(Request req, Response resp) {
    Index requestIndex = context.getIndex(req.getTarget());
    File targetFile = requestIndex.getFile();
    if (!targetFile.exists()) {
        resp.setCode(404);
        resp.setText("Not Found");
        try {
            resp.getPrintStream().println(String.format("File '%s' does not exist", targetFile.getAbsolutePath()));
            resp.commit();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    String contentType = requestIndex.getContentType();
    resp.set("Content-Type", contentType);
    OutputStream output = null;
    try {
        output = resp.getOutputStream();
        if (contentType.startsWith("text/")) {
            resp.set("Content-Encoding", Charset.defaultCharset().name());
            Reader input = new FileReader(requestIndex.getFile());
            IOUtils.copy(input, output);
            IOUtils.closeQuietly(input);
        } else {
            InputStream input = new FileInputStream(requestIndex.getFile());
            IOUtils.copy(input, output);
            IOUtils.closeQuietly(input);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        IOUtils.closeQuietly(output);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Reader(java.io.Reader) FileReader(java.io.FileReader) Index(org.simpleframework.http.resource.Index) UncheckedIOException(org.gradle.api.UncheckedIOException) FileReader(java.io.FileReader) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 65 with UncheckedIOException

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

the class OutputScrapingExecutionResult method normalize.

public static String normalize(String output) {
    StringBuilder result = new StringBuilder();
    List<String> lines;
    try {
        lines = CharSource.wrap(output).readLines();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    int i = 0;
    while (i < lines.size()) {
        String line = lines.get(i);
        if (line.contains(DaemonStartupMessage.STARTING_DAEMON_MESSAGE)) {
            // Remove the "daemon starting" message
            i++;
        } else if (line.contains(DaemonStateCoordinator.DAEMON_WILL_STOP_MESSAGE)) {
            // Remove the "Daemon will be shut down" message
            i++;
        } else if (i == lines.size() - 1 && line.matches("Total time: [\\d\\.]+ secs")) {
            result.append("Total time: 1 secs");
            result.append('\n');
            i++;
        } else {
            result.append(line);
            result.append('\n');
            i++;
        }
    }
    return result.toString();
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)101 IOException (java.io.IOException)79 File (java.io.File)32 InputStream (java.io.InputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 FileInputStream (java.io.FileInputStream)5 Matcher (java.util.regex.Matcher)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileReader (java.io.FileReader)3