⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringservletoutputstream.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
/* *                                   ____. *                       __/\ ______|    |__/\.     _______ *            __   .____|    |       \   |    +----+       \ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________ *   \\______: :---|    :    :           |    :    |         \________> *           |__\---\_____________:______:    :____|____:_____\ *                                      /_____| * *              . . . i n   j a h i a   w e   t r u s t . . . * * * * ----- BEGIN LICENSE BLOCK ----- * Version: JCSL 1.0 * * The contents of this file are subject to the Jahia Community Source License * 1.0 or later (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.jahia.org/license * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the rights, obligations and limitations governing use of the contents * of the file. The Original and Upgraded Code is the Jahia CMS and Portal * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA * Ltd. owns the copyrights in the portions it created. All Rights Reserved. * * The Shared Modifications are Jahia View Helper. * * The Developer of the Shared Modifications is Jahia Solution S�rl. * Portions created by the Initial Developer are Copyright (C) 2002 by the * Initial Developer. All Rights Reserved. * * Contributor(s): * 22-AUG-2003, Jahia Solutions Sarl, Fulco Houkes * * ----- END LICENSE BLOCK ----- */package org.jahia.services.applications;import org.jahia.utils.JahiaConsole;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import javax.servlet.ServletOutputStream;/** * A simple ServletOutputStream based class that writes to a String and * simultaneously to an output stream if configured. * * Note : none of this is supposed to be optimised in anyway, it was done a * quick and dirty wayusing mostly already available functions calls to make * this reliable. * * @todo Test this code with Orion, WebLogic, etc... This might be very * container-sensitive code. * * @author : Serge Huber * */public class StringServletOutputStream extends ServletOutputStream {    private ByteArrayOutputStream byteArray = new ByteArrayOutputStream ();    private OutputStreamWriter streamWriter;    private ServletOutputStream existingStream;    private OutputStreamWriter existingStreamWriter;    private String encoding;    public StringServletOutputStream (String encoding) throws UnsupportedEncodingException {        super ();        this.encoding = encoding;        streamWriter = new OutputStreamWriter (byteArray, encoding);    }    public StringServletOutputStream (ServletOutputStream existingStream, String encoding) throws UnsupportedEncodingException {        super ();        this.existingStream = existingStream;        this.encoding = encoding;        streamWriter = new OutputStreamWriter (byteArray, encoding);        existingStreamWriter = new OutputStreamWriter (existingStream, encoding);    }    /*    public void print(boolean b) {        try {            Boolean bol = new Boolean(b);            streamWriter.write(bol.toString());        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(char c) {        try {            streamWriter.write(c);        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(char[] s) {        try {            streamWriter.write(s);        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(double d) {        try {            streamWriter.write(Double.toString(d));        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(float f) {        try {            streamWriter.write(Float.toString(f));        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(int i) {        try {            streamWriter.write(i);        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(long l) {        try {            streamWriter.write(Long.toString(l));        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void print(String s) {        try {            streamWriter.write(s);        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void println() {        try {            streamWriter.write("\n");        } catch (java.io.IOException ioe) {            logger.warn (ioe);        }    }    public void println(boolean b) {        this.print(b);        this.println();    }    public void println(char c) {        this.print(c);        this.println();    }    public void println(char[] s) {        this.print(s);        this.println();    }    public void println(double d) {        this.print(d);        this.println();    }    public void println(float f) {        this.print(f);        this.println();    }    public void println(int i) {        this.print(i);        this.println();    }    public void println(long l) {        this.print(l);        this.println();    }    public void println(String x) {        this.print(x);        this.println();    }*/    public void write (char[] cbuf)            throws IOException {        streamWriter.write (cbuf, 0, cbuf.length);        if (existingStream != null) {            existingStreamWriter.write (cbuf, 0, cbuf.length);        }    }    public void write (char[] cbuf, int off, int len)            throws IOException {        streamWriter.write (cbuf, off, len);        if (existingStream != null) {            existingStreamWriter.write (cbuf, off, len);        }    }    public void write (int c)            throws IOException {        byteArray.write (c);        if (existingStream != null) {            existingStream.write (c);        }    }    public void write (String s)            throws IOException {        streamWriter.write (s);        if (existingStream != null) {            existingStreamWriter.write (s);        }    }    public void write (String str, int off, int len)            throws IOException {        streamWriter.write (str, off, len);        if (existingStream != null) {            existingStreamWriter.write (str, off, len);        }    }    public String getBuffer () throws UnsupportedEncodingException {        return byteArray.toString (encoding);    }    public void flush ()            throws IOException {        if (existingStream != null) {            JahiaConsole.println (StringServletOutputStream.class.getName (),                    "Flushing pass-through stream...");            existingStreamWriter.flush ();            existingStream.flush ();        }    }    public void close () {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -