001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.commons.io.res.util; 020 021import java.io.IOException; 022import java.io.OutputStream; 023 024import lucee.commons.io.res.Resource; 025 026public class ResourceOutputStream extends OutputStream { 027 028 private final Resource res; 029 private final OutputStream os; 030 031 /** 032 * Constructor of the class 033 * @param res 034 * @param os 035 */ 036 public ResourceOutputStream(Resource res, OutputStream os) { 037 this.res=res; 038 this.os=os; 039 } 040 041 @Override 042 public void write(int b) throws IOException { 043 os.write(b); 044 } 045 046 @Override 047 public void close() throws IOException { 048 try { 049 os.close(); 050 } 051 finally { 052 res.getResourceProvider().unlock(res); 053 } 054 } 055 056 @Override 057 public void flush() throws IOException { 058 os.flush(); 059 } 060 061 @Override 062 public void write(byte[] b, int off, int len) throws IOException { 063 os.write(b, off, len); 064 } 065 066 @Override 067 public void write(byte[] b) throws IOException { 068 os.write(b); 069 } 070 071 /** 072 * @return the os 073 */ 074 public OutputStream getOutputStream() { 075 return os; 076 } 077 078 /** 079 * @return the res 080 */ 081 public Resource getResource() { 082 return res; 083 } 084 085}