1   /*
2    * $Id: SignallingOutputStream.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.ftp.server;
12  
13  import java.io.IOException;
14  import java.io.OutputStream;
15  
16  import org.apache.commons.io.output.ByteArrayOutputStream;
17  
18  public class SignallingOutputStream extends OutputStream
19  {
20  
21      private String name;
22      private ServerState state;
23      private ByteArrayOutputStream delegate = new ByteArrayOutputStream();
24  
25      public SignallingOutputStream(String name, ServerState state)
26      {
27          this.name = name;
28          this.state = state;
29      }
30  
31      public void write(int b) throws IOException {
32          delegate.write(b);
33      }
34  
35      // @Override
36      public void close() throws IOException
37      {
38          delegate.close();
39          state.pushLastUpload(new NamedPayload(name, delegate.toByteArray()));
40          super.close();
41      }
42  
43  }