View Javadoc
1   package com.srv4pos.commons.io;
2   
3   import com.srv4pos.server.api.infrastructure.ConnectionWriter;
4   
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.io.OutputStream;
8   
9   /**
10  * Implementation of {@link com.srv4pos.server.api.infrastructure.ConnectionWriter} which write data from {@link java.io.InputStream}.
11  * <p>User: Kirill, Date: 23.08.13 14:51</p>
12  */
13  public class InputStreamConnectionWriter implements ConnectionWriter {
14      private InputStream inputStream;
15  
16      /**
17       * Set the source of data.
18       * @param inputStream the source stream
19       */
20      public InputStreamConnectionWriter(InputStream inputStream) {
21          this.inputStream = inputStream;
22      }
23  
24      /**
25       * Write data.
26       * @param outputStream the target stream for write
27       * @throws IOException if an I/O error occurs
28       */
29      public void write(OutputStream outputStream) throws IOException {
30          IOUtils.copy(inputStream, outputStream);
31      }
32  
33      /**
34       * Get length of content. We cannot define it for stream.
35       * @return null
36       */
37      public Integer getContentLength() {
38          return null;
39      }
40  }