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.Source;
12  import net.java.truecommons.shed.BitField;
13  
14  /**
15   * An adapter from an input socket to a source with access options.
16   *
17   * @author Christian Schlichtherle
18   */
19  public class FsInputSocketSource implements Source {
20  
21      private final BitField<FsAccessOption> options;
22      private final InputSocket<? extends Entry> socket;
23  
24      public FsInputSocketSource(
25              final BitField<FsAccessOption> options,
26              final InputSocket<? extends Entry> socket) {
27          this.options = Objects.requireNonNull(options);
28          this.socket = Objects.requireNonNull(socket);
29      }
30  
31      public FsInputSocketSource(final FsInputSocketSource source) {
32          this.options = source.getOptions();
33          this.socket = source.getSocket();
34      }
35  
36      public BitField<FsAccessOption> getOptions() {
37          return options;
38      }
39  
40      public InputSocket<? extends Entry> getSocket() {
41          return socket;
42      }
43  
44      @Override
45      public InputStream 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  }