// Path: http-builder-ng-core/src/main/java/groovyx/net/http/TransportingException.java
// public class TransportingException extends RuntimeException {
// 
//     public TransportingException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
//     public TransportingException(final Throwable cause) {
//         super(cause);
//     }
// }


import groovyx.net.http.TransportingException;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
    public static String copyAsString(final BufferedInputStream inputStream) throws IOException, IllegalStateException {
        if (inputStream == null) return null;

        try {
            inputStream.mark(Integer.MAX_VALUE);
            return new String(streamToBytes(inputStream, false));
        } finally {
            try {
                inputStream.reset();
            } catch (IOException ioe) {
                throw new IllegalStateException("Unable to reset stream - original stream content may be corrupted");
            }
        }
    }

    /**
     * Transfers the contents of the {@link InputStream} into the {@link OutputStream}, optionally closing the stream.
     *
     * @param istream the input stream
     * @param ostream the output stream
     * @param close   whether or not to close the output stream
     */
    public static void transfer(final InputStream istream, final OutputStream ostream, final boolean close) {
        try {
            final byte[] bytes = new byte[2_048];
            int read;
            while ((read = istream.read(bytes)) != -1) {
                ostream.write(bytes, 0, read);
            }
        } catch (IOException e) {
// Path: http-builder-ng-core/src/main/java/groovyx/net/http/TransportingException.java
// public class TransportingException extends RuntimeException {
// 
//     public TransportingException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
//     public TransportingException(final Throwable cause) {
//         super(cause);
//     }
// }


// Path: http-builder-ng-core/src/main/java/groovyx/net/http/util/IoUtils.java
import groovyx.net.http.TransportingException;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

    public static String copyAsString(final BufferedInputStream inputStream) throws IOException, IllegalStateException {
        if (inputStream == null) return null;

        try {
            inputStream.mark(Integer.MAX_VALUE);
            return new String(streamToBytes(inputStream, false));
        } finally {
            try {
                inputStream.reset();
            } catch (IOException ioe) {
                throw new IllegalStateException("Unable to reset stream - original stream content may be corrupted");
            }
        }
    }

    /**
     * Transfers the contents of the {@link InputStream} into the {@link OutputStream}, optionally closing the stream.
     *
     * @param istream the input stream
     * @param ostream the output stream
     * @param close   whether or not to close the output stream
     */
    public static void transfer(final InputStream istream, final OutputStream ostream, final boolean close) {
        try {
            final byte[] bytes = new byte[2_048];
            int read;
            while ((read = istream.read(bytes)) != -1) {
                ostream.write(bytes, 0, read);
            }
        } catch (IOException e) {
            throw new TransportingException(e);