001 package railo.commons.io.res.type.datasource; 002 003 import java.io.IOException; 004 import java.io.OutputStream; 005 import java.sql.SQLException; 006 007 import railo.runtime.exp.AlwaysThrow; 008 009 public class DatasourceResourceOutputStream extends OutputStream { 010 011 private final DataWriter dw; 012 private final OutputStream os; 013 014 /** 015 * Constructor of the class 016 * @param res 017 * @param os 018 */ 019 public DatasourceResourceOutputStream(DataWriter dw, OutputStream os) { 020 this.dw=dw; 021 this.os=os; 022 } 023 024 /** 025 * @see java.io.OutputStream#write(int) 026 */ 027 public void write(int b) throws IOException { 028 os.write(b); 029 } 030 031 /** 032 * 033 * @see java.io.OutputStream#close() 034 */ 035 public void close() throws IOException { 036 os.close(); 037 try { 038 dw.join(); 039 } catch (InterruptedException e) { 040 throw new AlwaysThrow(e.getMessage()); 041 } 042 043 044 SQLException ioe=dw.getException(); 045 if(ioe!=null) { 046 throw new AlwaysThrow(ioe.getMessage()); 047 } 048 } 049 050 /** 051 * 052 * @see java.io.OutputStream#flush() 053 */ 054 public void flush() throws IOException { 055 os.flush(); 056 } 057 058 /** 059 * 060 * @see java.io.OutputStream#write(byte[], int, int) 061 */ 062 public void write(byte[] b, int off, int len) throws IOException { 063 os.write(b, off, len); 064 } 065 066 /** 067 * 068 * @see java.io.OutputStream#write(byte[]) 069 */ 070 public void write(byte[] b) throws IOException { 071 os.write(b); 072 } 073 074 /** 075 * @return the os 076 */ 077 public OutputStream getOutputStream() { 078 return os; 079 } 080 081 }