001 package org.shiftone.jrat.core.output; 002 003 004 import org.shiftone.jrat.util.io.proxy.ProxyOutputStream; 005 import org.shiftone.jrat.util.log.Logger; 006 007 import java.io.IOException; 008 import java.io.OutputStream; 009 010 011 /** 012 * @author jeff@shiftone.org (Jeff Drost) 013 */ 014 public class FileOutputOutputStream extends ProxyOutputStream implements FileOutput { 015 016 private static final Logger LOG = Logger.getLogger(FileOutputOutputStream.class); 017 private final FileOutputRegistry registry; 018 private final OutputStream target; 019 private final String name; 020 private boolean closed = false; 021 022 public FileOutputOutputStream(FileOutputRegistry registry, OutputStream target, String name) { 023 024 this.registry = registry; 025 this.target = target; 026 this.name = name; 027 } 028 029 030 protected OutputStream getTarget() throws IOException { 031 return target; 032 } 033 034 035 public synchronized void close() throws IOException { 036 037 if (!closed) { 038 LOG.info("closing"); 039 040 closed = true; 041 042 registry.remove(this); 043 super.flush(); 044 super.close(); 045 } 046 } 047 048 049 public String toString() { 050 return "OutputStream[" + name + "]"; 051 } 052 }