View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.jumpmind.symmetric.transport.internal;
22  
23  import java.io.BufferedWriter;
24  import java.io.IOException;
25  import java.io.OutputStream;
26  import java.io.OutputStreamWriter;
27  import java.io.UnsupportedEncodingException;
28  
29  import org.apache.commons.io.IOUtils;
30  import org.jumpmind.symmetric.common.Constants;
31  import org.jumpmind.symmetric.transport.IOutgoingTransport;
32  
33  public class InternalOutgoingTransport implements IOutgoingTransport {
34  
35      BufferedWriter writer = null;
36  
37      boolean open = true;
38  
39      public InternalOutgoingTransport(OutputStream pushOs) throws UnsupportedEncodingException {
40          writer = new BufferedWriter(new OutputStreamWriter(pushOs, Constants.ENCODING));
41      }
42  
43      public InternalOutgoingTransport(BufferedWriter writer) {
44          this.writer = writer;
45      }
46  
47      public void close() throws IOException {
48          IOUtils.closeQuietly(writer);
49          open = false;
50      }
51  
52      public boolean isOpen() {
53          return open;
54      }
55  
56      public BufferedWriter open() throws IOException {
57          return writer;
58      }
59  
60  }