Example usage for javax.servlet.jsp JspWriter write

List of usage examples for javax.servlet.jsp JspWriter write

Introduction

In this page you can find the example usage for javax.servlet.jsp JspWriter write.

Prototype

public abstract void write(char cbuf[], int off, int len) throws IOException;

Source Link

Document

Writes a portion of an array of characters.

Usage

From source file:dk.netarkivet.common.utils.StreamUtils.java

/**
 * Will copy everything from input stream to jsp writer, closing input
 * stream afterwards. Charset UTF-8 is assumed.
 *
 * @param in  Inputstream to copy from//from   w w w . j  a va  2  s  .  c  o  m
 * @param out JspWriter to copy to
 * @throws ArgumentNotValid if either parameter is null
 * @throws IOFailure if a read or write error happens during copy
 */
public static void copyInputStreamToJspWriter(InputStream in, JspWriter out) {
    ArgumentNotValid.checkNotNull(in, "InputStream in");
    ArgumentNotValid.checkNotNull(out, "JspWriter out");

    byte[] buf = new byte[Constants.IO_BUFFER_SIZE];
    int read = 0;
    try {
        try {
            while ((read = in.read(buf)) != -1) {
                out.write(new String(buf, UTF8_CHARSET), 0, read);
            }
        } finally {
            in.close();
        }
    } catch (IOException e) {
        String errMsg = "Trouble copying inputstream " + in + " to JspWriter " + out;
        log.warn(errMsg, e);
        throw new IOFailure(errMsg, e);
    }
}