View Javadoc
1   /*
2    * Copyright (C) 2005-2015 Schlichtherle IT Services.
3    * All rights reserved. Use is subject to license terms.
4    */
5   package net.java.truevfs.kernel.spec;
6   
7   import java.io.*;
8   import java.nio.channels.SeekableByteChannel;
9   import java.util.Objects;
10  import net.java.truecommons.cio.*;
11  import net.java.truecommons.io.Sink;
12  import net.java.truecommons.shed.BitField;
13  
14  /**
15   * An adapter from an output socket to a sink with access options.
16   *
17   * @author Christian Schlichtherle
18   */
19  public class FsOutputSocketSink implements Sink {
20  
21      private final BitField<FsAccessOption> options;
22      private final OutputSocket<? extends Entry> socket;
23  
24      public FsOutputSocketSink(
25              final BitField<FsAccessOption> options,
26              final OutputSocket<? extends Entry> socket) {
27          this.options = Objects.requireNonNull(options);
28          this.socket = Objects.requireNonNull(socket);
29      }
30  
31      public FsOutputSocketSink(final FsOutputSocketSink sink) {
32          this.options = sink.getOptions();
33          this.socket = sink.getSocket();
34      }
35  
36      public BitField<FsAccessOption> getOptions() {
37          return options;
38      }
39  
40      public OutputSocket<? extends Entry> getSocket() {
41          return socket;
42      }
43  
44      @Override
45      public OutputStream stream() throws IOException {
46          return getSocket().stream(null);
47      }
48  
49      @Override
50      public SeekableByteChannel channel() throws IOException {
51          return getSocket().channel(null);
52      }
53  }