001    /**
002     * Copyright (c) 2000-present 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.kernel.io.unsync;
016    
017    import java.io.IOException;
018    import java.io.OutputStream;
019    
020    /**
021     * <p>
022     * See https://issues.liferay.com/browse/LPS-6648.
023     * </p>
024     *
025     * @author Shuyang Zhou
026     */
027    public class UnsyncFilterOutputStream extends OutputStream {
028    
029            public UnsyncFilterOutputStream(OutputStream outputStream) {
030                    this.outputStream = outputStream;
031            }
032    
033            @Override
034            public void close() throws IOException {
035                    try (OutputStream os = outputStream) {
036                            flush();
037                    }
038            }
039    
040            @Override
041            public void flush() throws IOException {
042                    outputStream.flush();
043            }
044    
045            @Override
046            public void write(byte[] bytes) throws IOException {
047                    write(bytes, 0, bytes.length);
048            }
049    
050            @Override
051            public void write(byte[] bytes, int offset, int length) throws IOException {
052                    outputStream.write(bytes, offset, length);
053            }
054    
055            @Override
056            public void write(int b) throws IOException {
057                    outputStream.write(b);
058            }
059    
060            protected OutputStream outputStream;
061    
062    }