001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.servlet.filters.gzip;
016    
017    import java.io.IOException;
018    import java.io.OutputStream;
019    
020    import java.util.zip.GZIPOutputStream;
021    
022    import javax.servlet.ServletOutputStream;
023    
024    /**
025     * @author Shuyang Zhou
026     */
027    public class GZipServletOutputStream extends ServletOutputStream {
028    
029            public GZipServletOutputStream(OutputStream outputStream)
030                    throws IOException {
031    
032                    _gZipOutputStream = new GZIPOutputStream(outputStream);
033            }
034    
035            public void close() throws IOException {
036                    _gZipOutputStream.close();
037            }
038    
039            public void flush() throws IOException {
040                    _gZipOutputStream.flush();
041            }
042    
043            public void write(byte[] byteArray) throws IOException {
044                    _gZipOutputStream.write(byteArray);
045            }
046    
047            public void write(byte[] byteArray, int offset, int length)
048                    throws IOException {
049    
050                    _gZipOutputStream.write(byteArray, offset, length);
051            }
052    
053            public void write(int b) throws IOException {
054                    _gZipOutputStream.write(b);
055            }
056    
057            private GZIPOutputStream _gZipOutputStream;
058    
059    }